diff --git a/Sources/dafl_project_flutter/lib/controller/controller.dart b/Sources/dafl_project_flutter/lib/controller/controller.dart index 498f729..835b87a 100644 --- a/Sources/dafl_project_flutter/lib/controller/controller.dart +++ b/Sources/dafl_project_flutter/lib/controller/controller.dart @@ -16,7 +16,7 @@ class Controller{ static Loader? loader = DatabaseLoader(); static Searcher _searcher = DatabaseSearcher(); - User currentUser = User(null, null); + User currentUser = User("", ""); factory Controller(){ if (_this == null) _this = Controller._(); diff --git a/Sources/dafl_project_flutter/lib/model/user.dart b/Sources/dafl_project_flutter/lib/model/user.dart index f1063a4..22bcb95 100644 --- a/Sources/dafl_project_flutter/lib/model/user.dart +++ b/Sources/dafl_project_flutter/lib/model/user.dart @@ -6,19 +6,40 @@ import 'music.dart'; class User{ //attributes from DAFL - int? idDafl; - String? usernameDafl; - String? passwDafl; + late int _idDafl; + late String _usernameDafl; + late String _passwDafl; + //attributes to link with API - String? usernameAPI; - String? passwAPI; + late String _usernameAPI; + late String _passwAPI; + + + + // Getters for attributes + int get idDafl => _idDafl; + String get passwAPI => _passwAPI; + String get usernameDafl => _usernameDafl; + String get passwDafl => _passwDafl; + String get usernameAPI => _usernameAPI; + + // Setters for attributes + set idDafl(int value) { _idDafl = value; } + set usernameDafl(String value) { _usernameDafl = value; } + set passwDafl(String value) { _passwDafl = value; } + set usernameAPI(String value) { _usernameAPI = value; } + set passwAPI(String value) { _passwAPI = value; } + + //constructors - User(this.usernameDafl, this.passwDafl); + User(this._usernameDafl, this._passwDafl); + + User.name(this._usernameDafl); + + User.fromDatabase(this._idDafl, this._usernameDafl); - User.name(this.usernameDafl); - User.fromDatabase(this.idDafl, this.usernameDafl); //lists Set likedUsers={}; @@ -38,6 +59,10 @@ class User{ Music('Paradis','Sopico','https://cdns-images.dzcdn.net/images/cover/17a9747927ac3e5ea56f92f635d9180c/500x500.jpg')].reversed.toList(); Map conversations={}; + + + + void addDiscovery(Music newmusic){ if(MyApp().controller?.currentUser?.Discovery == null){ diff --git a/Sources/dafl_project_flutter/lib/persistence/database_connexion.dart b/Sources/dafl_project_flutter/lib/persistence/database_connexion.dart index 4983ac3..d7fe1ed 100644 --- a/Sources/dafl_project_flutter/lib/persistence/database_connexion.dart +++ b/Sources/dafl_project_flutter/lib/persistence/database_connexion.dart @@ -21,13 +21,13 @@ class DatabaseConnexion{ static String? _psqlDataBase; + + // Read the database connection identifiers in a file static Future _loadLogs() async{ try{ final _loadedData = await rootBundle.loadString(filePath); - print('appel de -readLogs'); - final _logs = LineSplitter.split(_loadedData).toList(); _psqlUser = _logs[0]; @@ -42,14 +42,19 @@ class DatabaseConnexion{ - //Initialise connexion to the database + //Initialise and open a connection to the database static Future initConnexion() async{ if(_psqlHost == null || _psqlPswd == null || _psqlUser == null || _psqlDataBase == null){ await _loadLogs(); } - var uri = 'postgres://$_psqlUser:$_psqlPswd@$_psqlHost:5442/$_psqlDataBase'; + try{ + var uri = 'postgres://$_psqlUser:$_psqlPswd@$_psqlHost:5442/$_psqlDataBase'; - return connect(uri); + return connect(uri); + } + catch(e){ + throw Exception('Connection to database : IMPOSSIBLE'); + } } } \ 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 94416d4..a258774 100644 --- a/Sources/dafl_project_flutter/lib/persistence/database_loader.dart +++ b/Sources/dafl_project_flutter/lib/persistence/database_loader.dart @@ -6,15 +6,23 @@ import 'database_connexion.dart'; class DatabaseLoader extends Loader{ + + // Load an user from database @override - Future load(String? username, String? password) async { + Future load(String username, String password) async { + User? userToReturn = null; final connection = await DatabaseConnexion.initConnexion(); connection.query('select * from utilisateur where username = @username AND password = @password', {'username': username, 'password': password}).toList() .then((result) { - print(result); }); - } + if(result.isNotEmpty){ + userToReturn = User(username, password); + } + }).whenComplete(() { + connection.close();}); + return userToReturn; + } } diff --git a/Sources/dafl_project_flutter/lib/persistence/database_saver.dart b/Sources/dafl_project_flutter/lib/persistence/database_saver.dart index e900980..d8385a5 100644 --- a/Sources/dafl_project_flutter/lib/persistence/database_saver.dart +++ b/Sources/dafl_project_flutter/lib/persistence/database_saver.dart @@ -5,7 +5,6 @@ import '../model/user.dart'; class DatabaseSaver extends Saver{ - DatabaseConnexion dbConnexion = DatabaseConnexion(); @override void save(User userToSave) async{ diff --git a/Sources/dafl_project_flutter/lib/persistence/database_searcher.dart b/Sources/dafl_project_flutter/lib/persistence/database_searcher.dart index 5bf2d40..af15b59 100644 --- a/Sources/dafl_project_flutter/lib/persistence/database_searcher.dart +++ b/Sources/dafl_project_flutter/lib/persistence/database_searcher.dart @@ -3,21 +3,23 @@ import 'package:dafl_project_flutter/persistence/database_connexion.dart'; import 'searcher.dart'; class DatabaseSearcher extends Searcher{ + Future searchUser(String? username, String? password) async { return true; } @override Future searchByUsername(String? username) async{ final connection = await DatabaseConnexion.initConnexion(); + bool isHere = true; connection.query('select * from utilisateur where username = $username').toList().then((rows) { if(rows.isEmpty){ - connection.close(); - return false; + isHere = false; } + }).whenComplete(() { + print('close'); }); - connection.close(); - return true; + return isHere; } -} \ No newline at end of file +} diff --git a/Sources/dafl_project_flutter/lib/persistence/loader.dart b/Sources/dafl_project_flutter/lib/persistence/loader.dart index cf64cee..43a6fde 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 7b29836..ea0700d 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,6 +229,7 @@ class _SignInPageState extends State { ); } + void checkInformations(String username,String password){ if(username ==""){ Notify(2, context); @@ -238,7 +239,7 @@ class _SignInPageState extends State { } else{ //MyApp().controller.load(userNameTextField.text, passwordTextField.text); - MyApp().controller.currentUser = User(userNameTextField.text, passwordTextField.text); + MyApp().controller.currentUser = User(username, password); Navigator.of(context).push( PageTransition( type: PageTransitionType.fade, 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 af4f2d4..70b9afb 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 @@ -298,15 +298,17 @@ class _SignUpPageState extends State { ); } - Future checkInformations(String username,String password, String confirmPassword) async { - if(username ==""){ + + Future checkInformations(String username, String password, String confirmPassword) async { + + if(username == ""){ Notify(2, context); } else if(! await MyApp().controller.searchByUsername(username)){ Notify(0, context); } - /* - else if(password =="" || confirmPassword == ""){ + + if(password == "" || confirmPassword == ""){ Notify(4, context); } else if(password.length <8){ @@ -315,12 +317,9 @@ class _SignUpPageState extends State { else if(password != confirmPassword){ Notify(1, context); } - else if(password != confirmPassword){ - Notify(1, context); - } - */ else{ - MyApp().controller.save(User(userNameTextField.text, passwordConfirmTextField.text)); + MyApp().controller.save(User(username, password)); + Navigator.of(context).push( PageTransition( duration: Duration(milliseconds: 300), diff --git a/Sources/dafl_project_flutter/pubspec.yaml b/Sources/dafl_project_flutter/pubspec.yaml index 728a5f8..f06d927 100644 --- a/Sources/dafl_project_flutter/pubspec.yaml +++ b/Sources/dafl_project_flutter/pubspec.yaml @@ -89,6 +89,7 @@ flutter: assets: - assets/images/ - assets/fonts/ + - assets/ # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware