add profile wip
This commit is contained in:
@@ -32,8 +32,7 @@ class AddProfile extends StatefulWidget {
|
||||
_AddProfileState createState() => _AddProfileState();
|
||||
}
|
||||
|
||||
class _AddProfileState extends State<AddProfile>
|
||||
with ShowAlertDialog {
|
||||
class _AddProfileState extends State<AddProfile> with ShowAlertDialog {
|
||||
TextEditingController inputUserName = TextEditingController();
|
||||
|
||||
TextEditingController inputName = TextEditingController();
|
||||
@@ -80,7 +79,7 @@ class _AddProfileState extends State<AddProfile>
|
||||
return "${year}-${month}-${day}";
|
||||
}
|
||||
|
||||
Future<void> _updateProfile(BuildContext context) async {
|
||||
Future<void> _createProfile(BuildContext context) async {
|
||||
var username = inputUserName.text;
|
||||
var firstName = inputFirstName.text;
|
||||
var name = inputName.text;
|
||||
@@ -98,44 +97,42 @@ class _AddProfileState extends State<AddProfile>
|
||||
|
||||
var urlPut = Uri.parse("${globals.api}/users");
|
||||
|
||||
var responsePost = await http.post(urlPut,
|
||||
headers: {
|
||||
HttpHeaders.acceptHeader: 'application/json, text/plain, */*',
|
||||
HttpHeaders.contentTypeHeader: 'application/json'
|
||||
},
|
||||
body: jsonEncode({
|
||||
'name': name,
|
||||
'username': username,
|
||||
'firstName': firstName,
|
||||
'password': password,
|
||||
'email': email,
|
||||
'roles': '',
|
||||
'birth': birth.toString()
|
||||
}));
|
||||
print(responsePost.statusCode);
|
||||
if (responsePost.statusCode == 200) {
|
||||
showAlertDialog(context, "Ajout", "Votre utilisateur a été ajouté");
|
||||
Navigator.pushReplacement(
|
||||
context, MaterialPageRoute(builder: (_) => LoginDemo()));
|
||||
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[responsePost.statusCode] ??
|
||||
"Problème d'authentification inconnu";
|
||||
showAlertDialog(context, "Erreur serveur", text);
|
||||
var responsePost = await http.post(urlPut,
|
||||
headers: {
|
||||
HttpHeaders.acceptHeader: 'application/json, text/plain, */*',
|
||||
HttpHeaders.contentTypeHeader: 'application/json'
|
||||
},
|
||||
body: jsonEncode({
|
||||
'name': name,
|
||||
'username': username,
|
||||
'firstName': firstName,
|
||||
'password': password,
|
||||
'email': email,
|
||||
'roles': '',
|
||||
'birth': birth.toString()
|
||||
}));
|
||||
print(responsePost.statusCode);
|
||||
if (responsePost.statusCode == 200) {
|
||||
showAlertDialog(context, "Ajout", "Votre utilisateur a été ajouté");
|
||||
Navigator.pushReplacement(
|
||||
context, MaterialPageRoute(builder: (_) => LoginDemo()));
|
||||
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[responsePost.statusCode] ??
|
||||
"Problème d'authentification inconnu";
|
||||
showAlertDialog(context, "Erreur serveur", text);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -266,11 +263,11 @@ class _AddProfileState extends State<AddProfile>
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_updateProfile(context);
|
||||
_createProfile(context);
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
'Modifier le profil',
|
||||
'Créer le profil',
|
||||
style: TextStyle(color: Colors.white, fontSize: 25),
|
||||
),
|
||||
),
|
||||
|
Reference in New Issue
Block a user