mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
create visitor password
This commit is contained in:
@ -73,7 +73,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
ChangePasswordEvent event, Emitter<AuthState> emit) async {
|
||||
try {
|
||||
emit(LoadingForgetState());
|
||||
bool response = await AuthenticationAPI.verifyOtp(
|
||||
var response = await AuthenticationAPI.verifyOtp(
|
||||
email: forgetEmailController.text, otpCode: forgetOtp.text);
|
||||
if (response == true) {
|
||||
await AuthenticationAPI.forgetPassword(
|
||||
@ -81,8 +81,11 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
email: forgetEmailController.text);
|
||||
_timer?.cancel();
|
||||
emit(const TimerState(isButtonEnabled: true, remainingTime: 0));
|
||||
}
|
||||
emit(SuccessForgetState());
|
||||
} else if (response == "You entered wrong otp") {
|
||||
forgetValidate = response; // Set the validation message
|
||||
emit(AuthInitialState());
|
||||
}
|
||||
} catch (failure) {
|
||||
forgetValidate='Invalid Credentials!';
|
||||
emit(AuthInitialState());
|
||||
@ -91,6 +94,13 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
}
|
||||
}
|
||||
|
||||
String? validateCode(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Code is required';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void _onUpdateTimer(UpdateTimerEvent event, Emitter<AuthState> emit) {
|
||||
emit(TimerState(
|
||||
isButtonEnabled: event.isButtonEnabled,
|
||||
@ -196,6 +206,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
validate='';
|
||||
return null;
|
||||
}
|
||||
|
||||
String? loginValidateEmail(String? value) {
|
||||
if (!RegExp(r'^[^@]+@[^@]+\.[^@]+').hasMatch(value!)) {
|
||||
return '';
|
||||
@ -203,12 +214,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
return null;
|
||||
}
|
||||
|
||||
String? validateCode(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Code is required';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
bool _validateInputs(Emitter<AuthState> emit) {
|
||||
emit(LoadingForgetState());
|
||||
|
@ -21,6 +21,11 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
child: BlocConsumer<AuthBloc, AuthState>(
|
||||
listener: (context, state) {
|
||||
if (state is SuccessForgetState) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Change Password Successfully '),
|
||||
),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
} else if (state is FailureForgetState) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@ -242,6 +247,17 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
const TextStyle(color: Colors.black),
|
||||
),
|
||||
),
|
||||
if (forgetBloc.forgetValidate != '') // Check if there is a validation message
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: Text(
|
||||
forgetBloc.forgetValidate,
|
||||
style: const TextStyle(
|
||||
color: ColorsManager.red,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
|
@ -79,13 +79,16 @@ class AuthenticationAPI {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<bool> verifyOtp(
|
||||
static Future verifyOtp(
|
||||
{required String email, required String otpCode}) async {
|
||||
try{
|
||||
final response = await HTTPService().post(
|
||||
path: ApiEndpoints.verifyOtp,
|
||||
body: {"email": email, "type": "PASSWORD", "otpCode": otpCode},
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
print('json=$json');
|
||||
|
||||
if (json['message'] == 'Otp Verified Successfully') {
|
||||
return true;
|
||||
} else {
|
||||
@ -93,6 +96,20 @@ class AuthenticationAPI {
|
||||
}
|
||||
});
|
||||
return response;
|
||||
}on DioException catch (e){
|
||||
if (e.response != null) {
|
||||
if (e.response!.statusCode == 400) {
|
||||
// Handle 400 Bad Request
|
||||
final errorData = e.response!.data;
|
||||
String errorMessage = errorData['message'];
|
||||
debugPrint('Unexpected Error: $errorMessage');
|
||||
return errorMessage;
|
||||
|
||||
}
|
||||
} else {
|
||||
debugPrint('Error: ${e.message}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Future<List<RegionModel>> fetchRegion() async {
|
||||
|
Reference in New Issue
Block a user