From 73ab6f3d05b79e3fff5c891a54ee37ad4856ddf6 Mon Sep 17 00:00:00 2001 From: mohammad Date: Wed, 30 Oct 2024 09:47:18 +0300 Subject: [PATCH] forget_password&power_clamp_issue --- lib/pages/auth/bloc/auth_bloc.dart | 42 +++++++++++++------ .../power_clamp/bloc/smart_power_bloc.dart | 7 ++-- .../view/smart_power_device_control.dart | 4 +- lib/services/auth_api.dart | 3 +- lib/utils/color_manager.dart | 3 +- 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/lib/pages/auth/bloc/auth_bloc.dart b/lib/pages/auth/bloc/auth_bloc.dart index 5b269141..60cc2f86 100644 --- a/lib/pages/auth/bloc/auth_bloc.dart +++ b/lib/pages/auth/bloc/auth_bloc.dart @@ -31,7 +31,8 @@ class AuthBloc extends Bloc { ////////////////////////////// forget password ////////////////////////////////// final TextEditingController forgetEmailController = TextEditingController(); - final TextEditingController forgetPasswordController = TextEditingController(); + final TextEditingController forgetPasswordController = + TextEditingController(); final TextEditingController forgetOtp = TextEditingController(); final forgetFormKey = GlobalKey(); final forgetEmailKey = GlobalKey(); @@ -48,7 +49,8 @@ class AuthBloc extends Bloc { 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 { _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 { emit(const TimerState(isButtonEnabled: true, remainingTime: 0)); } - Future changePassword(ChangePasswordEvent event, Emitter emit) async { + Future changePassword( + ChangePasswordEvent event, Emitter 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 { } void _onUpdateTimer(UpdateTimerEvent event, Emitter 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 { 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 { 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 { static Future 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 { 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(':'); diff --git a/lib/pages/device_managment/power_clamp/bloc/smart_power_bloc.dart b/lib/pages/device_managment/power_clamp/bloc/smart_power_bloc.dart index 04cb1b54..6792027f 100644 --- a/lib/pages/device_managment/power_clamp/bloc/smart_power_bloc.dart +++ b/lib/pages/device_managment/power_clamp/bloc/smart_power_bloc.dart @@ -589,14 +589,14 @@ class SmartPowerBloc extends Bloc { TextButton( child: const Text('Cancel'), onPressed: () { - Navigator.of(context) .pop(); + Navigator.of(context).pop(); }, ), TextButton( child: const Text('OK'), onPressed: () { final selectedDateTime = DateTime(selectedYear); - Navigator.of(context).pop(selectedDateTime); + Navigator.of(context).pop(selectedDateTime); }, ), ], @@ -718,7 +718,6 @@ class SmartPowerBloc extends Bloc { // formattedDate = newDate.toString(); }); emit(FilterRecordsState(filteredRecords: energyDataList)); - } List energyDataList = []; @@ -773,7 +772,7 @@ class SmartPowerBloc extends Bloc { } String endChartDate = ''; - + void selectDateRange() async { DateTime startDate = dateTime!; DateTime endDate = DateTime(startDate.year, startDate.month + 1, 1) diff --git a/lib/pages/device_managment/power_clamp/view/smart_power_device_control.dart b/lib/pages/device_managment/power_clamp/view/smart_power_device_control.dart index 635f44ea..0c55dcad 100644 --- a/lib/pages/device_managment/power_clamp/view/smart_power_device_control.dart +++ b/lib/pages/device_managment/power_clamp/view/smart_power_device_control.dart @@ -66,7 +66,7 @@ class SmartPowerDeviceControl extends StatelessWidget style: TextStyle( fontSize: 32, fontWeight: FontWeight.w700, - color: ColorsManager.grayColor), + color: ColorsManager.textPrimaryColor), ), ], ), @@ -176,7 +176,7 @@ class SmartPowerDeviceControl extends StatelessWidget children: [ EnergyConsumptionPage( formattedDate: - '${blocProvider.formattedDate}${blocProvider.endChartDate}', + '${blocProvider.dateTime!.day}/${blocProvider.dateTime!.month}/${blocProvider.dateTime!.year} ${blocProvider.endChartDate}', onTap: () { blocProvider.add(SelectDateEvent(context: context)); blocProvider.add(FilterRecordsByDateEvent( diff --git a/lib/services/auth_api.dart b/lib/services/auth_api.dart index f84bed1a..2b158cdb 100644 --- a/lib/services/auth_api.dart +++ b/lib/services/auth_api.dart @@ -18,10 +18,11 @@ class AuthenticationAPI { static Future forgetPassword({ required var email, required var password, + required var otpCode, }) async { final response = await HTTPService().post( path: ApiEndpoints.forgetPassword, - body: {"email": email, "password": password}, + body: {"email": email, "password": password,"otpCode": otpCode}, showServerMessage: true, expectedResponseModel: (json) {}); return response; diff --git a/lib/utils/color_manager.dart b/lib/utils/color_manager.dart index 9b4692bc..481fb2fa 100644 --- a/lib/utils/color_manager.dart +++ b/lib/utils/color_manager.dart @@ -42,4 +42,5 @@ abstract class ColorsManager { static const Color textGreen = Color(0xFF008905); static const Color yaGreen = Color(0xFFFFBF44); } -//background: #999999; +//background: #background: #5D5D5D; +