editprofile complete
This commit is contained in:
parent
f84f513e67
commit
82c31acf99
@ -1,16 +1,14 @@
|
|||||||
import 'package:covas_mobile/pages/CameraEdit.dart';
|
import 'package:covas_mobile/classes/MyDrawer.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
||||||
import 'package:textfield_tags/textfield_tags.dart';
|
|
||||||
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'dart:typed_data';
|
|
||||||
import '../classes/events.dart';
|
import '../classes/events.dart';
|
||||||
|
import '../classes/MyDrawer.dart';
|
||||||
|
|
||||||
import '../classes/alert.dart';
|
import '../classes/alert.dart';
|
||||||
import '../classes/eventAdded.dart';
|
import '../classes/eventAdded.dart';
|
||||||
@ -50,6 +48,7 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
TextEditingController inputEmail = TextEditingController();
|
TextEditingController inputEmail = TextEditingController();
|
||||||
TextEditingController inputBirth = TextEditingController();
|
TextEditingController inputBirth = TextEditingController();
|
||||||
TextEditingController inputPassword = TextEditingController();
|
TextEditingController inputPassword = TextEditingController();
|
||||||
|
TextEditingController inputPasswordConfirmed = TextEditingController();
|
||||||
|
|
||||||
onTapFunctionDatePicker({required BuildContext context}) async {
|
onTapFunctionDatePicker({required BuildContext context}) async {
|
||||||
DateTime initialDate = DateTime.parse(formatDate(inputBirth.text));
|
DateTime initialDate = DateTime.parse(formatDate(inputBirth.text));
|
||||||
@ -88,18 +87,23 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _updateProfile(BuildContext context) async {
|
Future<void> _updateProfile(BuildContext context) async {
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
||||||
var accessToken = prefs.getString("access_token") ?? "";
|
|
||||||
|
|
||||||
var username = inputUserName.text;
|
var username = inputUserName.text;
|
||||||
var firstName = inputFirstName.text;
|
var firstName = inputFirstName.text;
|
||||||
var name = inputName.text;
|
var name = inputName.text;
|
||||||
var email = inputEmail.text;
|
var email = inputEmail.text;
|
||||||
var password = inputPassword.text;
|
var password = inputPassword.text;
|
||||||
|
var confirmedPassword = inputPasswordConfirmed.text;
|
||||||
var birth = DateTime.parse(formatDate(inputBirth.text));
|
var birth = DateTime.parse(formatDate(inputBirth.text));
|
||||||
|
|
||||||
|
if (password != confirmedPassword) {
|
||||||
|
showAlertDialog(context, "Erreur", "Mot de passe different");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var urlPut = Uri.parse("${globals.api}/users/me");
|
var urlPut = Uri.parse("${globals.api}/users/me");
|
||||||
|
|
||||||
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
|
var accessToken = prefs.getString("access_token") ?? "";
|
||||||
var responsePut = await http.put(urlPut,
|
var responsePut = await http.put(urlPut,
|
||||||
headers: {
|
headers: {
|
||||||
HttpHeaders.cookieHeader: 'access_token=${accessToken}',
|
HttpHeaders.cookieHeader: 'access_token=${accessToken}',
|
||||||
@ -116,49 +120,23 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
}));
|
}));
|
||||||
print(responsePut.statusCode);
|
print(responsePut.statusCode);
|
||||||
if (responsePut.statusCode == 200) {
|
if (responsePut.statusCode == 200) {
|
||||||
showEventDialog(context, " Votre utiliseteur modifie");
|
showEventDialog(context, "Votre utilisateur a été modifié");
|
||||||
} else {
|
return;
|
||||||
var text = "";
|
|
||||||
switch (responsePut.statusCode) {
|
|
||||||
case 400:
|
|
||||||
{
|
|
||||||
text = "Requête mal construite";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 406:
|
|
||||||
{
|
|
||||||
text = "Mot de passe incorrect";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 404:
|
|
||||||
{
|
|
||||||
text = "Utilisateur inconnu";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 403:
|
|
||||||
{
|
|
||||||
text = "Utilisateur desactive";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 410:
|
|
||||||
{
|
|
||||||
text = "Token invalide";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 500:
|
|
||||||
{
|
|
||||||
text = "Probleme interne du serveur";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
text = "Probleme d'authentification inconnu";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final errorMessages = {
|
||||||
|
400: "Requête mal construite",
|
||||||
|
406: "Mot de passe incorrect",
|
||||||
|
404: "Utilisateur inconnu",
|
||||||
|
403: "Utilisateur désactivé",
|
||||||
|
410: "Token invalide",
|
||||||
|
500: "Problème interne du serveur",
|
||||||
|
};
|
||||||
|
|
||||||
|
final text = errorMessages[responsePut.statusCode] ??
|
||||||
|
"Problème d'authentification inconnu";
|
||||||
showAlertDialog(context, "Erreur serveur", text);
|
showAlertDialog(context, "Erreur serveur", text);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -179,6 +157,7 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
backgroundColor: Colors.blue,
|
backgroundColor: Colors.blue,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
),
|
),
|
||||||
|
drawer: MyDrawer(),
|
||||||
body: Form(
|
body: Form(
|
||||||
key: _formKey,
|
key: _formKey,
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
@ -196,6 +175,32 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
hintText: 'Modifier le pseudo'),
|
hintText: 'Modifier le pseudo'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Padding(
|
||||||
|
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
|
child: TextFormField(
|
||||||
|
controller: inputPassword,
|
||||||
|
obscureText: true,
|
||||||
|
validator: (value) => _validateField(value),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
labelText: 'Mot de passe',
|
||||||
|
hintText: 'Entrez le mot de passe'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
|
child: TextFormField(
|
||||||
|
controller: inputPasswordConfirmed,
|
||||||
|
obscureText: true,
|
||||||
|
validator: (value) => _validateField(value),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
labelText: 'Mot de passe',
|
||||||
|
hintText: 'Confirmez le mot de passe'),
|
||||||
|
),
|
||||||
|
),
|
||||||
Padding(
|
Padding(
|
||||||
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
||||||
padding: EdgeInsets.symmetric(horizontal: 15),
|
padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user