pull/28/head
Lucas Delanier 2 years ago
parent 2c11b6f44a
commit 75c7139442

@ -60,7 +60,7 @@ class MyApp extends StatelessWidget {
// is not restarted. // is not restarted.
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
), ),
home: LoginScreen()); home: WellcomeScreen());
}, },
designSize: Size(390, 844), designSize: Size(390, 844),
); );

@ -1,14 +1,9 @@
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:justmusic/model/User.dart'; import 'package:justmusic/model/User.dart';
import 'package:firebase_auth/firebase_auth.dart' as firebase_auth;
import '../../main.dart';
class UserMapper { class UserMapper {
static User? toModel(DocumentSnapshot<Map<String, dynamic>>? snapshot, static User toModel(DocumentSnapshot<Map<String, dynamic>> snapshot,
SnapshotOptions? options) { SnapshotOptions? options) {
if (snapshot == null) {
return null;
}
final data = snapshot.data(); final data = snapshot.data();
return User( return User(
data?["uid"], data?["uid"],

@ -30,11 +30,10 @@ class _LoginScreenState extends State<LoginScreen> {
.login(_userMailTextField.text, _passwordTextField.text); .login(_userMailTextField.text, _passwordTextField.text);
Navigator.pushNamed(context, '/explanation'); Navigator.pushNamed(context, '/explanation');
} catch (e) { } catch (e) {
print(e);
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: Text( content: Text(
e.toString(), "Erreur: Email ou mot de passe incorrect",
style: GoogleFonts.plusJakartaSans( style: GoogleFonts.plusJakartaSans(
color: Colors.white, color: Colors.white,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
@ -71,7 +70,7 @@ class _LoginScreenState extends State<LoginScreen> {
CrossAxisAlignment.center, CrossAxisAlignment.center,
children: [ children: [
Flexible( Flexible(
flex: 5, flex: 4,
child: Padding( child: Padding(
padding: EdgeInsets.only(bottom: 60), padding: EdgeInsets.only(bottom: 60),
child: Column( child: Column(
@ -108,10 +107,12 @@ class _LoginScreenState extends State<LoginScreen> {
), ),
), ),
Expanded( Expanded(
flex: 4, flex: 5,
child: Column( child: Column(
crossAxisAlignment: crossAxisAlignment:
CrossAxisAlignment.end, CrossAxisAlignment.end,
mainAxisAlignment:
MainAxisAlignment.center,
children: [ children: [
TextFormField( TextFormField(
controller: _userMailTextField, controller: _userMailTextField,
@ -138,25 +139,24 @@ class _LoginScreenState extends State<LoginScreen> {
strokeTextField), strokeTextField),
borderRadius: BorderRadius.all( borderRadius: BorderRadius.all(
Radius.circular(10))), Radius.circular(10))),
contentPadding: prefix: const Padding(
EdgeInsets.only( padding: EdgeInsets.only(
top: 0, left: 20.0)),
bottom: 0, suffix: const Padding(
left: defaultPadding), padding: EdgeInsets.only(
left: 20.0)),
fillColor: bgTextField, fillColor: bgTextField,
filled: true, filled: true,
errorStyle: TextStyle(
fontSize: 9, height: 0.3),
focusColor: Color.fromRGBO( focusColor: Color.fromRGBO(
255, 255, 255, 0.30), 255, 255, 255, 0.30),
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderSide: BorderSide( borderSide:
width: 1, BorderSide(width: 1, color: strokeTextField),
color: borderRadius: BorderRadius.all(Radius.circular(10))),
strokeTextField),
borderRadius: BorderRadius.all(
Radius.circular(10))),
hintText: 'Email', hintText: 'Email',
hintStyle: hintStyle: GoogleFonts.plusJakartaSans(color: strokeTextField)),
GoogleFonts.plusJakartaSans(color: strokeTextField)),
), ),
SizedBox( SizedBox(
height: 18, height: 18,
@ -174,8 +174,6 @@ class _LoginScreenState extends State<LoginScreen> {
return null; return null;
}, },
cursorColor: primaryColor, cursorColor: primaryColor,
keyboardType:
TextInputType.emailAddress,
style: style:
GoogleFonts.plusJakartaSans( GoogleFonts.plusJakartaSans(
color: primaryColor), color: primaryColor),
@ -190,10 +188,6 @@ class _LoginScreenState extends State<LoginScreen> {
BorderRadius.all( BorderRadius.all(
Radius.circular( Radius.circular(
10))), 10))),
contentPadding: EdgeInsets.only(
top: 0,
bottom: 0,
left: defaultPadding),
fillColor: bgTextField, fillColor: bgTextField,
filled: true, filled: true,
focusColor: Color.fromRGBO( focusColor: Color.fromRGBO(
@ -212,6 +206,9 @@ class _LoginScreenState extends State<LoginScreen> {
hintStyle: hintStyle:
GoogleFonts.plusJakartaSans( GoogleFonts.plusJakartaSans(
color: strokeTextField), color: strokeTextField),
prefix: const Padding(
padding: EdgeInsets.only(
left: 20.0)),
suffixIcon: Container( suffixIcon: Container(
padding: EdgeInsets.only( padding: EdgeInsets.only(
right: 10), right: 10),
@ -240,6 +237,8 @@ class _LoginScreenState extends State<LoginScreen> {
height: 2, height: 2,
), ),
)), )),
errorStyle: TextStyle(
fontSize: 9, height: 0.3),
), ),
), ),
Padding( Padding(
@ -259,6 +258,46 @@ class _LoginScreenState extends State<LoginScreen> {
child: LoginButton( child: LoginButton(
callback: handleLogin, 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>[
TextSpan(
text: " Sinscire",
style: GoogleFonts
.plusJakartaSans(
fontSize:
15,
fontWeight:
FontWeight
.w400,
color:
primaryColor)),
],
),
),
),
),
),
], ],
), ),
), ),
@ -321,38 +360,6 @@ class _LoginScreenState extends State<LoginScreen> {
text: "Login with Google", text: "Login with Google",
onPressed: () {}, 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>[
TextSpan(
text: " Sinscire",
style: GoogleFonts
.plusJakartaSans(
fontSize:
13,
fontWeight:
FontWeight
.w400,
color:
primaryColor)),
],
),
),
)
], ],
), ),
)) ))

@ -292,6 +292,34 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
callback: () {}, 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>[
TextSpan(
text: " Connexion",
style: GoogleFonts.plusJakartaSans(
fontSize: 15,
fontWeight: FontWeight.w400,
color: primaryColor)),
],
),
),
),
),
),
], ],
)), )),
SizedBox(height: 50.h), SizedBox(height: 50.h),

@ -71,13 +71,21 @@ class WellcomeScreen extends StatelessWidget {
SizedBox( SizedBox(
height: defaultPadding, height: defaultPadding,
), ),
Text( GestureDetector(
onTap: () {
Navigator.pushNamed(context, '/login');
},
child: Padding(
padding: const EdgeInsets.all(3.0),
child: Text(
"Tu as déja un compte? Connexion", "Tu as déja un compte? Connexion",
style: GoogleFonts.plusJakartaSans( style: GoogleFonts.plusJakartaSans(
color: Colors.white, color: Colors.white,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
fontSize: 15), fontSize: 15),
), ),
),
),
], ],
), ),
), ),

@ -1,4 +1,3 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart' as firebase_auth; import 'package:firebase_auth/firebase_auth.dart' as firebase_auth;
import 'package:justmusic/service/AuthService.dart'; import 'package:justmusic/service/AuthService.dart';
@ -25,19 +24,17 @@ class UserViewModel {
} }
login(String pseudo, String password) async { login(String pseudo, String password) async {
try {
await _authService.login(pseudo, password); await _authService.login(pseudo, password);
if (firebase_auth.FirebaseAuth.instance.currentUser == null) {
throw Exception("User login failed");
}
final user = await MyApp.db final user = await MyApp.db
.collection("users") .collection("users")
.doc(firebase_auth.FirebaseAuth.instance.currentUser?.uid) .doc(firebase_auth.FirebaseAuth.instance.currentUser?.uid)
.get(); .get();
User? data = UserMapper.toModel(user, null); User data = UserMapper.toModel(user, null);
if (data == null) {
throw Exception("User login failed");
}
_userCurrent = data; _userCurrent = data;
} catch (e) {
throw Exception("Erreur: Email ou mot de passe incorrect");
}
} }
register(String pseudo, String password, String email) async { register(String pseudo, String password, String email) async {
@ -47,9 +44,6 @@ class UserViewModel {
.doc(firebase_auth.FirebaseAuth.instance.currentUser?.uid) .doc(firebase_auth.FirebaseAuth.instance.currentUser?.uid)
.get(); .get();
User? data = UserMapper.toModel(user, null); User? data = UserMapper.toModel(user, null);
if (data == null) {
throw Exception("User register failed");
}
_userCurrent = data; _userCurrent = data;
} }

Loading…
Cancel
Save