Added create a unit screen, and implemented otp screen bloc and view

This commit is contained in:
Abdullah Alassaf
2024-05-30 10:59:22 +03:00
parent 28576f2cd5
commit 9877dde78e
22 changed files with 789 additions and 348 deletions
+45 -22
View File
@@ -19,11 +19,6 @@ class AuthCubit extends Cubit<AuthState> {
final TextEditingController emailController = TextEditingController();
final TextEditingController passwordController = TextEditingController();
// final TextEditingController emailSignUpController = TextEditingController();
// final TextEditingController fullNameController = TextEditingController();
// final TextEditingController passwordSignUpController = TextEditingController();
// final TextEditingController reEnterPasswordSignUpController = TextEditingController();
String fullName = '';
String email = '';
String signUpPassword = '';
@@ -51,6 +46,10 @@ class AuthCubit extends Cubit<AuthState> {
static Token token = Token.emptyConstructor();
setOtpCode(String value) {
otpCode = value;
}
/////////////////////////////////////VALIDATORS/////////////////////////////////////
String? passwordValidator(String? value) {
if (value != null) {
@@ -64,9 +63,6 @@ class AuthCubit extends Cubit<AuthState> {
}
}
}
if (signUpFormKey.currentState != null) {
signUpFormKey.currentState!.save();
}
return null;
}
@@ -94,19 +90,16 @@ class AuthCubit extends Cubit<AuthState> {
if (parts.any((part) => part.length < 2 || part.length > 30)) {
return 'Full name parts must be between 2 and 30 characters long';
}
if (signUpFormKey.currentState != null) {
signUpFormKey.currentState!.save();
}
return null;
}
String reEnterPasswordCheck(String? value) {
String? reEnterPasswordCheck(String? value) {
passwordValidator(value);
if (signUpPassword == value) {
if (signUpFormKey.currentState != null) {
signUpFormKey.currentState!.save();
}
return '';
// if (signUpFormKey.currentState != null) {
// signUpFormKey.currentState!.save();
// }
return null;
} else {
return 'Passwords do not match';
}
@@ -115,9 +108,6 @@ class AuthCubit extends Cubit<AuthState> {
String? emailAddressValidator(String? value) {
if (value != null && value.isNotEmpty && value != "") {
if (checkValidityOfEmail(value)) {
if (signUpFormKey.currentState != null) {
signUpFormKey.currentState!.save();
}
return null;
} else {
return 'Please enter a valid email';
@@ -204,14 +194,47 @@ class AuthCubit extends Cubit<AuthState> {
}
if (response) {
maskedEmail = maskEmail(email);
final response = await AuthenticationAPI.sendOtp(body: {'email': email, 'type': 'PASSWORD'});
otpCode = response['otp'];
emit(AuthSignUpSuccess());
await sendOtp();
} else {
emit(AuthLoginError(message: 'Something went wrong'));
}
}
sendOtp() async {
try {
final response =
await AuthenticationAPI.sendOtp(body: {'email': email, 'type': 'VERIFICATION'});
// otpCode = response['otp'];
emit(AuthSignUpSuccess());
} catch (_) {
emit(AuthLoginError(message: 'Something went wrong'));
}
}
verifyOtp() async {
emit(AuthLoginLoading());
try {
final response = await AuthenticationAPI.verifyPassCode(
body: {'email': email, 'type': 'VERIFICATION', 'otpCode': otpCode});
if (response['statusCode'] == 200) {
emailController.text = email;
passwordController.text = signUpPassword;
await login();
emit(AuthOtpSuccess());
} else {
emit(AuthLoginError(message: 'Something went wrong'));
}
// if (otpCode == '654321') {
// emit(AuthOtpSuccess());
// } else {
// emit(AuthLoginError(message: 'Otp is not correct'));
// }
} catch (failure) {
emit(AuthLoginError(message: failure.toString()));
return;
}
}
logout() async {
emit(AuthLogoutLoading());
try {