From 600550a57ce3fea16608d636de2ffb5aa4723773 Mon Sep 17 00:00:00 2001 From: delanierlucas Date: Wed, 2 Nov 2022 11:02:47 +0100 Subject: [PATCH] merge master --- .idea/Daflv4.iml | 6 + .idea/libraries/Dart_Packages.xml | 160 ++++++++++++++++++ Sources/dafl_project_flutter/ios/Podfile.lock | 6 + .../lib/controller/controller.dart | 11 ++ .../dafl_project_flutter/lib/model/user.dart | 4 +- .../lib/persistence/database_connexion.dart | 46 +++++ .../lib/persistence/database_loader.dart | 21 +++ .../lib/persistence/database_saver.dart | 19 +++ .../lib/persistence/database_search.dart | 0 .../lib/persistence/loader.dart | 7 + .../lib/persistence/saver.dart | 5 + .../lib/persistence/search.dart | 6 + .../lib/views/pages/main/w_discovery.dart | 6 +- .../lib/views/pages/sign_in/p_sign_in.dart | 2 +- .../lib/views/pages/sign_up/p_sign_up.dart | 6 +- Sources/dafl_project_flutter/pubspec.lock | 140 +++++++++++++++ Sources/dafl_project_flutter/pubspec.yaml | 3 + 17 files changed, 441 insertions(+), 7 deletions(-) create mode 100644 Sources/dafl_project_flutter/lib/persistence/database_connexion.dart create mode 100644 Sources/dafl_project_flutter/lib/persistence/database_loader.dart create mode 100644 Sources/dafl_project_flutter/lib/persistence/database_saver.dart create mode 100644 Sources/dafl_project_flutter/lib/persistence/database_search.dart create mode 100644 Sources/dafl_project_flutter/lib/persistence/loader.dart create mode 100644 Sources/dafl_project_flutter/lib/persistence/saver.dart create mode 100644 Sources/dafl_project_flutter/lib/persistence/search.dart diff --git a/.idea/Daflv4.iml b/.idea/Daflv4.iml index 8422991..508dab8 100644 --- a/.idea/Daflv4.iml +++ b/.idea/Daflv4.iml @@ -24,6 +24,12 @@ + + + + + + diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml index 1bb776b..6362b19 100644 --- a/.idea/libraries/Dart_Packages.xml +++ b/.idea/libraries/Dart_Packages.xml @@ -44,6 +44,13 @@ + + + + + + @@ -72,6 +79,13 @@ + + + + + + @@ -100,6 +114,20 @@ + + + + + + + + + + + + @@ -212,6 +240,13 @@ + + + + + + @@ -233,6 +268,13 @@ + + + + + + @@ -254,6 +296,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -261,6 +352,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -268,6 +387,13 @@ + + + + + + @@ -352,6 +478,20 @@ + + + + + + + + + + + + @@ -375,14 +515,18 @@ + + + + @@ -396,14 +540,28 @@ + + + + + + + + + + + + + + @@ -415,6 +573,8 @@ + + diff --git a/Sources/dafl_project_flutter/ios/Podfile.lock b/Sources/dafl_project_flutter/ios/Podfile.lock index efc9b1f..6d41903 100644 --- a/Sources/dafl_project_flutter/ios/Podfile.lock +++ b/Sources/dafl_project_flutter/ios/Podfile.lock @@ -5,6 +5,8 @@ PODS: - fluttertoast (0.0.2): - Flutter - Toast + - path_provider_ios (0.0.1): + - Flutter - Toast (4.0.0) - vibration (1.7.5): - Flutter @@ -13,6 +15,7 @@ DEPENDENCIES: - Flutter (from `Flutter`) - flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`) - fluttertoast (from `.symlinks/plugins/fluttertoast/ios`) + - path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`) - vibration (from `.symlinks/plugins/vibration/ios`) SPEC REPOS: @@ -26,6 +29,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/flutter_native_splash/ios" fluttertoast: :path: ".symlinks/plugins/fluttertoast/ios" + path_provider_ios: + :path: ".symlinks/plugins/path_provider_ios/ios" vibration: :path: ".symlinks/plugins/vibration/ios" @@ -33,6 +38,7 @@ SPEC CHECKSUMS: Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef fluttertoast: 74526702fea2c060ea55dde75895b7e1bde1c86b + path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02 Toast: 91b396c56ee72a5790816f40d3a94dd357abc196 vibration: 7d883d141656a1c1a6d8d238616b2042a51a1241 diff --git a/Sources/dafl_project_flutter/lib/controller/controller.dart b/Sources/dafl_project_flutter/lib/controller/controller.dart index 02e8115..053e331 100644 --- a/Sources/dafl_project_flutter/lib/controller/controller.dart +++ b/Sources/dafl_project_flutter/lib/controller/controller.dart @@ -1,9 +1,18 @@ +import '../persistence/database_loader.dart'; +import '../persistence/database_saver.dart'; +import '../persistence/loader.dart'; + +import '../persistence/saver.dart'; +import '../persistence/loader.dart'; import '../model/user.dart'; class Controller{ static Controller? _this; + static Saver? saver = DatabaseSaver(); + static Loader? loader = DatabaseLoader(); + User currentUser = User(null, null); factory Controller(){ @@ -14,9 +23,11 @@ class Controller{ Controller._(); void save(User userToSave){ + saver?.save(userToSave); } void load(String username, String password) async{ + currentUser = await loader?.load(username, password) as User; } 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 2951e1d..f1063a4 100644 --- a/Sources/dafl_project_flutter/lib/model/user.dart +++ b/Sources/dafl_project_flutter/lib/model/user.dart @@ -39,11 +39,11 @@ class User{ Map conversations={}; 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/persistence/database_connexion.dart b/Sources/dafl_project_flutter/lib/persistence/database_connexion.dart new file mode 100644 index 0000000..f83108a --- /dev/null +++ b/Sources/dafl_project_flutter/lib/persistence/database_connexion.dart @@ -0,0 +1,46 @@ +import 'dart:convert'; +import 'dart:io'; + +import 'package:flutter/services.dart'; +import 'package:path_provider/path_provider.dart'; + +import '../model/user.dart'; +import 'package:postgresql2/constants.dart'; +import 'package:postgresql2/pool.dart'; +import 'package:postgresql2/postgresql.dart'; + +class DatabaseConnexion{ + final String filePath = '../../assets/logs.txt'; + + String? _psqlUser; + String? _psqlPswd; + String? _psqlHost; + String? _psqlDataBase; + + + Future _loadLogs() async{ + try{ + final _loadedData = await rootBundle.loadString(filePath); + + final _logs = LineSplitter.split(_loadedData).toList(); + + _psqlUser = _logs[0]; + _psqlPswd = _logs[1]; + _psqlHost = _logs[2]; + _psqlDataBase = _logs[3]; + } + catch(e){ + throw Exception('Logs file Not Found'); + } + } + + + //Initialise connexion to the database + Future initConnexion() async{ + await _loadLogs(); + + var uri = 'postgres://$_psqlUser:$_psqlPswd@$_psqlHost:5442/$_psqlDataBase'; + + return connect(uri); + } +} \ 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 new file mode 100644 index 0000000..a632976 --- /dev/null +++ b/Sources/dafl_project_flutter/lib/persistence/database_loader.dart @@ -0,0 +1,21 @@ +import 'dart:async'; + +import 'loader.dart'; +import '../model/user.dart'; +import 'database_connexion.dart'; + +class DatabaseLoader extends Loader{ + DatabaseConnexion dbConnexion = DatabaseConnexion(); + + + @override + Future load(String? username, String? password) async { + final connection = await dbConnexion.initConnexion(); + + connection.query('select * from utilisateur where username = @username AND password = @password', + {'username': username, + 'password': password}).toList() + .then((result) { + print(result); }); + } +} diff --git a/Sources/dafl_project_flutter/lib/persistence/database_saver.dart b/Sources/dafl_project_flutter/lib/persistence/database_saver.dart new file mode 100644 index 0000000..53d70fe --- /dev/null +++ b/Sources/dafl_project_flutter/lib/persistence/database_saver.dart @@ -0,0 +1,19 @@ +import 'dart:io'; +import 'database_connexion.dart'; +import 'saver.dart'; +import '../model/user.dart'; + + +class DatabaseSaver extends Saver{ + DatabaseConnexion dbConnexion = DatabaseConnexion(); + + @override + void save(User userToSave) async{ + final connection = await dbConnexion.initConnexion(); + + connection.execute('insert into utilisateur (username, password) values (@username, @password)', + { 'id' : '', + 'username': userToSave.usernameDafl, + 'password' : userToSave.passwDafl}).then((_) {}); + } +} \ No newline at end of file diff --git a/Sources/dafl_project_flutter/lib/persistence/database_search.dart b/Sources/dafl_project_flutter/lib/persistence/database_search.dart new file mode 100644 index 0000000..e69de29 diff --git a/Sources/dafl_project_flutter/lib/persistence/loader.dart b/Sources/dafl_project_flutter/lib/persistence/loader.dart new file mode 100644 index 0000000..cf64cee --- /dev/null +++ b/Sources/dafl_project_flutter/lib/persistence/loader.dart @@ -0,0 +1,7 @@ +import 'dart:async'; + +import '../model/user.dart'; + +abstract class Loader{ + Future load(String? username, String? password); +} \ No newline at end of file diff --git a/Sources/dafl_project_flutter/lib/persistence/saver.dart b/Sources/dafl_project_flutter/lib/persistence/saver.dart new file mode 100644 index 0000000..da1ca5d --- /dev/null +++ b/Sources/dafl_project_flutter/lib/persistence/saver.dart @@ -0,0 +1,5 @@ +import '../model/user.dart'; + +abstract class Saver{ + void save(User userToSave); +} \ No newline at end of file diff --git a/Sources/dafl_project_flutter/lib/persistence/search.dart b/Sources/dafl_project_flutter/lib/persistence/search.dart new file mode 100644 index 0000000..76bb714 --- /dev/null +++ b/Sources/dafl_project_flutter/lib/persistence/search.dart @@ -0,0 +1,6 @@ +import '../model/user.dart'; + +abstract class Search{ + bool searchUser(String? username, String? password); + bool searchUsername(String? username); +} \ No newline at end of file diff --git a/Sources/dafl_project_flutter/lib/views/pages/main/w_discovery.dart b/Sources/dafl_project_flutter/lib/views/pages/main/w_discovery.dart index 6eb1a42..cb1fc71 100644 --- a/Sources/dafl_project_flutter/lib/views/pages/main/w_discovery.dart +++ b/Sources/dafl_project_flutter/lib/views/pages/main/w_discovery.dart @@ -113,8 +113,8 @@ class _DiscoveryListState extends State { crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, children: [ - Text(MyApp().controller.currentUser.Discovery[reversedIndex].name ?? '',style: TextStyle(fontFamily: 'DMSans', color: Colors.white.withOpacity(1) ,fontSize: 20, fontWeight: FontWeight.w800),), - Text(MyApp().controller.currentUser.Discovery[reversedIndex].artist ?? '',style: TextStyle(fontFamily: 'DMSans', color: Colors.white.withOpacity(0.6) ,fontSize: 16, fontWeight: FontWeight.w400),), + Text(MyApp().controller.currentUser?.Discovery[reversedIndex].name ?? '',style: TextStyle(fontFamily: 'DMSans', color: Colors.white.withOpacity(1) ,fontSize: 20, fontWeight: FontWeight.w800),), + Text(MyApp().controller.currentUser?.Discovery[reversedIndex].artist ?? '',style: TextStyle(fontFamily: 'DMSans', color: Colors.white.withOpacity(0.6) ,fontSize: 16, fontWeight: FontWeight.w400),), ], ),), @@ -128,7 +128,7 @@ class _DiscoveryListState extends State { ), onDismissed: (direction) { if(direction == DismissDirection.startToEnd) - MyApp().controller.currentUser.Discovery.removeAt(reversedIndex); + MyApp().controller.currentUser?.Discovery.removeAt(reversedIndex); }, background: Container(decoration: BoxDecoration( image: DecorationImage(image: AssetImage("assets/images/delete_background.png"), fit: BoxFit.cover), 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 e6416c7..bfd0439 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 @@ -236,7 +236,7 @@ class _SignInPageState extends State { Notify(4, context); } else{ - MyApp().controller.changeCurrentUser(MyApp().controller.createUser(userNameTextField.text, passwordTextField.text)); + MyApp().controller.load(userNameTextField.text, passwordTextField.text); 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 7ee6f17..deeb72d 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 @@ -2,6 +2,7 @@ import 'package:dafl_project_flutter/main.dart'; import 'package:flutter/material.dart'; import 'package:page_transition/page_transition.dart'; import 'package:rive/rive.dart' as riv; +import '../../../model/user.dart'; import '../home/p_home.dart'; import '../sign_in/p_sign_in.dart'; import '../../../controller/controller.dart'; @@ -310,8 +311,11 @@ class _SignUpPageState extends State { else if(password != confirmPassword){ Notify(1, context); } + else if(password != confirmPassword){ + Notify(1, context); + } else{ - MyApp().controller.createUser(userNameTextField.text, passwordConfirmTextField.text); + MyApp().controller.save(User(userNameTextField.text, passwordConfirmTextField.text)); Navigator.of(context).push( PageTransition( duration: Duration(milliseconds: 300), diff --git a/Sources/dafl_project_flutter/pubspec.lock b/Sources/dafl_project_flutter/pubspec.lock index 552dcf5..96388e7 100644 --- a/Sources/dafl_project_flutter/pubspec.lock +++ b/Sources/dafl_project_flutter/pubspec.lock @@ -43,6 +43,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.2.1" + charcode: + dependency: transitive + description: + name: charcode + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" checked_yaml: dependency: transitive description: @@ -71,6 +78,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.16.0" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.1" crypto: dependency: transitive description: @@ -99,6 +113,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.1" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.4" flutter: dependency: "direct main" description: flutter @@ -205,6 +233,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.0" + logging: + dependency: transitive + description: + name: logging + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" matcher: dependency: transitive description: @@ -226,6 +261,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" + mime: + dependency: transitive + description: + name: mime + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" nested: dependency: transitive description: @@ -247,6 +289,55 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.2" + path_provider: + dependency: "direct main" + description: + name: path_provider + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.11" + path_provider_android: + dependency: transitive + description: + name: path_provider_android + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.21" + path_provider_ios: + dependency: transitive + description: + name: path_provider_ios + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.11" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.7" + path_provider_macos: + dependency: transitive + description: + name: path_provider_macos + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.6" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" petitparser: dependency: transitive description: @@ -254,6 +345,34 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "5.0.0" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" + postgresql2: + dependency: "direct main" + description: + name: postgresql2 + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "4.2.4" provider: dependency: "direct main" description: @@ -261,6 +380,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "6.0.4" + rikulo_commons: + dependency: transitive + description: + name: rikulo_commons + url: "https://pub.dartlang.org" + source: hosted + version: "5.2.1" rive: dependency: "direct main" description: @@ -343,6 +469,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.7.6" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0+2" xml: dependency: transitive description: diff --git a/Sources/dafl_project_flutter/pubspec.yaml b/Sources/dafl_project_flutter/pubspec.yaml index cbd0b78..e41b996 100644 --- a/Sources/dafl_project_flutter/pubspec.yaml +++ b/Sources/dafl_project_flutter/pubspec.yaml @@ -43,6 +43,8 @@ dependencies: animations: ^2.0.7 fluttertoast: ^8.1.1 vibration: ^1.7.6 + postgresql2: ^1.0.3 + path_provider: ^2.0.11 dev_dependencies: flutter_test: @@ -87,6 +89,7 @@ flutter: assets: - assets/images/ - assets/fonts/ + - assets/logs.txt # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware