diff --git a/Sources/dafl_project_flutter/lib/controller/controller.dart b/Sources/dafl_project_flutter/lib/controller/controller.dart index 7a9ea57..7da6b68 100644 --- a/Sources/dafl_project_flutter/lib/controller/controller.dart +++ b/Sources/dafl_project_flutter/lib/controller/controller.dart @@ -31,8 +31,8 @@ class Controller{ saver.save(userToSave); } - void load(String username, String password) async{ - currentUser = await loader.load(username, password) as User; + Future load(String username, String password) async{ + changeCurrentUser(await loader.load(username, password)); } User createUser(String username, String password){ diff --git a/Sources/dafl_project_flutter/lib/model/user.dart b/Sources/dafl_project_flutter/lib/model/user.dart index 864f018..0509730 100644 --- a/Sources/dafl_project_flutter/lib/model/user.dart +++ b/Sources/dafl_project_flutter/lib/model/user.dart @@ -92,5 +92,5 @@ class User{ } @override - String toString() => "$usernameDafl ($idDafl)"; + String toString() => "$usernameDafl ($passwDafl)"; } \ No newline at end of file diff --git a/Sources/dafl_project_flutter/lib/persistence/database_loader.dart b/Sources/dafl_project_flutter/lib/persistence/database_loader.dart index a258774..4c3bc53 100644 --- a/Sources/dafl_project_flutter/lib/persistence/database_loader.dart +++ b/Sources/dafl_project_flutter/lib/persistence/database_loader.dart @@ -9,20 +9,19 @@ class DatabaseLoader extends Loader{ // Load an user from database @override - Future load(String username, String password) async { - User? userToReturn = null; + Future load(String username, String password) async { 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, 'password': password}).toList() .then((result) { - if(result.isNotEmpty){ - userToReturn = User(username, password); - } + print(result); + if(result.isNotEmpty) return User(username, password); + else return User("", ""); }).whenComplete(() { connection.close();}); - return userToReturn; + return queryResult; } } diff --git a/Sources/dafl_project_flutter/lib/persistence/database_searcher.dart b/Sources/dafl_project_flutter/lib/persistence/database_searcher.dart index 612b19b..a01721b 100644 --- a/Sources/dafl_project_flutter/lib/persistence/database_searcher.dart +++ b/Sources/dafl_project_flutter/lib/persistence/database_searcher.dart @@ -16,7 +16,8 @@ class DatabaseSearcher extends Searcher{ bool queryResult = await connection.query('select * from utilisateur where username = @username',{ 'username' : usernameToSearch}) .toList() - .then((rows) { return rows.isEmpty; }); + .then((rows) { return rows.isEmpty; }).whenComplete(() { + connection.close();}); return queryResult; diff --git a/Sources/dafl_project_flutter/lib/persistence/loader.dart b/Sources/dafl_project_flutter/lib/persistence/loader.dart index 43a6fde..2adf991 100644 --- a/Sources/dafl_project_flutter/lib/persistence/loader.dart +++ b/Sources/dafl_project_flutter/lib/persistence/loader.dart @@ -3,5 +3,5 @@ import 'dart:async'; import '../model/user.dart'; abstract class Loader{ - Future load(String username, String password); + Future load(String username, String password); } \ No newline at end of file diff --git a/Sources/dafl_project_flutter/lib/views/pages/sign_in/p_sign_in.dart b/Sources/dafl_project_flutter/lib/views/pages/sign_in/p_sign_in.dart index 958f632..733c779 100644 --- a/Sources/dafl_project_flutter/lib/views/pages/sign_in/p_sign_in.dart +++ b/Sources/dafl_project_flutter/lib/views/pages/sign_in/p_sign_in.dart @@ -229,7 +229,7 @@ class _SignInPageState extends State { } - void checkInformations(String username,String password){ + void checkInformations(String username,String password) async{ if(username ==""){ Notify(2, context); } @@ -237,14 +237,21 @@ class _SignInPageState extends State { Notify(4, context); } else{ - //MyApp().controller.load(userNameTextField.text, passwordTextField.text); - MyApp().controller.currentUser = User(username, password); - Navigator.of(context).push( - PageTransition( - type: PageTransitionType.fade, - childCurrent: widget, - child: Splash()), - ); + await MyApp().controller.load(userNameTextField.text, passwordTextField.text); + + if(MyApp().controller.currentUser.usernameDafl != ""){ + Navigator.of(context).push( + PageTransition( + type: PageTransitionType.fade, + childCurrent: widget, + child: Splash()), + ); + } + else{ + Notify(2, context); + } + + } } diff --git a/Sources/dafl_project_flutter/lib/views/pages/sign_up/p_sign_up.dart b/Sources/dafl_project_flutter/lib/views/pages/sign_up/p_sign_up.dart index 569336b..800c8c0 100644 --- a/Sources/dafl_project_flutter/lib/views/pages/sign_up/p_sign_up.dart +++ b/Sources/dafl_project_flutter/lib/views/pages/sign_up/p_sign_up.dart @@ -300,7 +300,6 @@ class _SignUpPageState extends State { Future checkInformations(String username, String password, String confirmPassword) async { - if(username == ""){ Notify(2, context); }