diff --git a/Sources/dafl_project_flutter/lib/controller/controller.dart b/Sources/dafl_project_flutter/lib/controller/controller.dart index 835b87a..7a9ea57 100644 --- a/Sources/dafl_project_flutter/lib/controller/controller.dart +++ b/Sources/dafl_project_flutter/lib/controller/controller.dart @@ -12,12 +12,14 @@ import '../persistence/searcher.dart'; class Controller{ static Controller? _this; - static Saver? saver = DatabaseSaver(); - static Loader? loader = DatabaseLoader(); + static Saver saver = DatabaseSaver(); + static Loader loader = DatabaseLoader(); static Searcher _searcher = DatabaseSearcher(); + User currentUser = User("", ""); + factory Controller(){ if (_this == null) _this = Controller._(); return _this!; @@ -26,11 +28,11 @@ class Controller{ Controller._(); void save(User userToSave){ - saver?.save(userToSave); + saver.save(userToSave); } void load(String username, String password) async{ - currentUser = await loader?.load(username, password) as User; + currentUser = await loader.load(username, password) as User; } User createUser(String username, String password){ @@ -43,16 +45,16 @@ class Controller{ void changeUsernameCourant(String newName){ if(newName !=null){ - this.currentUser?.usernameDafl = newName; + this.currentUser.usernameDafl = newName; } } void changePasswordCourant(String newPass){ if(newPass !=null){ - this.currentUser?.passwDafl = newPass; + this.currentUser.passwDafl = newPass; } } Future searchByUsername(String username) async{ - return _searcher.searchByUsername(username); + return await _searcher.searchByUsername(username); } } diff --git a/Sources/dafl_project_flutter/lib/model/user.dart b/Sources/dafl_project_flutter/lib/model/user.dart index 22bcb95..864f018 100644 --- a/Sources/dafl_project_flutter/lib/model/user.dart +++ b/Sources/dafl_project_flutter/lib/model/user.dart @@ -61,14 +61,12 @@ class User{ - - void addDiscovery(Music newmusic){ - if(MyApp().controller?.currentUser?.Discovery == null){ + if(MyApp().controller.currentUser.Discovery == null){ } else{ - MyApp().controller.currentUser?.Discovery.add(newmusic); + MyApp().controller.currentUser.Discovery.add(newmusic); } diff --git a/Sources/dafl_project_flutter/lib/model/user_creator.dart b/Sources/dafl_project_flutter/lib/model/user_creator.dart deleted file mode 100644 index 07029e6..0000000 --- a/Sources/dafl_project_flutter/lib/model/user_creator.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'user.dart'; - -class UserCreator{ - - User? createUser(int id, String username){ - - } -} \ No newline at end of file diff --git a/Sources/dafl_project_flutter/lib/persistence/.logs/.gitkeep b/Sources/dafl_project_flutter/lib/persistence/.logs/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/Sources/dafl_project_flutter/lib/persistence/.logs/logs.txt b/Sources/dafl_project_flutter/lib/persistence/.logs/logs.txt deleted file mode 100644 index f589036..0000000 --- a/Sources/dafl_project_flutter/lib/persistence/.logs/logs.txt +++ /dev/null @@ -1,5 +0,0 @@ -postgres -mdpDaflBd -89.83.54.48 -BD-DaflMusic - diff --git a/Sources/dafl_project_flutter/lib/persistence/database_saver.dart b/Sources/dafl_project_flutter/lib/persistence/database_saver.dart index d8385a5..25ab875 100644 --- a/Sources/dafl_project_flutter/lib/persistence/database_saver.dart +++ b/Sources/dafl_project_flutter/lib/persistence/database_saver.dart @@ -6,6 +6,8 @@ import '../model/user.dart'; class DatabaseSaver extends Saver{ + + // Save user in the database @override void save(User userToSave) async{ final connection = await DatabaseConnexion.initConnexion(); @@ -13,7 +15,11 @@ class DatabaseSaver extends Saver{ connection.execute('insert into utilisateur (username, password) values (@username, @password)', { 'id' : '', 'username': userToSave.usernameDafl, - 'password' : userToSave.passwDafl}).then((_) {}); + 'password' : userToSave.passwDafl}) + + .whenComplete(() { + connection.close(); + }); } } \ No newline at end of file diff --git a/Sources/dafl_project_flutter/lib/persistence/database_searcher.dart b/Sources/dafl_project_flutter/lib/persistence/database_searcher.dart index af15b59..612b19b 100644 --- a/Sources/dafl_project_flutter/lib/persistence/database_searcher.dart +++ b/Sources/dafl_project_flutter/lib/persistence/database_searcher.dart @@ -2,24 +2,24 @@ import 'package:dafl_project_flutter/persistence/database_connexion.dart'; import 'searcher.dart'; -class DatabaseSearcher extends Searcher{ + +class DatabaseSearcher extends Searcher{ Future searchUser(String? username, String? password) async { return true; } + + // Search an user in the database by username @override - Future searchByUsername(String? username) async{ + Future searchByUsername(String? usernameToSearch) async{ final connection = await DatabaseConnexion.initConnexion(); - bool isHere = true; - connection.query('select * from utilisateur where username = $username').toList().then((rows) { - if(rows.isEmpty){ - isHere = false; - } - }).whenComplete(() { - print('close'); - }); + bool queryResult = await connection.query('select * from utilisateur where username = @username',{ 'username' : usernameToSearch}) + .toList() + .then((rows) { return rows.isEmpty; }); + - return isHere; + return queryResult; } + } 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 ea0700d..958f632 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 @@ -1,6 +1,5 @@ import 'dart:ui'; import 'package:dafl_project_flutter/model/user.dart'; -import 'package:dafl_project_flutter/views/pages/main/p_main.dart'; import 'package:flutter/material.dart'; import 'package:page_transition/page_transition.dart'; import '../../../main.dart'; 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 70b9afb..569336b 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 @@ -307,7 +307,6 @@ class _SignUpPageState extends State { else if(! await MyApp().controller.searchByUsername(username)){ Notify(0, context); } - if(password == "" || confirmPassword == ""){ Notify(4, context); }