Register done

pull/28/head
root 2 years ago
parent d8cf5ed01e
commit ffc8e24ea3

@ -29,7 +29,7 @@ class _LoginScreenState extends State<LoginScreen> {
try { try {
await MyApp.userViewModel await MyApp.userViewModel
.login(_userMailTextField.text, _passwordTextField.text); .login(_userMailTextField.text, _passwordTextField.text);
Navigator.pushNamed(context, '/explanation'); Navigator.pushNamed(context, '/feed');
} catch (e) { } catch (e) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(

@ -10,6 +10,7 @@ import 'package:google_fonts/google_fonts.dart';
import 'package:justmusic/values/constants.dart'; import 'package:justmusic/values/constants.dart';
import '../components/login_button.dart'; import '../components/login_button.dart';
import '../main.dart';
class RegistrationScreen extends StatefulWidget { class RegistrationScreen extends StatefulWidget {
const RegistrationScreen({Key? key}) : super(key: key); const RegistrationScreen({Key? key}) : super(key: key);
@ -20,111 +21,258 @@ class RegistrationScreen extends StatefulWidget {
class _RegistrationScreenState extends State<RegistrationScreen> { class _RegistrationScreenState extends State<RegistrationScreen> {
bool passenable = true; bool passenable = true;
final _formKey = GlobalKey<FormState>();
final _userPseudoTextField = TextEditingController();
final _userMailTextField = TextEditingController();
final _passwordTextField = TextEditingController();
final _passwordConfirmTextField = TextEditingController();
handleRegister() async {
if (_formKey.currentState!.validate()) {
try {
await MyApp.userViewModel.register(_userPseudoTextField.text,
_passwordTextField.text, _userMailTextField.text);
Navigator.pushNamed(context, '/explanation');
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
e.toString() ?? "",
style: GoogleFonts.plusJakartaSans(
color: Colors.white,
fontWeight: FontWeight.w400,
fontSize: 20.h),
),
backgroundColor: Colors.red,
),
);
}
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: bgColor, backgroundColor: bgColor,
body: Stack( body: Form(
children: [ key: _formKey,
SingleChildScrollView( child: Stack(
child: SizedBox( children: [
width: double.infinity, SingleChildScrollView(
child: Column( child: SizedBox(
children: [ width: double.infinity,
Padding( child: Column(
padding: EdgeInsets.only(top: 100.h), children: [
child: AutoSizeText( Padding(
"On a besoin de ça!", padding: EdgeInsets.only(top: 100.h),
style: GoogleFonts.plusJakartaSans( child: AutoSizeText(
color: Colors.white, "On a besoin de ça!",
fontWeight: FontWeight.w600, style: GoogleFonts.plusJakartaSans(
fontSize: 30.w), color: Colors.white,
maxLines: 1, fontWeight: FontWeight.w600,
maxFontSize: 50, fontSize: 30.w),
overflow: TextOverflow.fade, maxLines: 1,
maxFontSize: 50,
overflow: TextOverflow.fade,
),
), ),
), ConstrainedBox(
ConstrainedBox( constraints: BoxConstraints(maxWidth: 600),
constraints: BoxConstraints(maxWidth: 600), child: Column(
child: Column( mainAxisAlignment: MainAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start, children: [
children: [ Padding(
Padding( padding: EdgeInsets.symmetric(
padding: horizontal: defaultPadding),
EdgeInsets.symmetric(horizontal: defaultPadding), child: Padding(
child: Padding( padding: EdgeInsets.only(bottom: 50.h),
padding: EdgeInsets.only(bottom: 50.h), child: Column(
child: Column( mainAxisAlignment: MainAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end, children: [
children: [ SizedBox(
SizedBox( height: 15.h,
height: 15.h,
),
SizedBox(
width: 230.h,
child: AutoSizeText(
"Promis cest rapide.",
style: GoogleFonts.plusJakartaSans(
color: Colors.white,
fontWeight: FontWeight.w400,
fontSize: 17.w),
maxFontSize: 20,
textAlign: TextAlign.center,
), ),
), SizedBox(
], width: 230.h,
child: AutoSizeText(
"Promis cest rapide.",
style: GoogleFonts.plusJakartaSans(
color: Colors.white,
fontWeight: FontWeight.w400,
fontSize: 17.w),
maxFontSize: 20,
textAlign: TextAlign.center,
),
),
],
),
), ),
), ),
), Padding(
Padding( padding: EdgeInsets.only(
bottom: 16.h,
left: defaultPadding,
right: defaultPadding),
child: TextFormField(
controller: _userPseudoTextField,
keyboardAppearance: Brightness.dark,
validator: (value) {
if (value == null || value.isEmpty) {
return 'entrez un pseudo valide';
}
return null;
},
cursorColor: primaryColor,
keyboardType: TextInputType.emailAddress,
style: GoogleFonts.plusJakartaSans(
color: primaryColor, fontSize: 15),
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 1.sp,
color: strokeTextField),
borderRadius: const BorderRadius.all(
Radius.circular(10))),
prefix: const Padding(
padding: EdgeInsets.only(left: 20.0)),
suffix: const Padding(
padding: EdgeInsets.only(left: 20.0)),
fillColor: bgTextField,
filled: true,
focusColor: const Color.fromRGBO(
255, 255, 255, 0.30),
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(
width: 1, color: strokeTextField),
borderRadius: BorderRadius.all(
Radius.circular(10))),
hintText: 'Pseudo',
hintStyle: GoogleFonts.plusJakartaSans(
color: strokeTextField)),
)),
Padding(
padding: EdgeInsets.only(
bottom: 16.h,
left: defaultPadding,
right: defaultPadding),
child: TextFormField(
controller: _userMailTextField,
keyboardAppearance: Brightness.dark,
validator: (value) {
if (value == null || value.isEmpty) {
return 'entrez un email valide';
}
return null;
},
cursorColor: primaryColor,
keyboardType: TextInputType.emailAddress,
style: GoogleFonts.plusJakartaSans(
color: primaryColor),
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 1, color: strokeTextField),
borderRadius: BorderRadius.all(
Radius.circular(10))),
prefix: const Padding(
padding: EdgeInsets.only(left: 20.0)),
suffix: const Padding(
padding: EdgeInsets.only(left: 20.0)),
fillColor: bgTextField,
filled: true,
focusColor:
Color.fromRGBO(255, 255, 255, 0.30),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 1, color: strokeTextField),
borderRadius: BorderRadius.all(
Radius.circular(10))),
hintText: 'Email',
hintStyle: GoogleFonts.plusJakartaSans(
color: strokeTextField)),
)),
Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
bottom: 16.h, bottom: 16.h,
left: defaultPadding, left: defaultPadding,
right: defaultPadding), right: defaultPadding),
child: TextFormField( child: TextFormField(
controller: _passwordTextField,
keyboardAppearance: Brightness.dark, keyboardAppearance: Brightness.dark,
obscureText: passenable,
validator: (value) { validator: (value) {
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
return 'TODO'; return 'entrez un mot de passe valide';
} }
return null; return null;
}, },
cursorColor: primaryColor, cursorColor: primaryColor,
keyboardType: TextInputType.emailAddress,
style: GoogleFonts.plusJakartaSans( style: GoogleFonts.plusJakartaSans(
color: primaryColor, fontSize: 15), color: primaryColor),
decoration: InputDecoration( decoration: InputDecoration(
focusedBorder: OutlineInputBorder( focusedBorder: OutlineInputBorder(
borderSide: BorderSide( borderSide: BorderSide(
width: 1.sp, color: strokeTextField), width: 1, color: strokeTextField),
borderRadius: const BorderRadius.all( borderRadius:
Radius.circular(10))), BorderRadius.all(Radius.circular(10))),
contentPadding: const EdgeInsets.only( prefix: const Padding(
top: 0, bottom: 0, left: defaultPadding), padding: EdgeInsets.only(left: 20.0)),
fillColor: bgTextField, suffix: const Padding(
filled: true, padding: EdgeInsets.only(left: 20.0)),
focusColor: fillColor: bgTextField,
const Color.fromRGBO(255, 255, 255, 0.30), filled: true,
enabledBorder: const OutlineInputBorder( focusColor: Color.fromRGBO(255, 255, 255, 0.30),
borderSide: BorderSide( enabledBorder: OutlineInputBorder(
width: 1, color: strokeTextField), borderSide: BorderSide(
borderRadius: BorderRadius.all( width: 1, color: strokeTextField),
Radius.circular(10))), borderRadius:
hintText: 'Pseudo', BorderRadius.all(Radius.circular(10))),
hintStyle: GoogleFonts.plusJakartaSans( hintText: 'Mot de passe',
color: strokeTextField)), hintStyle: GoogleFonts.plusJakartaSans(
)), color: strokeTextField),
Padding( suffixIcon: Container(
padding: EdgeInsets.only(right: 10),
margin: EdgeInsets.all(5),
height: 3,
child: InkWell(
onTap: () {
setState(() {
if (passenable) {
passenable = false;
} else {
passenable = true;
}
});
},
// Image tapped
splashColor: Colors.white10,
// Splash color over image
child: Image(
image: passenable
? AssetImage(
"assets/images/show_icon.png")
: AssetImage(
"assets/images/hide_icon.png"),
height: 2,
),
)),
),
),
),
Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
bottom: 16.h, bottom: 16.h,
left: defaultPadding, left: defaultPadding,
right: defaultPadding), right: defaultPadding),
child: TextFormField( child: TextFormField(
controller: _passwordConfirmTextField,
keyboardAppearance: Brightness.dark, keyboardAppearance: Brightness.dark,
obscureText: passenable,
validator: (value) { validator: (value) {
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
return 'TODO'; return 'entrez un mot de passe valide';
} else if (_passwordTextField.text != value) {
return 'les mots de passes ne sont pas identiques';
} }
return null; return null;
}, },
@ -133,275 +281,177 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
style: GoogleFonts.plusJakartaSans( style: GoogleFonts.plusJakartaSans(
color: primaryColor), color: primaryColor),
decoration: InputDecoration( decoration: InputDecoration(
focusedBorder: OutlineInputBorder( focusedBorder: OutlineInputBorder(
borderSide: BorderSide( borderSide: BorderSide(
width: 1, color: strokeTextField), width: 1, color: strokeTextField),
borderRadius: BorderRadius.all( borderRadius:
Radius.circular(10))), BorderRadius.all(Radius.circular(10))),
contentPadding: EdgeInsets.only( prefix: const Padding(
top: 0, bottom: 0, left: defaultPadding), padding: EdgeInsets.only(left: 20.0)),
fillColor: bgTextField, suffix: const Padding(
filled: true, padding: EdgeInsets.only(left: 20.0)),
focusColor: fillColor: bgTextField,
Color.fromRGBO(255, 255, 255, 0.30), filled: true,
enabledBorder: OutlineInputBorder( focusColor: Color.fromRGBO(255, 255, 255, 0.30),
borderSide: BorderSide( enabledBorder: OutlineInputBorder(
width: 1, color: strokeTextField), borderSide: BorderSide(
borderRadius: BorderRadius.all( width: 1, color: strokeTextField),
Radius.circular(10))), borderRadius:
hintText: 'Email', BorderRadius.all(Radius.circular(10))),
hintStyle: GoogleFonts.plusJakartaSans( hintText: 'Confirmation du Mot de passe',
color: strokeTextField)), hintStyle: GoogleFonts.plusJakartaSans(
)), color: strokeTextField),
Padding( suffixIcon: Container(
padding: EdgeInsets.only( padding: EdgeInsets.only(right: 10),
bottom: 16.h, margin: EdgeInsets.all(5),
left: defaultPadding, height: 3,
right: defaultPadding), child: InkWell(
child: TextFormField( onTap: () {
keyboardAppearance: Brightness.dark, setState(() {
obscureText: passenable, if (passenable) {
validator: (value) { passenable = false;
if (value == null || value.isEmpty) { } else {
return 'TODO'; passenable = true;
} }
return null; });
}, },
cursorColor: primaryColor, // Image tapped
keyboardType: TextInputType.emailAddress, splashColor: Colors.white10,
style: GoogleFonts.plusJakartaSans( // Splash color over image
color: primaryColor), child: Image(
decoration: InputDecoration( image: passenable
focusedBorder: OutlineInputBorder( ? AssetImage(
borderSide: BorderSide( "assets/images/show_icon.png")
width: 1, color: strokeTextField), : AssetImage(
borderRadius: "assets/images/hide_icon.png"),
BorderRadius.all(Radius.circular(10))), height: 2,
contentPadding: EdgeInsets.only( ),
top: 0, bottom: 0, left: defaultPadding), )),
fillColor: bgTextField, ),
filled: true,
focusColor: Color.fromRGBO(255, 255, 255, 0.30),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 1, color: strokeTextField),
borderRadius:
BorderRadius.all(Radius.circular(10))),
hintText: 'Mot de passe',
hintStyle: GoogleFonts.plusJakartaSans(
color: strokeTextField),
suffixIcon: Container(
padding: EdgeInsets.only(right: 10),
margin: EdgeInsets.all(5),
height: 3,
child: InkWell(
onTap: () {
setState(() {
if (passenable) {
passenable = false;
} else {
passenable = true;
}
});
}, // Image tapped
splashColor: Colors
.white10, // Splash color over image
child: Image(
image: passenable
? AssetImage(
"assets/images/show_icon.png")
: AssetImage(
"assets/images/hide_icon.png"),
height: 2,
),
)),
), ),
), ),
), Padding(
Padding( padding: EdgeInsets.symmetric(
padding: EdgeInsets.only( horizontal: defaultPadding),
bottom: 16.h, child: SizedBox(
left: defaultPadding, width: 600,
right: defaultPadding), child: LoginButton(
child: TextFormField( callback: handleRegister,
keyboardAppearance: Brightness.dark, )),
obscureText: passenable,
validator: (value) {
if (value == null || value.isEmpty) {
return 'TODO';
}
return null;
},
cursorColor: primaryColor,
keyboardType: TextInputType.emailAddress,
style: GoogleFonts.plusJakartaSans(
color: primaryColor),
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 1, color: strokeTextField),
borderRadius:
BorderRadius.all(Radius.circular(10))),
contentPadding: EdgeInsets.only(
top: 0, bottom: 0, left: defaultPadding),
fillColor: bgTextField,
filled: true,
focusColor: Color.fromRGBO(255, 255, 255, 0.30),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 1, color: strokeTextField),
borderRadius:
BorderRadius.all(Radius.circular(10))),
hintText: 'Confirmation du Mot de passe',
hintStyle: GoogleFonts.plusJakartaSans(
color: strokeTextField),
suffixIcon: Container(
padding: EdgeInsets.only(right: 10),
margin: EdgeInsets.all(5),
height: 3,
child: InkWell(
onTap: () {
setState(() {
if (passenable) {
passenable = false;
} else {
passenable = true;
}
});
}, // Image tapped
splashColor: Colors
.white10, // Splash color over image
child: Image(
image: passenable
? AssetImage(
"assets/images/show_icon.png")
: AssetImage(
"assets/images/hide_icon.png"),
height: 2,
),
)),
),
), ),
), Align(
Padding( child: GestureDetector(
padding: onTap: () {
EdgeInsets.symmetric(horizontal: defaultPadding), Navigator.pushNamed(context, '/login');
child: SizedBox( },
width: 600, child: Padding(
child: LoginButton( padding: EdgeInsets.only(top: 20),
callback: () {}, child: RichText(
)), textAlign: TextAlign.center,
), text: TextSpan(
Align( text: 'Tu as déjà un compte?',
child: GestureDetector( style: GoogleFonts.plusJakartaSans(
onTap: () { color: Colors.white,
Navigator.pushNamed(context, '/login'); fontWeight: FontWeight.w400,
}, fontSize: 15),
child: Padding( children: <TextSpan>[
padding: EdgeInsets.only(top: 20), TextSpan(
child: RichText( text: " Connexion",
textAlign: TextAlign.center, style: GoogleFonts.plusJakartaSans(
text: TextSpan( fontSize: 15,
text: 'Tu as déjà un compte?', fontWeight: FontWeight.w400,
style: GoogleFonts.plusJakartaSans( color: primaryColor)),
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),
ConstrainedBox(
constraints: BoxConstraints(maxWidth: 600),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Expanded(
child: Container(
color: Color(0xFF3D3D3D),
height: 1,
),
), ),
], Padding(
)), padding: const EdgeInsets.only(
SizedBox(height: 50.h), left: defaultPadding, right: defaultPadding),
ConstrainedBox( child: Text(
constraints: BoxConstraints(maxWidth: 600), 'Ou',
child: Row( style: GoogleFonts.plusJakartaSans(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, color: Colors.white,
children: [ fontWeight: FontWeight.bold),
Expanded( ),
child: Container(
color: Color(0xFF3D3D3D),
height: 1,
),
),
Padding(
padding: const EdgeInsets.only(
left: defaultPadding, right: defaultPadding),
child: Text(
'Ou',
style: GoogleFonts.plusJakartaSans(
color: Colors.white, fontWeight: FontWeight.bold),
), ),
), Expanded(
Expanded( child: Container(
child: Container( height: 1,
height: 1, color: Color(0xFF3D3D3D),
color: Color(0xFF3D3D3D), )),
)), ],
], ),
), ),
), SizedBox(height: 47.h),
SizedBox(height: 47.h), ConstrainedBox(
ConstrainedBox( constraints: BoxConstraints(maxWidth: 540),
constraints: BoxConstraints(maxWidth: 540), child: SizedBox(
child: SizedBox( width: 300.sp,
width: 300.sp, height: 50,
height: 50, child: SignInButton(
child: SignInButton( Buttons.Google,
Buttons.Google, text: "Login with Google",
text: "Login with Google", onPressed: () {},
onPressed: () {}, shape: RoundedRectangleBorder(
shape: RoundedRectangleBorder( borderRadius:
borderRadius: BorderRadius.all(Radius.circular(20))), BorderRadius.all(Radius.circular(20))),
),
), ),
), ),
), ],
], ),
), )),
)), IgnorePointer(
IgnorePointer( child: Container(
child: Container( height: 240.h,
height: 240.h, decoration: BoxDecoration(
decoration: BoxDecoration( gradient: LinearGradient(begin: Alignment.topRight, stops: [
gradient: LinearGradient(begin: Alignment.topRight, stops: [ 0,
0, 1
1 ], colors: [
], colors: [ bgColor.withOpacity(1),
bgColor.withOpacity(1), bgColor.withOpacity(0)
bgColor.withOpacity(0) ])),
])), ),
), ),
), Align(
Align( alignment: Alignment.topCenter,
alignment: Alignment.topCenter, child: ConstrainedBox(
child: ConstrainedBox( constraints: BoxConstraints(maxWidth: 800),
constraints: BoxConstraints(maxWidth: 800), child: Padding(
child: Padding( padding: EdgeInsets.only(
padding: EdgeInsets.only( top: 45.h, left: defaultPadding, right: defaultPadding),
top: 45.h, left: defaultPadding, right: defaultPadding), child: ClipRRect(
child: ClipRRect( borderRadius: BorderRadius.circular(10.0),
borderRadius: BorderRadius.circular(10.0), child: LinearProgressIndicator(
child: LinearProgressIndicator( minHeight: 5,
minHeight: 5, value: 0.5,
value: 0.5, backgroundColor: grayColor,
backgroundColor: grayColor, color: primaryColor,
color: primaryColor, ),
), ),
), ),
), ),
), ),
), ],
], ),
), ),
); );
} }

@ -26,12 +26,13 @@ class AuthService {
.catchError((error) => print("Failed to add user: $error")); .catchError((error) => print("Failed to add user: $error"));
} on FirebaseAuthException catch (e) { } on FirebaseAuthException catch (e) {
if (e.code == 'weak-password') { if (e.code == 'weak-password') {
throw ('The password provided is too weak.'); throw ('Mot de passe trop court');
} else if (e.code == 'email-already-in-use') { } else if (e.code == 'email-already-in-use') {
throw ('The account already exists for that email.'); throw ('Mail déjà utilisé');
} else if (e.code == 'invalid-email') {
throw ('Mauvais format de mail');
} }
} catch (e) { rethrow;
throw (e);
} }
} }
@ -40,14 +41,14 @@ class AuthService {
await FirebaseAuth.instance await FirebaseAuth.instance
.signInWithEmailAndPassword(email: email, password: password); .signInWithEmailAndPassword(email: email, password: password);
} on FirebaseAuthException catch (e) { } on FirebaseAuthException catch (e) {
if(e.code == 'user-not-found') { if (e.code == 'user-not-found') {
throw('Mail incorrect'); throw ('Mail incorrect');
} else if(e.code == 'wrong-password') { } else if (e.code == 'wrong-password') {
throw('Mot de passe incorrect'); throw ('Mot de passe incorrect');
} else if(e.code == 'invalid-email') { } else if (e.code == 'invalid-email') {
throw('Format de mail incorrect'); throw ('Format de mail incorrect');
} else if(e.code == 'too-many-requests') { } else if (e.code == 'too-many-requests') {
throw('L\'accès à ce compte a été temporairement désactivé en raison de nombreuses tentatives de connexion infructueuses. Réessayer plus tard.'); throw ('L\'accès à ce compte a été temporairement désactivé en raison de nombreuses tentatives de connexion infructueuses. Réessayer plus tard.');
} }
rethrow; rethrow;
} }

@ -38,13 +38,17 @@ class UserViewModel {
} }
register(String pseudo, String password, String email) async { register(String pseudo, String password, String email) async {
_authService.register(pseudo, email, password); try {
final user = await MyApp.db await _authService.register(pseudo, email, password);
.collection("users") final user = await MyApp.db
.doc(firebase_auth.FirebaseAuth.instance.currentUser?.uid) .collection("users")
.get(); .doc(firebase_auth.FirebaseAuth.instance.currentUser?.uid)
User? data = UserMapper.toModel(user, null); .get();
_userCurrent = data; User data = UserMapper.toModel(user, null);
_userCurrent = data;
} catch (e) {
rethrow;
}
} }
logout() { logout() {

Loading…
Cancel
Save