ADD : User login (password verification + username) and notification if there is a problem
continuous-integration/drone/push Build is passing Details

messagerie_lucas_test
Audric SABATIER 2 years ago
parent 92c46322ff
commit b1b1f507f2

@ -31,8 +31,8 @@ class Controller{
saver.save(userToSave); saver.save(userToSave);
} }
void load(String username, String password) async{ Future<void> load(String username, String password) async{
currentUser = await loader.load(username, password) as User; changeCurrentUser(await loader.load(username, password));
} }
User createUser(String username, String password){ User createUser(String username, String password){

@ -92,5 +92,5 @@ class User{
} }
@override @override
String toString() => "$usernameDafl ($idDafl)"; String toString() => "$usernameDafl ($passwDafl)";
} }

@ -9,20 +9,19 @@ class DatabaseLoader extends Loader{
// Load an user from database // Load an user from database
@override @override
Future<User?> load(String username, String password) async { Future<User> load(String username, String password) async {
User? userToReturn = null;
final connection = await DatabaseConnexion.initConnexion(); final connection = await DatabaseConnexion.initConnexion();
connection.query('select * from utilisateur where username = @username AND password = @password', var queryResult = await connection.query('select * from utilisateur where username = @username AND password = @password',
{'username': username, {'username': username,
'password': password}).toList() 'password': password}).toList()
.then((result) { .then((result) {
if(result.isNotEmpty){ print(result);
userToReturn = User(username, password); if(result.isNotEmpty) return User(username, password);
} else return User("", "");
}).whenComplete(() { }).whenComplete(() {
connection.close();}); connection.close();});
return userToReturn; return queryResult;
} }
} }

@ -16,7 +16,8 @@ class DatabaseSearcher extends Searcher{
bool queryResult = await connection.query('select * from utilisateur where username = @username',{ 'username' : usernameToSearch}) bool queryResult = await connection.query('select * from utilisateur where username = @username',{ 'username' : usernameToSearch})
.toList() .toList()
.then((rows) { return rows.isEmpty; }); .then((rows) { return rows.isEmpty; }).whenComplete(() {
connection.close();});
return queryResult; return queryResult;

@ -3,5 +3,5 @@ import 'dart:async';
import '../model/user.dart'; import '../model/user.dart';
abstract class Loader{ abstract class Loader{
Future<User?> load(String username, String password); Future<User> load(String username, String password);
} }

@ -229,7 +229,7 @@ class _SignInPageState extends State<SignInPage> {
} }
void checkInformations(String username,String password){ void checkInformations(String username,String password) async{
if(username ==""){ if(username ==""){
Notify(2, context); Notify(2, context);
} }
@ -237,14 +237,21 @@ class _SignInPageState extends State<SignInPage> {
Notify(4, context); Notify(4, context);
} }
else{ else{
//MyApp().controller.load(userNameTextField.text, passwordTextField.text); await MyApp().controller.load(userNameTextField.text, passwordTextField.text);
MyApp().controller.currentUser = User(username, password);
Navigator.of(context).push( if(MyApp().controller.currentUser.usernameDafl != ""){
PageTransition( Navigator.of(context).push(
type: PageTransitionType.fade, PageTransition(
childCurrent: widget, type: PageTransitionType.fade,
child: Splash()), childCurrent: widget,
); child: Splash()),
);
}
else{
Notify(2, context);
}
} }
} }

@ -300,7 +300,6 @@ class _SignUpPageState extends State<SignUpPage> {
Future<void> checkInformations(String username, String password, String confirmPassword) async { Future<void> checkInformations(String username, String password, String confirmPassword) async {
if(username == ""){ if(username == ""){
Notify(2, context); Notify(2, context);
} }

Loading…
Cancel
Save