Fix : Modification des attributs nullable et non nullable, late pour instanciation future.
continuous-integration/drone/push Build is passing Details

messagerie_lucas_test
Audric SABATIER 2 years ago
parent 36e8d5faba
commit 0784d8f074

@ -16,7 +16,7 @@ class Controller{
static Loader? loader = DatabaseLoader(); static Loader? loader = DatabaseLoader();
static Searcher _searcher = DatabaseSearcher(); static Searcher _searcher = DatabaseSearcher();
User currentUser = User(null, null); User currentUser = User("", "");
factory Controller(){ factory Controller(){
if (_this == null) _this = Controller._(); if (_this == null) _this = Controller._();

@ -6,19 +6,40 @@ import 'music.dart';
class User{ class User{
//attributes from DAFL //attributes from DAFL
int? idDafl; late int _idDafl;
String? usernameDafl; late String _usernameDafl;
String? passwDafl; late String _passwDafl;
//attributes to link with API //attributes to link with API
String? usernameAPI; late String _usernameAPI;
String? passwAPI; 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 //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 //lists
Set<User> likedUsers={}; Set<User> likedUsers={};
@ -38,6 +59,10 @@ class User{
Music('Paradis','Sopico','https://cdns-images.dzcdn.net/images/cover/17a9747927ac3e5ea56f92f635d9180c/500x500.jpg')].reversed.toList(); Music('Paradis','Sopico','https://cdns-images.dzcdn.net/images/cover/17a9747927ac3e5ea56f92f635d9180c/500x500.jpg')].reversed.toList();
Map<User,Conversation> conversations={}; Map<User,Conversation> conversations={};
void addDiscovery(Music newmusic){ void addDiscovery(Music newmusic){
if(MyApp().controller?.currentUser?.Discovery == null){ if(MyApp().controller?.currentUser?.Discovery == null){

@ -21,13 +21,13 @@ class DatabaseConnexion{
static String? _psqlDataBase; static String? _psqlDataBase;
// Read the database connection identifiers in a file // Read the database connection identifiers in a file
static Future<void> _loadLogs() async{ static Future<void> _loadLogs() async{
try{ try{
final _loadedData = await rootBundle.loadString(filePath); final _loadedData = await rootBundle.loadString(filePath);
print('appel de -readLogs');
final _logs = LineSplitter.split(_loadedData).toList(); final _logs = LineSplitter.split(_loadedData).toList();
_psqlUser = _logs[0]; _psqlUser = _logs[0];
@ -42,14 +42,19 @@ class DatabaseConnexion{
//Initialise connexion to the database //Initialise and open a connection to the database
static Future<Connection> initConnexion() async{ static Future<Connection> initConnexion() async{
if(_psqlHost == null || _psqlPswd == null || _psqlUser == null || _psqlDataBase == null){ if(_psqlHost == null || _psqlPswd == null || _psqlUser == null || _psqlDataBase == null){
await _loadLogs(); await _loadLogs();
} }
try{
var uri = 'postgres://$_psqlUser:$_psqlPswd@$_psqlHost:5442/$_psqlDataBase'; var uri = 'postgres://$_psqlUser:$_psqlPswd@$_psqlHost:5442/$_psqlDataBase';
return connect(uri); return connect(uri);
} }
catch(e){
throw Exception('Connection to database : IMPOSSIBLE');
}
}
} }

@ -6,15 +6,23 @@ import 'database_connexion.dart';
class DatabaseLoader extends Loader{ class DatabaseLoader extends Loader{
// Load an user from database
@override @override
Future<User?> load(String? username, String? password) async { Future<User?> load(String username, String password) async {
User? userToReturn = null;
final connection = await DatabaseConnexion.initConnexion(); final connection = await DatabaseConnexion.initConnexion();
connection.query('select * from utilisateur where username = @username AND password = @password', connection.query('select * from utilisateur where username = @username AND password = @password',
{'username': username, {'username': username,
'password': password}).toList() 'password': password}).toList()
.then((result) { .then((result) {
print(result); }); if(result.isNotEmpty){
userToReturn = User(username, password);
} }
}).whenComplete(() {
connection.close();});
return userToReturn;
}
} }

@ -5,7 +5,6 @@ import '../model/user.dart';
class DatabaseSaver extends Saver{ class DatabaseSaver extends Saver{
DatabaseConnexion dbConnexion = DatabaseConnexion();
@override @override
void save(User userToSave) async{ void save(User userToSave) async{

@ -3,21 +3,23 @@ import 'package:dafl_project_flutter/persistence/database_connexion.dart';
import 'searcher.dart'; import 'searcher.dart';
class DatabaseSearcher extends Searcher{ class DatabaseSearcher extends Searcher{
Future<bool> searchUser(String? username, String? password) async { return true; } Future<bool> searchUser(String? username, String? password) async { return true; }
@override @override
Future<bool> searchByUsername(String? username) async{ Future<bool> searchByUsername(String? username) async{
final connection = await DatabaseConnexion.initConnexion(); final connection = await DatabaseConnexion.initConnexion();
bool isHere = true;
connection.query('select * from utilisateur where username = $username').toList().then((rows) { connection.query('select * from utilisateur where username = $username').toList().then((rows) {
if(rows.isEmpty){ if(rows.isEmpty){
connection.close(); isHere = false;
return false;
} }
}).whenComplete(() {
print('close');
}); });
connection.close(); return isHere;
return true;
} }
} }

@ -3,5 +3,5 @@ import 'dart:async';
import '../model/user.dart'; import '../model/user.dart';
abstract class Loader{ abstract class Loader{
Future<User?> load(String? username, String? password); Future<User?> load(String username, String password);
} }

@ -229,6 +229,7 @@ class _SignInPageState extends State<SignInPage> {
); );
} }
void checkInformations(String username,String password){ void checkInformations(String username,String password){
if(username ==""){ if(username ==""){
Notify(2, context); Notify(2, context);
@ -238,7 +239,7 @@ class _SignInPageState extends State<SignInPage> {
} }
else{ else{
//MyApp().controller.load(userNameTextField.text, passwordTextField.text); //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( Navigator.of(context).push(
PageTransition( PageTransition(
type: PageTransitionType.fade, type: PageTransitionType.fade,

@ -298,15 +298,17 @@ class _SignUpPageState extends State<SignUpPage> {
); );
} }
Future<void> checkInformations(String username,String password, String confirmPassword) async {
if(username ==""){ Future<void> checkInformations(String username, String password, String confirmPassword) async {
if(username == ""){
Notify(2, context); Notify(2, context);
} }
else if(! await MyApp().controller.searchByUsername(username)){ else if(! await MyApp().controller.searchByUsername(username)){
Notify(0, context); Notify(0, context);
} }
/*
else if(password =="" || confirmPassword == ""){ if(password == "" || confirmPassword == ""){
Notify(4, context); Notify(4, context);
} }
else if(password.length <8){ else if(password.length <8){
@ -315,12 +317,9 @@ class _SignUpPageState extends State<SignUpPage> {
else if(password != confirmPassword){ else if(password != confirmPassword){
Notify(1, context); Notify(1, context);
} }
else if(password != confirmPassword){
Notify(1, context);
}
*/
else{ else{
MyApp().controller.save(User(userNameTextField.text, passwordConfirmTextField.text)); MyApp().controller.save(User(username, password));
Navigator.of(context).push( Navigator.of(context).push(
PageTransition( PageTransition(
duration: Duration(milliseconds: 300), duration: Duration(milliseconds: 300),

@ -89,6 +89,7 @@ flutter:
assets: assets:
- assets/images/ - assets/images/
- assets/fonts/ - assets/fonts/
- assets/
# An image asset can refer to one or more resolution-specific "variants", see # An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware # https://flutter.dev/assets-and-images/#resolution-aware

Loading…
Cancel
Save