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);
}
void load(String username, String password) async{
currentUser = await loader.load(username, password) as User;
Future<void> load(String username, String password) async{
changeCurrentUser(await loader.load(username, password));
}
User createUser(String username, String password){

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

@ -9,20 +9,19 @@ class DatabaseLoader extends Loader{
// Load an user from database
@override
Future<User?> load(String username, String password) async {
User? userToReturn = null;
Future<User> 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;
}
}

@ -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;

@ -3,5 +3,5 @@ import 'dart:async';
import '../model/user.dart';
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 ==""){
Notify(2, context);
}
@ -237,14 +237,21 @@ class _SignInPageState extends State<SignInPage> {
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);
}
}
}

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

Loading…
Cancel
Save