|
|
|
@ -31,7 +31,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|
|
|
|
|
|
|
|
|
////////////////////////////// forget password //////////////////////////////////
|
|
|
|
|
final TextEditingController forgetEmailController = TextEditingController();
|
|
|
|
|
final TextEditingController forgetPasswordController = TextEditingController();
|
|
|
|
|
final TextEditingController forgetPasswordController =
|
|
|
|
|
TextEditingController();
|
|
|
|
|
final TextEditingController forgetOtp = TextEditingController();
|
|
|
|
|
final forgetFormKey = GlobalKey<FormState>();
|
|
|
|
|
final forgetEmailKey = GlobalKey<FormState>();
|
|
|
|
@ -48,7 +49,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_remainingTime = 1;
|
|
|
|
|
add(UpdateTimerEvent(remainingTime: _remainingTime, isButtonEnabled: false));
|
|
|
|
|
add(UpdateTimerEvent(
|
|
|
|
|
remainingTime: _remainingTime, isButtonEnabled: false));
|
|
|
|
|
try {
|
|
|
|
|
forgetEmailValidate = '';
|
|
|
|
|
_remainingTime = (await AuthenticationAPI.sendOtp(
|
|
|
|
@ -84,7 +86,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|
|
|
|
_timer?.cancel();
|
|
|
|
|
add(const UpdateTimerEvent(remainingTime: 0, isButtonEnabled: true));
|
|
|
|
|
} else {
|
|
|
|
|
add(UpdateTimerEvent(remainingTime: _remainingTime, isButtonEnabled: false));
|
|
|
|
|
add(UpdateTimerEvent(
|
|
|
|
|
remainingTime: _remainingTime, isButtonEnabled: false));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -94,21 +97,25 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|
|
|
|
emit(const TimerState(isButtonEnabled: true, remainingTime: 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> changePassword(ChangePasswordEvent event, Emitter<AuthState> emit) async {
|
|
|
|
|
Future<void> changePassword(
|
|
|
|
|
ChangePasswordEvent event, Emitter<AuthState> emit) async {
|
|
|
|
|
emit(LoadingForgetState());
|
|
|
|
|
try {
|
|
|
|
|
var response = await AuthenticationAPI.verifyOtp(
|
|
|
|
|
email: forgetEmailController.text, otpCode: forgetOtp.text);
|
|
|
|
|
if (response == true) {
|
|
|
|
|
await AuthenticationAPI.forgetPassword(
|
|
|
|
|
password: forgetPasswordController.text, email: forgetEmailController.text);
|
|
|
|
|
otpCode: forgetOtp.text,
|
|
|
|
|
password: forgetPasswordController.text,
|
|
|
|
|
email: forgetEmailController.text);
|
|
|
|
|
_timer?.cancel();
|
|
|
|
|
emit(const TimerState(isButtonEnabled: true, remainingTime: 0));
|
|
|
|
|
emit(SuccessForgetState());
|
|
|
|
|
}
|
|
|
|
|
} on DioException catch (e) {
|
|
|
|
|
final errorData = e.response!.data;
|
|
|
|
|
String errorMessage = errorData['error']['message'] ?? 'something went wrong';
|
|
|
|
|
String errorMessage =
|
|
|
|
|
errorData['error']['message'] ?? 'something went wrong';
|
|
|
|
|
validate = errorMessage;
|
|
|
|
|
emit(AuthInitialState());
|
|
|
|
|
}
|
|
|
|
@ -122,7 +129,9 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _onUpdateTimer(UpdateTimerEvent event, Emitter<AuthState> emit) {
|
|
|
|
|
emit(TimerState(isButtonEnabled: event.isButtonEnabled, remainingTime: event.remainingTime));
|
|
|
|
|
emit(TimerState(
|
|
|
|
|
isButtonEnabled: event.isButtonEnabled,
|
|
|
|
|
remainingTime: event.remainingTime));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////// login /////////////////////////////////////
|
|
|
|
@ -154,7 +163,9 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|
|
|
|
|
|
|
|
|
token = await AuthenticationAPI.loginWithEmail(
|
|
|
|
|
model: LoginWithEmailModel(
|
|
|
|
|
email: event.username, password: event.password, regionUuid: event.regionUuid),
|
|
|
|
|
email: event.username,
|
|
|
|
|
password: event.password,
|
|
|
|
|
regionUuid: event.regionUuid),
|
|
|
|
|
);
|
|
|
|
|
} catch (failure) {
|
|
|
|
|
validate = 'Invalid Credentials!';
|
|
|
|
@ -164,7 +175,8 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|
|
|
|
|
|
|
|
|
if (token.accessTokenIsNotEmpty) {
|
|
|
|
|
FlutterSecureStorage storage = const FlutterSecureStorage();
|
|
|
|
|
await storage.write(key: Token.loginAccessTokenKey, value: token.accessToken);
|
|
|
|
|
await storage.write(
|
|
|
|
|
key: Token.loginAccessTokenKey, value: token.accessToken);
|
|
|
|
|
const FlutterSecureStorage().write(
|
|
|
|
|
key: UserModel.userUuidKey,
|
|
|
|
|
value: Token.decodeToken(token.accessToken)['uuid'].toString());
|
|
|
|
@ -322,12 +334,14 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|
|
|
|
static Future<String> getTokenAndValidate() async {
|
|
|
|
|
try {
|
|
|
|
|
const storage = FlutterSecureStorage();
|
|
|
|
|
final firstLaunch =
|
|
|
|
|
await SharedPreferencesHelper.readBoolFromSP(StringsManager.firstLaunch) ?? true;
|
|
|
|
|
final firstLaunch = await SharedPreferencesHelper.readBoolFromSP(
|
|
|
|
|
StringsManager.firstLaunch) ??
|
|
|
|
|
true;
|
|
|
|
|
if (firstLaunch) {
|
|
|
|
|
storage.deleteAll();
|
|
|
|
|
}
|
|
|
|
|
await SharedPreferencesHelper.saveBoolToSP(StringsManager.firstLaunch, false);
|
|
|
|
|
await SharedPreferencesHelper.saveBoolToSP(
|
|
|
|
|
StringsManager.firstLaunch, false);
|
|
|
|
|
final value = await storage.read(key: Token.loginAccessTokenKey) ?? '';
|
|
|
|
|
if (value.isEmpty) {
|
|
|
|
|
return 'Token not found';
|
|
|
|
@ -380,7 +394,9 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|
|
|
|
final String formattedTime = [
|
|
|
|
|
if (days > 0) '${days}d', // Append 'd' for days
|
|
|
|
|
if (days > 0 || hours > 0)
|
|
|
|
|
hours.toString().padLeft(2, '0'), // Show hours if there are days or hours
|
|
|
|
|
hours
|
|
|
|
|
.toString()
|
|
|
|
|
.padLeft(2, '0'), // Show hours if there are days or hours
|
|
|
|
|
minutes.toString().padLeft(2, '0'),
|
|
|
|
|
seconds.toString().padLeft(2, '0'),
|
|
|
|
|
].join(':');
|
|
|
|
|