Register done

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

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

@ -10,6 +10,7 @@ import 'package:google_fonts/google_fonts.dart';
import 'package:justmusic/values/constants.dart';
import '../components/login_button.dart';
import '../main.dart';
class RegistrationScreen extends StatefulWidget {
const RegistrationScreen({Key? key}) : super(key: key);
@ -20,12 +21,42 @@ class RegistrationScreen extends StatefulWidget {
class _RegistrationScreenState extends State<RegistrationScreen> {
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
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: bgColor,
body: Stack(
body: Form(
key: _formKey,
child: Stack(
children: [
SingleChildScrollView(
child: SizedBox(
@ -51,8 +82,8 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
mainAxisAlignment: MainAxisAlignment.start,
children: [
Padding(
padding:
EdgeInsets.symmetric(horizontal: defaultPadding),
padding: EdgeInsets.symmetric(
horizontal: defaultPadding),
child: Padding(
padding: EdgeInsets.only(bottom: 50.h),
child: Column(
@ -83,10 +114,11 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
left: defaultPadding,
right: defaultPadding),
child: TextFormField(
controller: _userPseudoTextField,
keyboardAppearance: Brightness.dark,
validator: (value) {
if (value == null || value.isEmpty) {
return 'TODO';
return 'entrez un pseudo valide';
}
return null;
},
@ -97,15 +129,18 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 1.sp, color: strokeTextField),
width: 1.sp,
color: strokeTextField),
borderRadius: const BorderRadius.all(
Radius.circular(10))),
contentPadding: const 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,
focusColor:
const Color.fromRGBO(255, 255, 255, 0.30),
focusColor: const Color.fromRGBO(
255, 255, 255, 0.30),
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(
width: 1, color: strokeTextField),
@ -121,10 +156,11 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
left: defaultPadding,
right: defaultPadding),
child: TextFormField(
controller: _userMailTextField,
keyboardAppearance: Brightness.dark,
validator: (value) {
if (value == null || value.isEmpty) {
return 'TODO';
return 'entrez un email valide';
}
return null;
},
@ -138,8 +174,10 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
width: 1, color: 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,
focusColor:
@ -159,16 +197,16 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
left: defaultPadding,
right: defaultPadding),
child: TextFormField(
controller: _passwordTextField,
keyboardAppearance: Brightness.dark,
obscureText: passenable,
validator: (value) {
if (value == null || value.isEmpty) {
return 'TODO';
return 'entrez un mot de passe valide';
}
return null;
},
cursorColor: primaryColor,
keyboardType: TextInputType.emailAddress,
style: GoogleFonts.plusJakartaSans(
color: primaryColor),
decoration: InputDecoration(
@ -177,8 +215,10 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
width: 1, color: 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,
focusColor: Color.fromRGBO(255, 255, 255, 0.30),
@ -203,9 +243,10 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
passenable = true;
}
});
}, // Image tapped
splashColor: Colors
.white10, // Splash color over image
},
// Image tapped
splashColor: Colors.white10,
// Splash color over image
child: Image(
image: passenable
? AssetImage(
@ -224,11 +265,14 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
left: defaultPadding,
right: defaultPadding),
child: TextFormField(
controller: _passwordConfirmTextField,
keyboardAppearance: Brightness.dark,
obscureText: passenable,
validator: (value) {
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;
},
@ -242,8 +286,10 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
width: 1, color: 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,
focusColor: Color.fromRGBO(255, 255, 255, 0.30),
@ -268,9 +314,10 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
passenable = true;
}
});
}, // Image tapped
splashColor: Colors
.white10, // Splash color over image
},
// Image tapped
splashColor: Colors.white10,
// Splash color over image
child: Image(
image: passenable
? AssetImage(
@ -284,12 +331,12 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
),
),
Padding(
padding:
EdgeInsets.symmetric(horizontal: defaultPadding),
padding: EdgeInsets.symmetric(
horizontal: defaultPadding),
child: SizedBox(
width: 600,
child: LoginButton(
callback: () {},
callback: handleRegister,
)),
),
Align(
@ -340,7 +387,8 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
child: Text(
'Ou',
style: GoogleFonts.plusJakartaSans(
color: Colors.white, fontWeight: FontWeight.bold),
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
Expanded(
@ -362,7 +410,8 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
text: "Login with Google",
onPressed: () {},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20))),
borderRadius:
BorderRadius.all(Radius.circular(20))),
),
),
),
@ -403,6 +452,7 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
),
],
),
),
);
}
}

@ -26,12 +26,13 @@ class AuthService {
.catchError((error) => print("Failed to add user: $error"));
} on FirebaseAuthException catch (e) {
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') {
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) {
throw (e);
rethrow;
}
}
@ -40,14 +41,14 @@ class AuthService {
await FirebaseAuth.instance
.signInWithEmailAndPassword(email: email, password: password);
} on FirebaseAuthException catch (e) {
if(e.code == 'user-not-found') {
throw('Mail incorrect');
} else if(e.code == 'wrong-password') {
throw('Mot de passe incorrect');
} else if(e.code == 'invalid-email') {
throw('Format de mail incorrect');
} 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.');
if (e.code == 'user-not-found') {
throw ('Mail incorrect');
} else if (e.code == 'wrong-password') {
throw ('Mot de passe incorrect');
} else if (e.code == 'invalid-email') {
throw ('Format de mail incorrect');
} 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.');
}
rethrow;
}

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

Loading…
Cancel
Save