add edit profile
This commit is contained in:
parent
39b3efca33
commit
da3659e84a
@ -9,6 +9,7 @@ import 'dart:io';
|
|||||||
|
|
||||||
import '../classes/events.dart';
|
import '../classes/events.dart';
|
||||||
import '../classes/MyDrawer.dart';
|
import '../classes/MyDrawer.dart';
|
||||||
|
import '../main.dart';
|
||||||
|
|
||||||
import '../classes/alert.dart';
|
import '../classes/alert.dart';
|
||||||
import '../classes/eventAdded.dart';
|
import '../classes/eventAdded.dart';
|
||||||
@ -104,43 +105,92 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
|
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
var accessToken = prefs.getString("access_token") ?? "";
|
var accessToken = prefs.getString("access_token") ?? "";
|
||||||
var responsePut = await http.put(urlPut,
|
if (accessToken.isNotEmpty) {
|
||||||
headers: {
|
var responsePut = await http.put(urlPut,
|
||||||
HttpHeaders.cookieHeader: 'access_token=${accessToken}',
|
headers: {
|
||||||
HttpHeaders.acceptHeader: 'application/json, text/plain, */*',
|
HttpHeaders.cookieHeader: 'access_token=${accessToken}',
|
||||||
HttpHeaders.contentTypeHeader: 'application/json'
|
HttpHeaders.acceptHeader: 'application/json, text/plain, */*',
|
||||||
},
|
HttpHeaders.contentTypeHeader: 'application/json'
|
||||||
body: jsonEncode({
|
},
|
||||||
'name': name,
|
body: jsonEncode({
|
||||||
'username': username,
|
'name': name,
|
||||||
'firstName': firstName,
|
'username': username,
|
||||||
'password': password,
|
'firstName': firstName,
|
||||||
'email': email,
|
'password': password,
|
||||||
'birth': birth
|
'email': email,
|
||||||
}));
|
'birth': birth
|
||||||
print(responsePut.statusCode);
|
}));
|
||||||
if (responsePut.statusCode == 200) {
|
print(responsePut.statusCode);
|
||||||
showEventDialog(context, "Votre utilisateur a été modifié");
|
if (responsePut.statusCode == 200) {
|
||||||
return;
|
showEventDialog(context, "Votre utilisateur a été modifié");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
} else {
|
||||||
|
Navigator.pushReplacement(
|
||||||
|
context, MaterialPageRoute(builder: (_) => LoginDemo()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final errorMessages = {
|
Future<void> _getInfoProfile() async {
|
||||||
400: "Requête mal construite",
|
var urlGet = Uri.parse("${globals.api}/users/me");
|
||||||
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] ??
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
"Problème d'authentification inconnu";
|
var accessToken = prefs.getString("access_token") ?? "";
|
||||||
showAlertDialog(context, "Erreur serveur", text);
|
if (accessToken.isNotEmpty) {
|
||||||
|
var responseGet = await http.get(urlGet, headers: {
|
||||||
|
HttpHeaders.cookieHeader: 'access_token=${accessToken}',
|
||||||
|
HttpHeaders.acceptHeader: 'application/json, text/plain, */*',
|
||||||
|
HttpHeaders.contentTypeHeader: 'application/json'
|
||||||
|
});
|
||||||
|
print(responseGet.statusCode);
|
||||||
|
if (responseGet.statusCode == 200) {
|
||||||
|
var body = json.decode(utf8.decode(responseGet.bodyBytes));
|
||||||
|
setState(() {
|
||||||
|
inputName.text = body["name"];
|
||||||
|
inputFirstName.text = body["firstName"];
|
||||||
|
inputUserName.text = body["username"];
|
||||||
|
inputEmail = body["email"];
|
||||||
|
inputBirth.text =
|
||||||
|
DateFormat("dd/MM/yyyy").format(DateTime.parse(body["birth"]));
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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[responseGet.statusCode] ??
|
||||||
|
"Problème d'authentification inconnu";
|
||||||
|
showAlertDialog(context, "Erreur serveur", text);
|
||||||
|
} else {
|
||||||
|
Navigator.pushReplacement(
|
||||||
|
context, MaterialPageRoute(builder: (_) => LoginDemo()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
_getInfoProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
@ -164,8 +214,9 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Padding(
|
Padding(
|
||||||
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
padding: const EdgeInsets.only(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 15),
|
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
||||||
|
//padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: inputUserName,
|
controller: inputUserName,
|
||||||
validator: (value) => _validateField(value),
|
validator: (value) => _validateField(value),
|
||||||
@ -176,12 +227,12 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
padding: const EdgeInsets.only(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 15),
|
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
||||||
|
//padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: inputPassword,
|
controller: inputPassword,
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
validator: (value) => _validateField(value),
|
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
labelText: 'Mot de passe',
|
labelText: 'Mot de passe',
|
||||||
@ -189,12 +240,12 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
padding: const EdgeInsets.only(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 15),
|
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
||||||
|
//padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: inputPasswordConfirmed,
|
controller: inputPasswordConfirmed,
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
validator: (value) => _validateField(value),
|
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
labelText: 'Mot de passe',
|
labelText: 'Mot de passe',
|
||||||
@ -202,8 +253,9 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
padding: const EdgeInsets.only(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 15),
|
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
||||||
|
//padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: inputName,
|
controller: inputName,
|
||||||
validator: (value) => _validateField(value),
|
validator: (value) => _validateField(value),
|
||||||
@ -214,8 +266,9 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
padding: const EdgeInsets.only(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 15),
|
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
||||||
|
//padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: inputFirstName,
|
controller: inputFirstName,
|
||||||
validator: (value) => _validateField(value),
|
validator: (value) => _validateField(value),
|
||||||
@ -226,8 +279,9 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
padding: const EdgeInsets.only(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 15),
|
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
||||||
|
//padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: inputName,
|
controller: inputName,
|
||||||
validator: (value) => _validateField(value),
|
validator: (value) => _validateField(value),
|
||||||
@ -247,7 +301,7 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
validator: (value) => _validateField(value),
|
validator: (value) => _validateField(value),
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
labelText: 'Date de nassance',
|
labelText: 'Date de naissance',
|
||||||
hintText: 'Cliquez ici pour selectionner une date'),
|
hintText: 'Cliquez ici pour selectionner une date'),
|
||||||
onTap: () => onTapFunctionDatePicker(context: context)),
|
onTap: () => onTapFunctionDatePicker(context: context)),
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user