mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 19:57:55 +00:00
Update form key to be a final field and add validators for email and password
- Make the form key a final field in the AuthCubit class - Add validators for email and password fields in the AuthCubit class - Update the LoginForm widget to use the form key from AuthCubit class - Add validators for email and password fields in the LoginForm widget
This commit is contained in:
@@ -20,8 +20,9 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
|
||||
static AuthCubit get(context) => BlocProvider.of(context);
|
||||
|
||||
TextEditingController emailController = TextEditingController();
|
||||
TextEditingController passwordController = TextEditingController();
|
||||
final TextEditingController emailController = TextEditingController();
|
||||
final TextEditingController passwordController = TextEditingController();
|
||||
final loginFormKey = GlobalKey<FormState>();
|
||||
bool isPasswordVisible = false;
|
||||
|
||||
static GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||
@@ -41,6 +42,56 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
static UserModel? user;
|
||||
|
||||
static Token token = Token.emptyConstructor();
|
||||
|
||||
/////////////////////////////////////VALIDATORS/////////////////////////////////////
|
||||
String? passwordValidator(String? value) {
|
||||
if (value != null) {
|
||||
if (value.isNotEmpty) {
|
||||
if (value.length >= 6) {
|
||||
return null;
|
||||
//TODO uncomment this code when the password validation is needed
|
||||
// if (RegExp(
|
||||
// r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$')
|
||||
// .hasMatch(value)) {
|
||||
// return null;
|
||||
// } else {
|
||||
// return 'Password must contain at least one uppercase letter, one lowercase letter, one number and one special character';
|
||||
// }
|
||||
} else {
|
||||
return 'Password must be at least 6 characters';
|
||||
}
|
||||
} else {
|
||||
return 'Please enter your password';
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String? emailAddressValidator(String? value) {
|
||||
if (value != null && value.isNotEmpty && value != "") {
|
||||
if (checkValidityOfEmail(value)) {
|
||||
if (loginFormKey.currentState != null) {
|
||||
loginFormKey.currentState!.save();
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
return 'Please enter a valid email';
|
||||
}
|
||||
} else {
|
||||
return 'Email address is required';
|
||||
}
|
||||
}
|
||||
|
||||
bool checkValidityOfEmail(String? email) {
|
||||
if (email != null) {
|
||||
return RegExp(
|
||||
r"^[a-zA-Z0-9]+([.!#$%&'*+/=?^_`{|}~-]?[a-zA-Z0-9]+)*@[a-zA-Z0-9]+([.-]?[a-zA-Z0-9]+)*\.[a-zA-Z0-9]{2,}$")
|
||||
.hasMatch(email);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////API CALLS/////////////////////////////////////
|
||||
login() async {
|
||||
emit(AuthLoginLoading());
|
||||
|
||||
Reference in New Issue
Block a user