Compare commits
No commits in common. "da3659e84a6968a20907dd725ccce4e13e2db6d2" and "82c31acf99c52c8b0255026da4080226b76e7028" have entirely different histories.
da3659e84a
...
82c31acf99
@ -2,7 +2,7 @@ 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 'dart:io';
|
import 'dart:io';
|
||||||
import '../pages/EditProfile.dart';
|
|
||||||
import 'alert.dart';
|
import 'alert.dart';
|
||||||
|
|
||||||
import '../variable/globals.dart' as globals;
|
import '../variable/globals.dart' as globals;
|
||||||
@ -108,10 +108,7 @@ class MyDrawer extends StatelessWidget with ShowAlertDialog {
|
|||||||
leading: Icon(Icons.account_circle),
|
leading: Icon(Icons.account_circle),
|
||||||
title: Text('Update profile'),
|
title: Text('Update profile'),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.pushReplacement(
|
Navigator.pop(context); // Close the drawer
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (_) => EditProfile())); // Close the drawer
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
|
@ -9,7 +9,6 @@ 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';
|
||||||
@ -105,7 +104,6 @@ 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") ?? "";
|
||||||
if (accessToken.isNotEmpty) {
|
|
||||||
var responsePut = await http.put(urlPut,
|
var responsePut = await http.put(urlPut,
|
||||||
headers: {
|
headers: {
|
||||||
HttpHeaders.cookieHeader: 'access_token=${accessToken}',
|
HttpHeaders.cookieHeader: 'access_token=${accessToken}',
|
||||||
@ -138,59 +136,11 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
final text = errorMessages[responsePut.statusCode] ??
|
final text = errorMessages[responsePut.statusCode] ??
|
||||||
"Problème d'authentification inconnu";
|
"Problème d'authentification inconnu";
|
||||||
showAlertDialog(context, "Erreur serveur", text);
|
showAlertDialog(context, "Erreur serveur", text);
|
||||||
} else {
|
|
||||||
Navigator.pushReplacement(
|
|
||||||
context, MaterialPageRoute(builder: (_) => LoginDemo()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _getInfoProfile() async {
|
|
||||||
var urlGet = Uri.parse("${globals.api}/users/me");
|
|
||||||
|
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
||||||
var accessToken = prefs.getString("access_token") ?? "";
|
|
||||||
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>();
|
||||||
@ -214,9 +164,8 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(
|
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
||||||
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: inputUserName,
|
controller: inputUserName,
|
||||||
validator: (value) => _validateField(value),
|
validator: (value) => _validateField(value),
|
||||||
@ -227,12 +176,12 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(
|
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
||||||
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
//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',
|
||||||
@ -240,12 +189,12 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(
|
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
||||||
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
//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',
|
||||||
@ -253,9 +202,8 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(
|
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
||||||
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: inputName,
|
controller: inputName,
|
||||||
validator: (value) => _validateField(value),
|
validator: (value) => _validateField(value),
|
||||||
@ -266,9 +214,8 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(
|
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
||||||
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: inputFirstName,
|
controller: inputFirstName,
|
||||||
validator: (value) => _validateField(value),
|
validator: (value) => _validateField(value),
|
||||||
@ -279,9 +226,8 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(
|
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
||||||
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: inputName,
|
controller: inputName,
|
||||||
validator: (value) => _validateField(value),
|
validator: (value) => _validateField(value),
|
||||||
@ -301,7 +247,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 naissance',
|
labelText: 'Date de nassance',
|
||||||
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