remove useless function
This commit is contained in:
parent
11c8cd74d2
commit
6a3ec9a969
@ -1,5 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.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';
|
||||||
|
|
||||||
@ -34,7 +33,7 @@ class AddProfile extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _AddProfileState extends State<AddProfile>
|
class _AddProfileState extends State<AddProfile>
|
||||||
with ShowAlertDialog, ShowAlertDialog {
|
with ShowAlertDialog {
|
||||||
TextEditingController inputUserName = TextEditingController();
|
TextEditingController inputUserName = TextEditingController();
|
||||||
|
|
||||||
TextEditingController inputName = TextEditingController();
|
TextEditingController inputName = TextEditingController();
|
||||||
@ -97,14 +96,10 @@ class _AddProfileState extends State<AddProfile>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var urlPut = Uri.parse("${globals.api}/users/me");
|
var urlPut = Uri.parse("${globals.api}/users");
|
||||||
|
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
var responsePost = await http.post(urlPut,
|
||||||
var accessToken = prefs.getString("access_token") ?? "";
|
|
||||||
if (accessToken.isNotEmpty) {
|
|
||||||
var responsePut = await http.put(urlPut,
|
|
||||||
headers: {
|
headers: {
|
||||||
HttpHeaders.cookieHeader: 'access_token=${accessToken}',
|
|
||||||
HttpHeaders.acceptHeader: 'application/json, text/plain, */*',
|
HttpHeaders.acceptHeader: 'application/json, text/plain, */*',
|
||||||
HttpHeaders.contentTypeHeader: 'application/json'
|
HttpHeaders.contentTypeHeader: 'application/json'
|
||||||
},
|
},
|
||||||
@ -117,8 +112,8 @@ class _AddProfileState extends State<AddProfile>
|
|||||||
'roles': '',
|
'roles': '',
|
||||||
'birth': birth.toString()
|
'birth': birth.toString()
|
||||||
}));
|
}));
|
||||||
print(responsePut.statusCode);
|
print(responsePost.statusCode);
|
||||||
if (responsePut.statusCode == 200) {
|
if (responsePost.statusCode == 200) {
|
||||||
showAlertDialog(context, "Ajout", "Votre utilisateur a été ajouté");
|
showAlertDialog(context, "Ajout", "Votre utilisateur a été ajouté");
|
||||||
Navigator.pushReplacement(
|
Navigator.pushReplacement(
|
||||||
context, MaterialPageRoute(builder: (_) => LoginDemo()));
|
context, MaterialPageRoute(builder: (_) => LoginDemo()));
|
||||||
@ -134,62 +129,16 @@ class _AddProfileState extends State<AddProfile>
|
|||||||
500: "Problème interne du serveur",
|
500: "Problème interne du serveur",
|
||||||
};
|
};
|
||||||
|
|
||||||
final text = errorMessages[responsePut.statusCode] ??
|
final text = errorMessages[responsePost.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.text = 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>();
|
||||||
@ -230,6 +179,7 @@ class _AddProfileState extends State<AddProfile>
|
|||||||
//padding: EdgeInsets.symmetric(horizontal: 15),
|
//padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: inputPassword,
|
controller: inputPassword,
|
||||||
|
validator: (value) => _validateField(value),
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
@ -243,6 +193,7 @@ class _AddProfileState extends State<AddProfile>
|
|||||||
//padding: EdgeInsets.symmetric(horizontal: 15),
|
//padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: inputPasswordConfirmed,
|
controller: inputPasswordConfirmed,
|
||||||
|
validator: (value) => _validateField(value),
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user