From 8dead99ae3779413047eb1963e61ecda639c706a Mon Sep 17 00:00:00 2001 From: JulianAlcala Date: Fri, 9 Jan 2026 13:07:06 +0100 Subject: [PATCH] recover password and link watch data and domain --- .../mobile_app/lib/navigation/app_router.dart | 2 +- apps/mobile_app/pubspec.lock | 2 +- modules/auth/lib/auth.dart | 2 +- .../datasource/auth_remote_datasource.dart | 16 ++- .../auth_remote_datasource_impl.dart | 81 +++++++++---- .../repositories/auth_repository_impl.dart | 33 +++++- .../domain/repositories/auth_repository.dart | 15 ++- .../device_sign_up/device_signup_builder.dart | 2 +- .../domain/create_child_profile_use_case.dart | 15 +++ .../create_child_profile_use_case_impl.dart | 37 ++++++ .../{ => presentation}/add_kid_screen.dart | 0 .../{ => presentation}/contact_screen.dart | 0 .../device_signup_screen.dart | 6 +- .../link_watch/create_profile_screen.dart | 0 .../link_watch_previous_screen.dart | 0 .../link_watch/link_watch_screen.dart | 0 .../use_cases/recover_password_use_case.dart | 9 +- .../recover_password_use_case_impl.dart | 10 +- .../new_password/new_password_screen.dart | 39 ------- .../request_recovery_screen.dart | 80 ++++++------- .../presentation/sent/sent_screen.dart | 45 ++++++-- .../state/recover_password_view_model.dart | 106 +++--------------- 22 files changed, 271 insertions(+), 229 deletions(-) create mode 100644 modules/auth/lib/src/features/device_sign_up/domain/create_child_profile_use_case.dart create mode 100644 modules/auth/lib/src/features/device_sign_up/domain/create_child_profile_use_case_impl.dart rename modules/auth/lib/src/features/device_sign_up/{ => presentation}/add_kid_screen.dart (100%) rename modules/auth/lib/src/features/device_sign_up/{ => presentation}/contact_screen.dart (100%) rename modules/auth/lib/src/features/device_sign_up/{ => presentation}/device_signup_screen.dart (91%) rename modules/auth/lib/src/features/device_sign_up/{ => presentation}/link_watch/create_profile_screen.dart (100%) rename modules/auth/lib/src/features/device_sign_up/{ => presentation}/link_watch/link_watch_previous_screen.dart (100%) rename modules/auth/lib/src/features/device_sign_up/{ => presentation}/link_watch/link_watch_screen.dart (100%) diff --git a/apps/mobile_app/lib/navigation/app_router.dart b/apps/mobile_app/lib/navigation/app_router.dart index 5864d36c..b8850e17 100644 --- a/apps/mobile_app/lib/navigation/app_router.dart +++ b/apps/mobile_app/lib/navigation/app_router.dart @@ -15,7 +15,7 @@ late final GoRouter appRouter; void configureAppRouter() { appRouter = GoRouter( navigatorKey: rootNavigatorKey, - initialLocation: AppRoutes.onboarding, + initialLocation: AppRoutes.login, debugLogDiagnostics: true, routes: [ GoRoute( diff --git a/apps/mobile_app/pubspec.lock b/apps/mobile_app/pubspec.lock index eaaefdb3..843c818c 100644 --- a/apps/mobile_app/pubspec.lock +++ b/apps/mobile_app/pubspec.lock @@ -832,7 +832,7 @@ packages: source: hosted version: "1.4.0" utils: - dependency: "direct overridden" + dependency: "direct main" description: path: "../../packages/utils" relative: true diff --git a/modules/auth/lib/auth.dart b/modules/auth/lib/auth.dart index 57994d61..c7e32910 100644 --- a/modules/auth/lib/auth.dart +++ b/modules/auth/lib/auth.dart @@ -1,4 +1,4 @@ -export 'src/features/device_sign_up/link_watch/create_profile_screen.dart'; +export 'src/features/device_sign_up/presentation/link_watch/create_profile_screen.dart'; export 'src/features/onboarding/onboarding_builder.dart'; export 'src/features/link_phone/presentation/request_phone/request_link_phone_builder.dart'; export 'src/features/link_phone/presentation/verify_code/verify_link_phone_code_builder.dart'; diff --git a/modules/auth/lib/src/core/data/datasource/auth_remote_datasource.dart b/modules/auth/lib/src/core/data/datasource/auth_remote_datasource.dart index 136241fd..15f7a8b3 100644 --- a/modules/auth/lib/src/core/data/datasource/auth_remote_datasource.dart +++ b/modules/auth/lib/src/core/data/datasource/auth_remote_datasource.dart @@ -16,7 +16,21 @@ abstract class AuthRemoteDatasource { required String token, required String code, }); - Future requestPasswordReset({String? phone, String? email}); + Future requestPasswordReset({required String email}); Future recoverPassword({required newPassword, required token}); + + Future createChildProfile({ + required String id, + required String parentId, + required String firstName, + required String lastName, + required int bornAt, + required String gender, + required String relationType, + required String address, + required String cardPublicKey, + required String deviceActivationCode, + required String scaProof, + }); } diff --git a/modules/auth/lib/src/core/data/datasource/auth_remote_datasource_impl.dart b/modules/auth/lib/src/core/data/datasource/auth_remote_datasource_impl.dart index a09d339b..feafde44 100644 --- a/modules/auth/lib/src/core/data/datasource/auth_remote_datasource_impl.dart +++ b/modules/auth/lib/src/core/data/datasource/auth_remote_datasource_impl.dart @@ -169,32 +169,26 @@ class AuthRemoteDatasourceImpl implements AuthRemoteDatasource { } @override - Future requestPasswordReset({ - String? phone, - String? email - }) async { + Future requestPasswordReset({required String email}) async { try { - if (phone == null && email == null) { - throw FormatException("No phone or email address given"); - } + late final Map body; + body = {'email': email}; - // late final Map body; - if (email != null) { - // body = {'email': email}; - return 'ec14b7e7-58dd-4a59-9f41-0da86eaabf14'; - } else { - // body = {'phone': phone!}; - return 'ec14b7e7-58dd-4a59-9f41-0da86eaabf14'; - // throw Exception("reset by phone is not currently implemented"); - } - /*final response = await _repository.put>( + final response = await _repository.put( '/auth/reset-password', body: body, ); - final token = response.data!['token']; - return token;*/ + final data = response.data; + if (data == null || data.isEmpty) { + throw Exception('Empty response from /auth/totp/code'); + } + + return data; } on DioException catch (error) { - throw _mapDioError(error, defaultMessage: 'Error to request password reset'); + throw _mapDioError( + error, + defaultMessage: 'Error to request password reset', + ); } } @@ -206,7 +200,52 @@ class AuthRemoteDatasourceImpl implements AuthRemoteDatasource { body: {'newPassword': newPassword, 'token': token}, ); } on DioException catch (error) { - throw _mapDioError(error, defaultMessage: 'Error to request password recovery'); + throw _mapDioError( + error, + defaultMessage: 'Error to request password recovery', + ); + } + } + + @override + Future createChildProfile({ + required String id, + required String parentId, + required String firstName, + required String lastName, + required int bornAt, + required String gender, + required String relationType, + required String address, + required String cardPublicKey, + required String deviceActivationCode, + required String scaProof, + }) async { + try { + final response = await _repository.post>( + '/auth/child-profiles', + body: { + 'id': id, + 'parentId': parentId, + 'firstName': firstName, + 'lastName': lastName, + 'bornAt': bornAt, + 'gender': gender, + 'relationType': relationType, + 'address': address, + 'cardPublicKey': cardPublicKey, + 'deviceActivationCode': deviceActivationCode, + 'scaProof': scaProof, + }, + ); + final data = response.data; + if (data == null || data.isEmpty) { + throw Exception('Empty response from /auth/child-profiles'); + } else { + return data['id']; + } + } on DioException catch (error) { + throw _mapDioError(error, defaultMessage: 'Error in createChildProfile'); } } } diff --git a/modules/auth/lib/src/core/data/repositories/auth_repository_impl.dart b/modules/auth/lib/src/core/data/repositories/auth_repository_impl.dart index 1f2fb7a0..a345990b 100644 --- a/modules/auth/lib/src/core/data/repositories/auth_repository_impl.dart +++ b/modules/auth/lib/src/core/data/repositories/auth_repository_impl.dart @@ -47,8 +47,8 @@ class AuthRepositoryImpl implements AuthRepository { } @override - Future requestPasswordReset({String? phone, String? email}) { - return _remote.requestPasswordReset(phone: phone, email: email); + Future requestPasswordReset({required String email}) { + return _remote.requestPasswordReset(email: email); } @override @@ -58,4 +58,33 @@ class AuthRepositoryImpl implements AuthRepository { }) { return _remote.recoverPassword(newPassword: newPassword, token: token); } + + @override + Future createChildProfile({ + required String id, + required String parentId, + required String firstName, + required String lastName, + required int bornAt, + required String gender, + required String relationType, + required String address, + required String cardPublicKey, + required String deviceActivationCode, + required String scaProof, + }) { + return _remote.createChildProfile( + id: id, + parentId: parentId, + firstName: firstName, + lastName: lastName, + bornAt: bornAt, + gender: gender, + relationType: relationType, + address: address, + cardPublicKey: cardPublicKey, + deviceActivationCode: deviceActivationCode, + scaProof: scaProof, + ); + } } diff --git a/modules/auth/lib/src/core/domain/repositories/auth_repository.dart b/modules/auth/lib/src/core/domain/repositories/auth_repository.dart index 5e78e95e..bb8cf60a 100644 --- a/modules/auth/lib/src/core/domain/repositories/auth_repository.dart +++ b/modules/auth/lib/src/core/domain/repositories/auth_repository.dart @@ -9,7 +9,7 @@ abstract class AuthRepository { Future login({required String email, required String password}); Future twoFactor({required String token, required String code}); - Future requestPasswordReset({String phone, String email}); + Future requestPasswordReset({required String email}); Future recoverPassword({ required String newPassword, @@ -23,4 +23,17 @@ abstract class AuthRepository { required String token, required String code, }); + Future createChildProfile({ + required String id, + required String parentId, + required String firstName, + required String lastName, + required int bornAt, + required String gender, + required String relationType, + required String address, + required String cardPublicKey, + required String deviceActivationCode, + required String scaProof, + }); } diff --git a/modules/auth/lib/src/features/device_sign_up/device_signup_builder.dart b/modules/auth/lib/src/features/device_sign_up/device_signup_builder.dart index d2f648ff..3e6aa449 100644 --- a/modules/auth/lib/src/features/device_sign_up/device_signup_builder.dart +++ b/modules/auth/lib/src/features/device_sign_up/device_signup_builder.dart @@ -1,4 +1,4 @@ -import 'package:auth/src/features/device_sign_up/device_signup_screen.dart'; +import 'package:auth/src/features/device_sign_up/presentation/device_signup_screen.dart'; import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; diff --git a/modules/auth/lib/src/features/device_sign_up/domain/create_child_profile_use_case.dart b/modules/auth/lib/src/features/device_sign_up/domain/create_child_profile_use_case.dart new file mode 100644 index 00000000..816a855a --- /dev/null +++ b/modules/auth/lib/src/features/device_sign_up/domain/create_child_profile_use_case.dart @@ -0,0 +1,15 @@ +abstract class CreateChildProfileUseCase { + Future createChildProfile({ + required String id, + required String parentId, + required String firstName, + required String lastName, + required int bornAt, + required String gender, + required String relationType, + required String address, + required String cardPublicKey, + required String deviceActivationCode, + required String scaProof, + }); +} diff --git a/modules/auth/lib/src/features/device_sign_up/domain/create_child_profile_use_case_impl.dart b/modules/auth/lib/src/features/device_sign_up/domain/create_child_profile_use_case_impl.dart new file mode 100644 index 00000000..1252a560 --- /dev/null +++ b/modules/auth/lib/src/features/device_sign_up/domain/create_child_profile_use_case_impl.dart @@ -0,0 +1,37 @@ +import 'package:auth/src/core/domain/repositories/auth_repository.dart'; +import 'package:auth/src/features/device_sign_up/domain/create_child_profile_use_case.dart'; + +class CreateChildProfileUseCaseImpl implements CreateChildProfileUseCase { + CreateChildProfileUseCaseImpl(this._repository); + + final AuthRepository _repository; + + @override + Future createChildProfile({ + required String id, + required String parentId, + required String firstName, + required String lastName, + required int bornAt, + required String gender, + required String relationType, + required String address, + required String cardPublicKey, + required String deviceActivationCode, + required String scaProof, + }) { + return _repository.createChildProfile( + id: id, + parentId: parentId, + firstName: firstName, + lastName: lastName, + bornAt: bornAt, + gender: gender, + relationType: relationType, + address: address, + cardPublicKey: cardPublicKey, + deviceActivationCode: deviceActivationCode, + scaProof: scaProof, + ); + } +} diff --git a/modules/auth/lib/src/features/device_sign_up/add_kid_screen.dart b/modules/auth/lib/src/features/device_sign_up/presentation/add_kid_screen.dart similarity index 100% rename from modules/auth/lib/src/features/device_sign_up/add_kid_screen.dart rename to modules/auth/lib/src/features/device_sign_up/presentation/add_kid_screen.dart diff --git a/modules/auth/lib/src/features/device_sign_up/contact_screen.dart b/modules/auth/lib/src/features/device_sign_up/presentation/contact_screen.dart similarity index 100% rename from modules/auth/lib/src/features/device_sign_up/contact_screen.dart rename to modules/auth/lib/src/features/device_sign_up/presentation/contact_screen.dart diff --git a/modules/auth/lib/src/features/device_sign_up/device_signup_screen.dart b/modules/auth/lib/src/features/device_sign_up/presentation/device_signup_screen.dart similarity index 91% rename from modules/auth/lib/src/features/device_sign_up/device_signup_screen.dart rename to modules/auth/lib/src/features/device_sign_up/presentation/device_signup_screen.dart index bc12c18e..b263e406 100644 --- a/modules/auth/lib/src/features/device_sign_up/device_signup_screen.dart +++ b/modules/auth/lib/src/features/device_sign_up/presentation/device_signup_screen.dart @@ -1,7 +1,7 @@ import 'package:auth/auth.dart'; -import 'package:auth/src/features/device_sign_up/add_kid_screen.dart'; -import 'package:auth/src/features/device_sign_up/link_watch/link_watch_screen.dart'; -import 'package:auth/src/features/device_sign_up/link_watch/link_watch_previous_screen.dart'; +import 'package:auth/src/features/device_sign_up/presentation/add_kid_screen.dart'; +import 'package:auth/src/features/device_sign_up/presentation/link_watch/link_watch_screen.dart'; +import 'package:auth/src/features/device_sign_up/presentation/link_watch/link_watch_previous_screen.dart'; import 'package:auth/src/features/sign_up/presentation/screens/account_created_screen.dart'; import 'package:auth/src/widgets/layouts/form_step_layout.dart'; import 'package:design_system/design_system.dart'; diff --git a/modules/auth/lib/src/features/device_sign_up/link_watch/create_profile_screen.dart b/modules/auth/lib/src/features/device_sign_up/presentation/link_watch/create_profile_screen.dart similarity index 100% rename from modules/auth/lib/src/features/device_sign_up/link_watch/create_profile_screen.dart rename to modules/auth/lib/src/features/device_sign_up/presentation/link_watch/create_profile_screen.dart diff --git a/modules/auth/lib/src/features/device_sign_up/link_watch/link_watch_previous_screen.dart b/modules/auth/lib/src/features/device_sign_up/presentation/link_watch/link_watch_previous_screen.dart similarity index 100% rename from modules/auth/lib/src/features/device_sign_up/link_watch/link_watch_previous_screen.dart rename to modules/auth/lib/src/features/device_sign_up/presentation/link_watch/link_watch_previous_screen.dart diff --git a/modules/auth/lib/src/features/device_sign_up/link_watch/link_watch_screen.dart b/modules/auth/lib/src/features/device_sign_up/presentation/link_watch/link_watch_screen.dart similarity index 100% rename from modules/auth/lib/src/features/device_sign_up/link_watch/link_watch_screen.dart rename to modules/auth/lib/src/features/device_sign_up/presentation/link_watch/link_watch_screen.dart diff --git a/modules/auth/lib/src/features/recover_password/domain/use_cases/recover_password_use_case.dart b/modules/auth/lib/src/features/recover_password/domain/use_cases/recover_password_use_case.dart index 76228be2..54f355a3 100644 --- a/modules/auth/lib/src/features/recover_password/domain/use_cases/recover_password_use_case.dart +++ b/modules/auth/lib/src/features/recover_password/domain/use_cases/recover_password_use_case.dart @@ -1,7 +1,8 @@ abstract class RecoverPasswordUseCase { Future requestEmail({required String email}); - Future requestSms({required String phone}); - - Future recoverPassword({required String newPassword, required String token}); -} \ No newline at end of file + Future recoverPassword({ + required String newPassword, + required String token, + }); +} diff --git a/modules/auth/lib/src/features/recover_password/domain/use_cases/recover_password_use_case_impl.dart b/modules/auth/lib/src/features/recover_password/domain/use_cases/recover_password_use_case_impl.dart index 6699e8f8..c97b1c0d 100644 --- a/modules/auth/lib/src/features/recover_password/domain/use_cases/recover_password_use_case_impl.dart +++ b/modules/auth/lib/src/features/recover_password/domain/use_cases/recover_password_use_case_impl.dart @@ -12,12 +12,10 @@ class RecoverPasswordUseCaseImpl implements RecoverPasswordUseCase { } @override - Future requestSms({required String phone}) async { - return await _repository.requestPasswordReset(phone: phone); - } - - @override - Future recoverPassword({required String newPassword, required String token}) async { + Future recoverPassword({ + required String newPassword, + required String token, + }) async { await _repository.recoverPassword(newPassword: newPassword, token: token); } } diff --git a/modules/auth/lib/src/features/recover_password/presentation/new_password/new_password_screen.dart b/modules/auth/lib/src/features/recover_password/presentation/new_password/new_password_screen.dart index 1eb2eb21..25148195 100644 --- a/modules/auth/lib/src/features/recover_password/presentation/new_password/new_password_screen.dart +++ b/modules/auth/lib/src/features/recover_password/presentation/new_password/new_password_screen.dart @@ -45,7 +45,6 @@ class NewPasswordScreen extends ConsumerWidget { labelSize: SizeUtils.getByScreen(small: 14, big: 14, xl: 12), hint: '********', controller: viewModel.passwordController, - // onVisibilityChanged: viewModel.togglePasswordVisible, ), SizedBox(height: 16), CustomTextField( @@ -54,8 +53,6 @@ class NewPasswordScreen extends ConsumerWidget { labelSize: SizeUtils.getByScreen(small: 14, big: 14, xl: 12), hint: '********', controller: viewModel.repeatedPasswordController, - // onVisibilityChanged: viewModel.togglePasswordVisible, - // color: viewState.equalPasswords ? const Color(0xFF4B4B4B) : const Color.fromRGBO(239, 17, 17, 1), ), if (!viewState.equalPasswords) ...[ SizedBox(height: 4), @@ -178,42 +175,6 @@ class NewPasswordScreen extends ConsumerWidget { SizedBox( height: SizeUtils.getByScreen(small: 32, big: 32, xl: 24), ), - Align( - alignment: Alignment.bottomLeft, - child: Text( - context.translate(I18n.mobilePhone), - style: TextStyle( - fontSize: SizeUtils.getByScreen( - small: 14, - big: 14, - xl: 12, - ), - letterSpacing: 0, - ), - ), - ), - SizedBox(height: 8), - Row( - spacing: 8, - children: [ - CountryPrefixPicker( - headerText: context.translate(I18n.selectYourCountry), - width: 80, - onChanged: (country) { - viewModel.updateDialCode( - country.dialCode ?? viewState.dialCode, - ); - }, - ), - Expanded( - child: CustomTextField( - hint: context.translate(I18n.phoneNumber), - keyboardType: TextInputType.number, - controller: viewModel.newPhoneNumberController, - ), - ), - ], - ), if (viewState.errorMessage.isNotEmpty) ...[ SizedBox(height: 10), Text( diff --git a/modules/auth/lib/src/features/recover_password/presentation/request_recovery/request_recovery_screen.dart b/modules/auth/lib/src/features/recover_password/presentation/request_recovery/request_recovery_screen.dart index b82e723c..669aca5e 100644 --- a/modules/auth/lib/src/features/recover_password/presentation/request_recovery/request_recovery_screen.dart +++ b/modules/auth/lib/src/features/recover_password/presentation/request_recovery/request_recovery_screen.dart @@ -23,20 +23,28 @@ class RequestRecoveryScreen extends ConsumerWidget { return Scaffold( backgroundColor: theme.getColorFor(ThemeCode.backgroundPrimary), body: Container( - margin: EdgeInsets.all(SizeUtils.getByScreen(small: 30, big: 30, xl: 20)), + margin: EdgeInsets.all( + SizeUtils.getByScreen(small: 30, big: 30, xl: 20), + ), child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( context.translate(I18n.recoverPasswordTitle), - style: TextStyle(fontWeight: FontWeight.bold, fontSize: SizeUtils.getByScreen(small: 29, big: 29, xl: 26)), + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: SizeUtils.getByScreen(small: 29, big: 28, xl: 26), + ), ), SizedBox(height: SizeUtils.getByScreen(small: 24, big: 32)), Text( context.translate(I18n.recoverPasswordSubtitle), textAlign: TextAlign.center, - style: TextStyle(letterSpacing: 0, fontSize: SizeUtils.getByScreen(small: 18, big: 18, xl: 16)), + style: TextStyle( + letterSpacing: 0, + fontSize: SizeUtils.getByScreen(small: 18, big: 18, xl: 16), + ), ), SizedBox(height: SizeUtils.getByScreen(small: 56, big: 48)), CustomTextField( @@ -44,49 +52,23 @@ class RequestRecoveryScreen extends ConsumerWidget { hint: context.translate(I18n.email), controller: viewModel.emailController, ), - SizedBox(height: SizeUtils.getByScreen(small: 40, big: 40, xl: 28)), - Align( - alignment: Alignment.bottomLeft, - child: Text( - context.translate(I18n.mobilePhone), - style: TextStyle(fontSize: 14, letterSpacing: 0), - ), + SizedBox( + height: SizeUtils.getByScreen(small: 20, big: 20, xl: 28), ), - SizedBox(height: 8), - Row( - children: [ - CountryPrefixPicker( - headerText: context.translate(I18n.selectYourCountry), - initialCountryCode: viewState.dialCode, - onChanged: (country) { - viewModel.updateDialCode( - country.dialCode ?? viewState.dialCode, - ); - }, - width: 80, - ), - SizedBox(width: SizeUtils.getByScreen(small: 10, big: 10, xl: 6)), - Expanded( - child: CustomTextField( - hint: context.translate(I18n.phoneNumber), - keyboardType: TextInputType.number, - controller: viewModel.phoneNumberController, - ), - ), - ], - ), - SizedBox(height: SizeUtils.getByScreen(small: 40, big: 40, xl: 28)), + if (viewState.errorMessage.isNotEmpty) ...[ - Text( - context.translate(viewState.errorMessage), - textAlign: TextAlign.center, - style: const TextStyle( - color: Color.fromRGBO(239, 17, 17, 1), - fontSize: 12, - ), + Text( + context.translate(viewState.errorMessage), + textAlign: TextAlign.center, + style: const TextStyle( + color: Color.fromRGBO(239, 17, 17, 1), + fontSize: 12, ), - SizedBox(height: 40), - ], + ), + ], + SizedBox( + height: SizeUtils.getByScreen(small: 10, big: 10, xl: 18), + ), Row( children: [ Expanded( @@ -96,17 +78,23 @@ class RequestRecoveryScreen extends ConsumerWidget { size: SizeUtils.getByScreen(small: 16, big: 16, xl: 14), ), ), - SizedBox(width: SizeUtils.getByScreen(small: 20, big: 20, xl: 10)), + SizedBox( + width: SizeUtils.getByScreen(small: 20, big: 20, xl: 10), + ), Expanded( child: PrimaryButton( onPressed: () async { await viewModel.requestRecovery(); - final updatedState = ref.read(recoverPasswordViewModelProvider); + final updatedState = ref.read( + recoverPasswordViewModelProvider, + ); if (updatedState.recoveryRequested) { Navigator.push( context, MaterialPageRoute( - builder: (_) => SentScreen(navigationContract: navigationContract), + builder: (_) => SentScreen( + navigationContract: navigationContract, + ), ), ); } diff --git a/modules/auth/lib/src/features/recover_password/presentation/sent/sent_screen.dart b/modules/auth/lib/src/features/recover_password/presentation/sent/sent_screen.dart index ddec9f64..c8c7777a 100644 --- a/modules/auth/lib/src/features/recover_password/presentation/sent/sent_screen.dart +++ b/modules/auth/lib/src/features/recover_password/presentation/sent/sent_screen.dart @@ -37,7 +37,9 @@ class SentScreen extends ConsumerWidget { letterSpacing: 0, ), ), - SizedBox(height: SizeUtils.getByScreen(small: 48, big: 48, xl: 40)), + SizedBox( + height: SizeUtils.getByScreen(small: 48, big: 48, xl: 40), + ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -45,22 +47,36 @@ class SentScreen extends ConsumerWidget { Icons.check, color: theme.getColorFor(ThemeCode.buttonPrimary), ), - SizedBox(width: SizeUtils.getByScreen(small: 10, big: 10, xl: 6)), + SizedBox( + width: SizeUtils.getByScreen(small: 10, big: 10, xl: 6), + ), Text( viewState.recoveryFormat == "email" ? context.translate(I18n.emailSent) : context.translate(I18n.smsSent), - style: TextStyle(fontSize: SizeUtils.getByScreen(small: 18, big: 18, xl: 15), fontWeight: FontWeight.bold), + style: TextStyle( + fontSize: SizeUtils.getByScreen( + small: 18, + big: 18, + xl: 15, + ), + fontWeight: FontWeight.bold, + ), ), ], ), - SizedBox(height: SizeUtils.getByScreen(small: 48, big: 48, xl: 40)), + SizedBox( + height: SizeUtils.getByScreen(small: 48, big: 48, xl: 40), + ), Text( viewState.recoveryFormat == "email" ? context.translate(I18n.checkEmail1) : context.translate(I18n.checkSms1), textAlign: TextAlign.center, - style: TextStyle(fontSize: SizeUtils.getByScreen(small: 17, big: 17, xl: 15), letterSpacing: 0), + style: TextStyle( + fontSize: SizeUtils.getByScreen(small: 17, big: 17, xl: 15), + letterSpacing: 0, + ), ), SizedBox(height: 16), Text( @@ -68,18 +84,21 @@ class SentScreen extends ConsumerWidget { ? context.translate(I18n.checkEmail2) : context.translate(I18n.checkSms2), textAlign: TextAlign.center, - style: TextStyle(fontSize: SizeUtils.getByScreen(small: 14, big: 14, xl: 12), letterSpacing: 0), + style: TextStyle( + fontSize: SizeUtils.getByScreen(small: 14, big: 14, xl: 12), + letterSpacing: 0, + ), + ), + SizedBox( + height: SizeUtils.getByScreen(small: 48, big: 48, xl: 40), ), - SizedBox(height: SizeUtils.getByScreen(small: 48, big: 48, xl: 40)), Row( children: [ Expanded( child: SecondaryButton( onPressed: () { - if ( viewState.recoveryFormat == "email") { + if (viewState.recoveryFormat == "email") { viewModel.requestEmail(); - } else { - viewModel.requestSms(); } }, text: viewState.recoveryFormat == "email" @@ -93,7 +112,11 @@ class SentScreen extends ConsumerWidget { child: PrimaryButton( onPressed: () => Navigator.push( context, - MaterialPageRoute(builder: (_) => NewPasswordScreen(navigationContract: navigationContract)), + MaterialPageRoute( + builder: (_) => NewPasswordScreen( + navigationContract: navigationContract, + ), + ), ), text: context.translate(I18n.continueKey), color: theme.getColorFor(ThemeCode.buttonSecondary), diff --git a/modules/auth/lib/src/features/recover_password/presentation/state/recover_password_view_model.dart b/modules/auth/lib/src/features/recover_password/presentation/state/recover_password_view_model.dart index 2fd912c7..d84d61c2 100644 --- a/modules/auth/lib/src/features/recover_password/presentation/state/recover_password_view_model.dart +++ b/modules/auth/lib/src/features/recover_password/presentation/state/recover_password_view_model.dart @@ -6,9 +6,10 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../providers/recover_password_provider.dart'; final recoverPasswordViewModelProvider = -NotifierProvider.autoDispose( - RecoverPasswordViewModel.new, -); + NotifierProvider.autoDispose< + RecoverPasswordViewModel, + RecoverPasswordViewState + >(RecoverPasswordViewModel.new); class RecoverPasswordViewModel extends Notifier { late final RecoverPasswordUseCase _recoverPasswordUseCase; @@ -22,9 +23,6 @@ class RecoverPasswordViewModel extends Notifier { RecoverPasswordViewState build() { _recoverPasswordUseCase = ref.read(recoverPasswordUseCaseProvider); - phoneNumberController = TextEditingController(); - phoneNumberController.addListener(_onPhoneNumberChanged); - emailController = TextEditingController(); emailController.addListener(_onEmailChanged); @@ -34,32 +32,11 @@ class RecoverPasswordViewModel extends Notifier { repeatedPasswordController = TextEditingController(); repeatedPasswordController.addListener(_onRepeatedPasswordChanged); - newPhoneNumberController = TextEditingController(); - newPhoneNumberController.addListener(_onNewPhoneNumberChanged); - ref.onDispose(disposeControllers); return const RecoverPasswordViewState(); } - void _onPhoneNumberChanged() { - final String raw = phoneNumberController.text; - state = state.copyWith( - phoneNumber: raw, - errorMessage: '', - recoveryRequested: false, - ); - } - - void _onNewPhoneNumberChanged() { - final String raw = newPhoneNumberController.text; - state = state.copyWith( - newPhoneNumber: raw, - errorMessage: '', - recoveryRequested: false, - ); - } - void _onEmailChanged() { final String raw = emailController.text; state = state.copyWith( @@ -103,28 +80,11 @@ class RecoverPasswordViewModel extends Notifier { ); } - void updateDialCode(String dialCode) { - state = state.copyWith( - dialCode: dialCode, - errorMessage: '', - ); - } - - void updateNewDialCode(String dialCode) { - state = state.copyWith( - newDialCode: dialCode, - errorMessage: '', - ); - } - - void togglePasswordVisible(){ - state = state.copyWith( - passwordVisible: !state.passwordVisible, - ); + void togglePasswordVisible() { + state = state.copyWith(passwordVisible: !state.passwordVisible); } Future requestRecovery() async { - final trimmedNumber = state.phoneNumber.trim(); final email = state.email.trim(); state = state.copyWith( @@ -135,8 +95,6 @@ class RecoverPasswordViewModel extends Notifier { if (email.isNotEmpty) { await requestEmail(); - } else if (trimmedNumber.isNotEmpty) { - await requestSms(); } else { state = state.copyWith( isLoading: false, @@ -150,7 +108,9 @@ class RecoverPasswordViewModel extends Notifier { final email = state.email.trim(); try { - final String token = await _recoverPasswordUseCase.requestEmail(email: email); + final String token = await _recoverPasswordUseCase.requestEmail( + email: email, + ); if (!ref.mounted) return; state = state.copyWith( @@ -172,34 +132,6 @@ class RecoverPasswordViewModel extends Notifier { } } - Future requestSms() async { - final trimmedNumber = state.phoneNumber.trim(); - - final fullPhone = '${state.dialCode}$trimmedNumber'; - - try { - final String token = await _recoverPasswordUseCase.requestSms(phone: fullPhone); - if (!ref.mounted) return; - - state = state.copyWith( - isLoading: false, - errorMessage: '', - recoveryRequested: true, - token: token, - recoveryFormat: 'sms' - ); - } catch (e) { - if (!ref.mounted) return; - - state = state.copyWith( - isLoading: false, - errorMessage: e.toString(), - recoveryRequested: false, - passwordChanged: false, - ); - } - } - Future recoverPassword() async { //final String fullPhone = state.newDialCode + state.newPhoneNumber; final String password = state.password; @@ -244,17 +176,13 @@ class RecoverPasswordViewModel extends Notifier { return; } - state = state.copyWith( - isLoading: true, - passwordChanged: false, - ); + state = state.copyWith(isLoading: true, passwordChanged: false); try { await _recoverPasswordUseCase.recoverPassword( - newPassword: password, token: state.token); - state = state.copyWith( - isLoading: false, - passwordChanged: true, + newPassword: password, + token: state.token, ); + state = state.copyWith(isLoading: false, passwordChanged: true); } catch (error) { state = state.copyWith( errorMessage: error.toString(), @@ -265,15 +193,11 @@ class RecoverPasswordViewModel extends Notifier { } void disposeControllers() { - phoneNumberController.removeListener(_onPhoneNumberChanged); - phoneNumberController.dispose(); - emailController.removeListener(_onPhoneNumberChanged); + emailController.removeListener(_onEmailChanged); emailController.dispose(); passwordController.removeListener(_onPasswordChanged); passwordController.dispose(); repeatedPasswordController.removeListener(_onRepeatedPasswordChanged); repeatedPasswordController.dispose(); - newPhoneNumberController.removeListener(_onNewPhoneNumberChanged); - newPhoneNumberController.dispose(); } -} \ No newline at end of file +}