Compare commits
No commits in common. "9846c614a101a2e482e03712469de6e3d00090be" and "6fdb5cb2fef94aa2715853d417d35135c24e524f" have entirely different histories.
9846c614a1
...
6fdb5cb2fe
@ -8,7 +8,7 @@ import 'dart:io';
|
|||||||
//import 'MyHomePage.dart';
|
//import 'MyHomePage.dart';
|
||||||
import 'pages/ListItemMenu.dart';
|
import 'pages/ListItemMenu.dart';
|
||||||
import 'pages/AddProfile.dart';
|
import 'pages/AddProfile.dart';
|
||||||
import 'pages/ForgotPassword.dart';
|
|
||||||
import 'classes/alert.dart';
|
import 'classes/alert.dart';
|
||||||
|
|
||||||
import 'variable/globals.dart' as globals;
|
import 'variable/globals.dart' as globals;
|
||||||
@ -221,8 +221,7 @@ class _LoginDemoState extends State<LoginDemo> with ShowAlertDialog {
|
|||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.push(context,
|
//TODO FORGOT PASSWORD SCREEN GOES HERE
|
||||||
MaterialPageRoute(builder: (_) => PasswordForgot()));
|
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'Forgot Password',
|
'Forgot Password',
|
||||||
|
@ -1,158 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
|
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import '../main.dart';
|
|
||||||
|
|
||||||
import '../classes/alert.dart';
|
|
||||||
|
|
||||||
import '../variable/globals.dart' as globals;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(MyApp());
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: PasswordForgot(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class PasswordForgot extends StatefulWidget {
|
|
||||||
const PasswordForgot({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
_PasswordForgotState createState() => _PasswordForgotState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _PasswordForgotState extends State<PasswordForgot> with ShowAlertDialog {
|
|
||||||
TextEditingController inputEmail = TextEditingController();
|
|
||||||
|
|
||||||
convertNulltoEmptyString(var check) {
|
|
||||||
if (check == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return check;
|
|
||||||
}
|
|
||||||
|
|
||||||
convertNulltoArray(List<String> check) {
|
|
||||||
if (check == null) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
return check;
|
|
||||||
}
|
|
||||||
|
|
||||||
String formatDate(String date) {
|
|
||||||
var splitedDate = date.split("/");
|
|
||||||
|
|
||||||
var day = splitedDate[0];
|
|
||||||
var month = splitedDate[1];
|
|
||||||
var year = splitedDate[2];
|
|
||||||
|
|
||||||
return "${year}-${month}-${day}";
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _forgotPassword(BuildContext context) async {
|
|
||||||
var email = inputEmail.text;
|
|
||||||
|
|
||||||
var urlPut = Uri.parse("${globals.api}/password/forgot");
|
|
||||||
|
|
||||||
var responsePost = await http.post(urlPut,
|
|
||||||
headers: {
|
|
||||||
HttpHeaders.acceptHeader: 'application/json, text/plain, */*',
|
|
||||||
HttpHeaders.contentTypeHeader: 'application/json'
|
|
||||||
},
|
|
||||||
body: jsonEncode({
|
|
||||||
'email': email,
|
|
||||||
}));
|
|
||||||
print(responsePost.statusCode);
|
|
||||||
if (responsePost.statusCode == 200) {
|
|
||||||
showAlertDialog(context, "Creation", "Un email a été envoyé à ${email}");
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
final _formKey = GlobalKey<FormState>();
|
|
||||||
String? _validateField(String? value) {
|
|
||||||
return value!.isEmpty ? 'Champ requis' : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text("Mot de passe oublie"),
|
|
||||||
backgroundColor: Colors.blue,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
),
|
|
||||||
body: Form(
|
|
||||||
key: _formKey,
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Column(
|
|
||||||
children: <Widget>[
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
|
||||||
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
||||||
child: TextFormField(
|
|
||||||
controller: inputEmail,
|
|
||||||
validator: (value) => _validateField(value),
|
|
||||||
decoration: InputDecoration(
|
|
||||||
border: OutlineInputBorder(),
|
|
||||||
labelText: 'Email',
|
|
||||||
hintText: 'Modifier l\'adresse mail'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
height: 30,
|
|
||||||
),
|
|
||||||
Container(
|
|
||||||
height: 50,
|
|
||||||
width: 250,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.blue,
|
|
||||||
borderRadius: BorderRadius.circular(20)),
|
|
||||||
child: TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
if (_formKey.currentState!.validate()) {
|
|
||||||
_forgotPassword(context);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: Text(
|
|
||||||
'Envoyer le mail',
|
|
||||||
style: TextStyle(color: Colors.white, fontSize: 25),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user