diff --git a/Sources/justMUSIC/lib/main.dart b/Sources/justMUSIC/lib/main.dart index 283502a..4b5ce53 100644 --- a/Sources/justMUSIC/lib/main.dart +++ b/Sources/justMUSIC/lib/main.dart @@ -60,7 +60,7 @@ class MyApp extends StatelessWidget { // is not restarted. primarySwatch: Colors.blue, ), - home: LoginScreen()); + home: WellcomeScreen()); }, designSize: Size(390, 844), ); diff --git a/Sources/justMUSIC/lib/model/mapper/UserMapper.dart b/Sources/justMUSIC/lib/model/mapper/UserMapper.dart index 25a8900..baca8fe 100644 --- a/Sources/justMUSIC/lib/model/mapper/UserMapper.dart +++ b/Sources/justMUSIC/lib/model/mapper/UserMapper.dart @@ -1,14 +1,9 @@ import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:justmusic/model/User.dart'; -import 'package:firebase_auth/firebase_auth.dart' as firebase_auth; -import '../../main.dart'; class UserMapper { - static User? toModel(DocumentSnapshot>? snapshot, + static User toModel(DocumentSnapshot> snapshot, SnapshotOptions? options) { - if (snapshot == null) { - return null; - } final data = snapshot.data(); return User( data?["uid"], diff --git a/Sources/justMUSIC/lib/screens/login_screen.dart b/Sources/justMUSIC/lib/screens/login_screen.dart index 58b52f4..16dd4d2 100644 --- a/Sources/justMUSIC/lib/screens/login_screen.dart +++ b/Sources/justMUSIC/lib/screens/login_screen.dart @@ -30,11 +30,10 @@ class _LoginScreenState extends State { .login(_userMailTextField.text, _passwordTextField.text); Navigator.pushNamed(context, '/explanation'); } catch (e) { - print(e); ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text( - e.toString(), + "Erreur: Email ou mot de passe incorrect", style: GoogleFonts.plusJakartaSans( color: Colors.white, fontWeight: FontWeight.w400, @@ -71,7 +70,7 @@ class _LoginScreenState extends State { CrossAxisAlignment.center, children: [ Flexible( - flex: 5, + flex: 4, child: Padding( padding: EdgeInsets.only(bottom: 60), child: Column( @@ -108,10 +107,12 @@ class _LoginScreenState extends State { ), ), Expanded( - flex: 4, + flex: 5, child: Column( crossAxisAlignment: CrossAxisAlignment.end, + mainAxisAlignment: + MainAxisAlignment.center, children: [ TextFormField( controller: _userMailTextField, @@ -138,25 +139,24 @@ class _LoginScreenState extends State { strokeTextField), borderRadius: BorderRadius.all( Radius.circular(10))), - contentPadding: - EdgeInsets.only( - top: 0, - bottom: 0, - left: defaultPadding), + prefix: const Padding( + padding: EdgeInsets.only( + left: 20.0)), + suffix: const Padding( + padding: EdgeInsets.only( + left: 20.0)), fillColor: bgTextField, filled: true, + errorStyle: TextStyle( + fontSize: 9, height: 0.3), focusColor: Color.fromRGBO( 255, 255, 255, 0.30), enabledBorder: OutlineInputBorder( - borderSide: BorderSide( - width: 1, - color: - strokeTextField), - borderRadius: BorderRadius.all( - Radius.circular(10))), + borderSide: + BorderSide(width: 1, color: strokeTextField), + borderRadius: BorderRadius.all(Radius.circular(10))), hintText: 'Email', - hintStyle: - GoogleFonts.plusJakartaSans(color: strokeTextField)), + hintStyle: GoogleFonts.plusJakartaSans(color: strokeTextField)), ), SizedBox( height: 18, @@ -174,8 +174,6 @@ class _LoginScreenState extends State { return null; }, cursorColor: primaryColor, - keyboardType: - TextInputType.emailAddress, style: GoogleFonts.plusJakartaSans( color: primaryColor), @@ -190,10 +188,6 @@ class _LoginScreenState extends State { BorderRadius.all( Radius.circular( 10))), - contentPadding: EdgeInsets.only( - top: 0, - bottom: 0, - left: defaultPadding), fillColor: bgTextField, filled: true, focusColor: Color.fromRGBO( @@ -212,6 +206,9 @@ class _LoginScreenState extends State { hintStyle: GoogleFonts.plusJakartaSans( color: strokeTextField), + prefix: const Padding( + padding: EdgeInsets.only( + left: 20.0)), suffixIcon: Container( padding: EdgeInsets.only( right: 10), @@ -240,6 +237,8 @@ class _LoginScreenState extends State { height: 2, ), )), + errorStyle: TextStyle( + fontSize: 9, height: 0.3), ), ), Padding( @@ -259,6 +258,46 @@ class _LoginScreenState extends State { child: LoginButton( callback: handleLogin, )), + Align( + child: GestureDetector( + onTap: () { + Navigator.pushNamed( + context, '/register'); + }, + child: Padding( + padding: + EdgeInsets.only(top: 20), + child: RichText( + textAlign: TextAlign.center, + text: TextSpan( + text: + 'Pas encore inscrit?', + style: GoogleFonts + .plusJakartaSans( + color: + Colors.white, + fontWeight: + FontWeight + .w400, + fontSize: 15), + children: [ + TextSpan( + text: " S’inscire", + style: GoogleFonts + .plusJakartaSans( + fontSize: + 15, + fontWeight: + FontWeight + .w400, + color: + primaryColor)), + ], + ), + ), + ), + ), + ), ], ), ), @@ -321,38 +360,6 @@ class _LoginScreenState extends State { text: "Login with Google", onPressed: () {}, ), - Padding( - padding: - EdgeInsets.only(top: 20), - child: RichText( - textAlign: TextAlign.center, - text: TextSpan( - text: - 'Pas encore inscrit?', - style: GoogleFonts - .plusJakartaSans( - color: - Colors.white, - fontWeight: - FontWeight - .w400, - fontSize: 13), - children: [ - TextSpan( - text: " S’inscire", - style: GoogleFonts - .plusJakartaSans( - fontSize: - 13, - fontWeight: - FontWeight - .w400, - color: - primaryColor)), - ], - ), - ), - ) ], ), )) diff --git a/Sources/justMUSIC/lib/screens/registration_screen.dart b/Sources/justMUSIC/lib/screens/registration_screen.dart index ff62533..ece7456 100644 --- a/Sources/justMUSIC/lib/screens/registration_screen.dart +++ b/Sources/justMUSIC/lib/screens/registration_screen.dart @@ -292,6 +292,34 @@ class _RegistrationScreenState extends State { callback: () {}, )), ), + Align( + child: GestureDetector( + onTap: () { + Navigator.pushNamed(context, '/login'); + }, + child: Padding( + padding: EdgeInsets.only(top: 20), + child: RichText( + textAlign: TextAlign.center, + text: TextSpan( + text: 'Tu as déjà un compte?', + style: GoogleFonts.plusJakartaSans( + color: Colors.white, + fontWeight: FontWeight.w400, + fontSize: 15), + children: [ + TextSpan( + text: " Connexion", + style: GoogleFonts.plusJakartaSans( + fontSize: 15, + fontWeight: FontWeight.w400, + color: primaryColor)), + ], + ), + ), + ), + ), + ), ], )), SizedBox(height: 50.h), diff --git a/Sources/justMUSIC/lib/screens/welcome_screen.dart b/Sources/justMUSIC/lib/screens/welcome_screen.dart index 5ba91e5..1d61dbc 100644 --- a/Sources/justMUSIC/lib/screens/welcome_screen.dart +++ b/Sources/justMUSIC/lib/screens/welcome_screen.dart @@ -71,12 +71,20 @@ class WellcomeScreen extends StatelessWidget { SizedBox( height: defaultPadding, ), - Text( - "Tu as déja un compte? Connexion", - style: GoogleFonts.plusJakartaSans( - color: Colors.white, - fontWeight: FontWeight.w400, - fontSize: 15), + GestureDetector( + onTap: () { + Navigator.pushNamed(context, '/login'); + }, + child: Padding( + padding: const EdgeInsets.all(3.0), + child: Text( + "Tu as déja un compte? Connexion", + style: GoogleFonts.plusJakartaSans( + color: Colors.white, + fontWeight: FontWeight.w400, + fontSize: 15), + ), + ), ), ], ), diff --git a/Sources/justMUSIC/lib/view_model/UserViewModel.dart b/Sources/justMUSIC/lib/view_model/UserViewModel.dart index d4bbfa7..881dda3 100644 --- a/Sources/justMUSIC/lib/view_model/UserViewModel.dart +++ b/Sources/justMUSIC/lib/view_model/UserViewModel.dart @@ -1,4 +1,3 @@ -import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_auth/firebase_auth.dart' as firebase_auth; import 'package:justmusic/service/AuthService.dart'; @@ -25,19 +24,17 @@ class UserViewModel { } login(String pseudo, String password) async { - await _authService.login(pseudo, password); - if (firebase_auth.FirebaseAuth.instance.currentUser == null) { - throw Exception("User login failed"); + try { + await _authService.login(pseudo, password); + final user = await MyApp.db + .collection("users") + .doc(firebase_auth.FirebaseAuth.instance.currentUser?.uid) + .get(); + User data = UserMapper.toModel(user, null); + _userCurrent = data; + } catch (e) { + throw Exception("Erreur: Email ou mot de passe incorrect"); } - final user = await MyApp.db - .collection("users") - .doc(firebase_auth.FirebaseAuth.instance.currentUser?.uid) - .get(); - User? data = UserMapper.toModel(user, null); - if (data == null) { - throw Exception("User login failed"); - } - _userCurrent = data; } register(String pseudo, String password, String email) async { @@ -47,9 +44,6 @@ class UserViewModel { .doc(firebase_auth.FirebaseAuth.instance.currentUser?.uid) .get(); User? data = UserMapper.toModel(user, null); - if (data == null) { - throw Exception("User register failed"); - } _userCurrent = data; }