reset password fix
This commit is contained in:
parent
dc8feb9c9e
commit
4a4c785304
@ -33,7 +33,7 @@ class ApiAuthRepository implements AuthRepository {
|
|||||||
body: requestBody,
|
body: requestBody,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode >= 200) {
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||||
return _parseUserFromResponse(
|
return _parseUserFromResponse(
|
||||||
response.body,
|
response.body,
|
||||||
fallbackUsername: username.trim(),
|
fallbackUsername: username.trim(),
|
||||||
@ -73,7 +73,7 @@ class ApiAuthRepository implements AuthRepository {
|
|||||||
body: requestBody,
|
body: requestBody,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode >= 200) {
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||||
return _parseUserFromResponse(
|
return _parseUserFromResponse(
|
||||||
response.body,
|
response.body,
|
||||||
fallbackUsername: username,
|
fallbackUsername: username,
|
||||||
@ -89,9 +89,14 @@ class ApiAuthRepository implements AuthRepository {
|
|||||||
Future<void> resetPassword({
|
Future<void> resetPassword({
|
||||||
required String userId,
|
required String userId,
|
||||||
required String password,
|
required String password,
|
||||||
|
required String oldPassword,
|
||||||
}) async {
|
}) async {
|
||||||
final uri = Uri.parse('$baseUrl/auth/reset-password');
|
final uri = Uri.parse('$baseUrl/auth/reset-password');
|
||||||
final requestBody = jsonEncode({'userId': userId, 'password': password});
|
final requestBody = jsonEncode({
|
||||||
|
'userId': userId,
|
||||||
|
'password': password,
|
||||||
|
'password2': oldPassword,
|
||||||
|
});
|
||||||
|
|
||||||
final response = await _client.put(
|
final response = await _client.put(
|
||||||
uri,
|
uri,
|
||||||
@ -99,7 +104,7 @@ class ApiAuthRepository implements AuthRepository {
|
|||||||
body: requestBody,
|
body: requestBody,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode >= 200) {
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +124,7 @@ class ApiAuthRepository implements AuthRepository {
|
|||||||
headers: {'Content-Type': 'application/json', 'x-api-key': apiSecret},
|
headers: {'Content-Type': 'application/json', 'x-api-key': apiSecret},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode >= 200) {
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||||
return _extractSuccessMessage(
|
return _extractSuccessMessage(
|
||||||
response.body,
|
response.body,
|
||||||
fallback: 'Password reset successfully',
|
fallback: 'Password reset successfully',
|
||||||
@ -148,7 +153,7 @@ class ApiAuthRepository implements AuthRepository {
|
|||||||
body: requestBody,
|
body: requestBody,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode >= 200) {
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||||
return _extractSuccessMessage(
|
return _extractSuccessMessage(
|
||||||
response.body,
|
response.body,
|
||||||
fallback: 'Password changed successfully',
|
fallback: 'Password changed successfully',
|
||||||
@ -169,7 +174,7 @@ class ApiAuthRepository implements AuthRepository {
|
|||||||
body: requestBody,
|
body: requestBody,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode >= 200) {
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -49,12 +49,16 @@ class MockAuthRepository implements AuthRepository {
|
|||||||
Future<void> resetPassword({
|
Future<void> resetPassword({
|
||||||
required String userId,
|
required String userId,
|
||||||
required String password,
|
required String password,
|
||||||
|
required String oldPassword,
|
||||||
}) async {
|
}) async {
|
||||||
await Future<void>.delayed(const Duration(milliseconds: 500));
|
await Future<void>.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
if (userId.trim().isEmpty) {
|
if (userId.trim().isEmpty) {
|
||||||
throw Exception('User ID is required.');
|
throw Exception('User ID is required.');
|
||||||
}
|
}
|
||||||
|
if (oldPassword.isEmpty) {
|
||||||
|
throw Exception('Old password is required.');
|
||||||
|
}
|
||||||
if (password.length < 8) {
|
if (password.length < 8) {
|
||||||
throw Exception('Password must be at least 8 characters.');
|
throw Exception('Password must be at least 8 characters.');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ abstract class AuthRepository {
|
|||||||
Future<void> resetPassword({
|
Future<void> resetPassword({
|
||||||
required String userId,
|
required String userId,
|
||||||
required String password,
|
required String password,
|
||||||
|
required String oldPassword,
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<String> resetCashierPassword({required String username});
|
Future<String> resetCashierPassword({required String username});
|
||||||
|
|||||||
@ -31,7 +31,9 @@ class LoginPage extends ConsumerWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TextInput.finishAutofillContext();
|
TextInput.finishAutofillContext();
|
||||||
ref.read(loginViewModelProvider.notifier).login(
|
ref
|
||||||
|
.read(loginViewModelProvider.notifier)
|
||||||
|
.login(
|
||||||
username: usernameController.text,
|
username: usernameController.text,
|
||||||
password: passwordController.text,
|
password: passwordController.text,
|
||||||
);
|
);
|
||||||
@ -51,6 +53,7 @@ class LoginPage extends ConsumerWidget {
|
|||||||
switch (action) {
|
switch (action) {
|
||||||
case LoginRequiredAction.passwordUpdateRequired:
|
case LoginRequiredAction.passwordUpdateRequired:
|
||||||
final userId = (next.requiredUserId ?? '').trim();
|
final userId = (next.requiredUserId ?? '').trim();
|
||||||
|
final oldPassword = next.requiredOldPassword ?? '';
|
||||||
if (userId.isEmpty) {
|
if (userId.isEmpty) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(
|
||||||
@ -61,6 +64,18 @@ class LoginPage extends ConsumerWidget {
|
|||||||
ref.read(loginViewModelProvider.notifier).clearRequirement();
|
ref.read(loginViewModelProvider.notifier).clearRequirement();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (oldPassword.isEmpty) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text(
|
||||||
|
'Password update required (missing login password)',
|
||||||
|
),
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
ref.read(loginViewModelProvider.notifier).clearRequirement();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(
|
||||||
@ -70,7 +85,10 @@ class LoginPage extends ConsumerWidget {
|
|||||||
);
|
);
|
||||||
ref.read(loginViewModelProvider.notifier).clearRequirement();
|
ref.read(loginViewModelProvider.notifier).clearRequirement();
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute<void>(builder: (_) => ResetPasswordPage(userId: userId)),
|
MaterialPageRoute<void>(
|
||||||
|
builder: (_) =>
|
||||||
|
ResetPasswordPage(userId: userId, oldPassword: oldPassword),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -254,7 +272,8 @@ class LoginPage extends ConsumerWidget {
|
|||||||
: 'Hide password',
|
: 'Hide password',
|
||||||
onPressed: state.isLoading
|
onPressed: state.isLoading
|
||||||
? null
|
? null
|
||||||
: () => ref
|
: () =>
|
||||||
|
ref
|
||||||
.read(
|
.read(
|
||||||
loginObscurePasswordProvider
|
loginObscurePasswordProvider
|
||||||
.notifier,
|
.notifier,
|
||||||
|
|||||||
@ -12,6 +12,7 @@ class LoginState {
|
|||||||
this.user,
|
this.user,
|
||||||
this.requiredAction,
|
this.requiredAction,
|
||||||
this.requiredUserId,
|
this.requiredUserId,
|
||||||
|
this.requiredOldPassword,
|
||||||
});
|
});
|
||||||
|
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
@ -20,6 +21,7 @@ class LoginState {
|
|||||||
final LoginUser? user;
|
final LoginUser? user;
|
||||||
final LoginRequiredAction? requiredAction;
|
final LoginRequiredAction? requiredAction;
|
||||||
final String? requiredUserId;
|
final String? requiredUserId;
|
||||||
|
final String? requiredOldPassword;
|
||||||
|
|
||||||
LoginState copyWith({
|
LoginState copyWith({
|
||||||
bool? isLoading,
|
bool? isLoading,
|
||||||
@ -28,6 +30,7 @@ class LoginState {
|
|||||||
LoginUser? user,
|
LoginUser? user,
|
||||||
LoginRequiredAction? requiredAction,
|
LoginRequiredAction? requiredAction,
|
||||||
String? requiredUserId,
|
String? requiredUserId,
|
||||||
|
String? requiredOldPassword,
|
||||||
bool clearError = false,
|
bool clearError = false,
|
||||||
bool clearSuccess = false,
|
bool clearSuccess = false,
|
||||||
bool clearUser = false,
|
bool clearUser = false,
|
||||||
@ -40,13 +43,20 @@ class LoginState {
|
|||||||
? null
|
? null
|
||||||
: successMessage ?? this.successMessage,
|
: successMessage ?? this.successMessage,
|
||||||
user: clearUser ? null : user ?? this.user,
|
user: clearUser ? null : user ?? this.user,
|
||||||
requiredAction: clearRequired ? null : requiredAction ?? this.requiredAction,
|
requiredAction: clearRequired
|
||||||
requiredUserId: clearRequired ? null : requiredUserId ?? this.requiredUserId,
|
? null
|
||||||
|
: requiredAction ?? this.requiredAction,
|
||||||
|
requiredUserId: clearRequired
|
||||||
|
? null
|
||||||
|
: requiredUserId ?? this.requiredUserId,
|
||||||
|
requiredOldPassword: clearRequired
|
||||||
|
? null
|
||||||
|
: requiredOldPassword ?? this.requiredOldPassword,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'LoginState(isLoading: $isLoading, errorMessage: $errorMessage, successMessage: $successMessage, user: $user, requiredAction: $requiredAction, requiredUserId: $requiredUserId)';
|
return 'LoginState(isLoading: $isLoading, errorMessage: $errorMessage, successMessage: $successMessage, user: $user, requiredAction: $requiredAction, requiredUserId: $requiredUserId, requiredOldPassword: $requiredOldPassword)';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -129,6 +129,7 @@ class LoginViewModel extends StateNotifier<LoginState> {
|
|||||||
isLoading: false,
|
isLoading: false,
|
||||||
requiredAction: LoginRequiredAction.passwordUpdateRequired,
|
requiredAction: LoginRequiredAction.passwordUpdateRequired,
|
||||||
requiredUserId: error.userId,
|
requiredUserId: error.userId,
|
||||||
|
requiredOldPassword: password,
|
||||||
clearError: true,
|
clearError: true,
|
||||||
clearSuccess: true,
|
clearSuccess: true,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -6,9 +6,14 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
class ResetPasswordPage extends ConsumerWidget {
|
class ResetPasswordPage extends ConsumerWidget {
|
||||||
const ResetPasswordPage({required this.userId, super.key});
|
const ResetPasswordPage({
|
||||||
|
required this.userId,
|
||||||
|
required this.oldPassword,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
final String userId;
|
final String userId;
|
||||||
|
final String oldPassword;
|
||||||
|
|
||||||
bool _isStrongPassword(String value) {
|
bool _isStrongPassword(String value) {
|
||||||
return value.length >= 8 &&
|
return value.length >= 8 &&
|
||||||
@ -52,7 +57,11 @@ class ResetPasswordPage extends ConsumerWidget {
|
|||||||
|
|
||||||
ref
|
ref
|
||||||
.read(resetPasswordViewModelProvider.notifier)
|
.read(resetPasswordViewModelProvider.notifier)
|
||||||
.resetPassword(userId: userId, password: password);
|
.resetPassword(
|
||||||
|
userId: userId,
|
||||||
|
password: password,
|
||||||
|
oldPassword: oldPassword,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -64,19 +73,13 @@ class ResetPasswordPage extends ConsumerWidget {
|
|||||||
final message = next.errorMessage;
|
final message = next.errorMessage;
|
||||||
if (message != null && message != previous?.errorMessage) {
|
if (message != null && message != previous?.errorMessage) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(content: Text(message), behavior: SnackBarBehavior.floating),
|
||||||
content: Text(message),
|
|
||||||
behavior: SnackBarBehavior.floating,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
final success = next.successMessage;
|
final success = next.successMessage;
|
||||||
if (success != null && success != previous?.successMessage) {
|
if (success != null && success != previous?.successMessage) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(content: Text(success), behavior: SnackBarBehavior.floating),
|
||||||
content: Text(success),
|
|
||||||
behavior: SnackBarBehavior.floating,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
@ -101,14 +104,18 @@ class ResetPasswordPage extends ConsumerWidget {
|
|||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
child: Center(
|
child: Center(
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
padding:
|
padding: const EdgeInsets.symmetric(
|
||||||
const EdgeInsets.symmetric(horizontal: 20, vertical: 24),
|
horizontal: 20,
|
||||||
|
vertical: 24,
|
||||||
|
),
|
||||||
child: ConstrainedBox(
|
child: ConstrainedBox(
|
||||||
constraints: const BoxConstraints(maxWidth: 440),
|
constraints: const BoxConstraints(maxWidth: 440),
|
||||||
child: Card(
|
child: Card(
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
color: colorScheme.surface.withOpacity(
|
color: colorScheme.surface.withOpacity(
|
||||||
Theme.of(context).brightness == Brightness.dark ? 0.75 : 0.92,
|
Theme.of(context).brightness == Brightness.dark
|
||||||
|
? 0.75
|
||||||
|
: 0.92,
|
||||||
),
|
),
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(28),
|
borderRadius: BorderRadius.circular(28),
|
||||||
@ -159,7 +166,9 @@ class ResetPasswordPage extends ConsumerWidget {
|
|||||||
style: Theme.of(context)
|
style: Theme.of(context)
|
||||||
.textTheme
|
.textTheme
|
||||||
.titleLarge
|
.titleLarge
|
||||||
?.copyWith(fontWeight: FontWeight.w800),
|
?.copyWith(
|
||||||
|
fontWeight: FontWeight.w800,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
'Your account requires a password change.',
|
'Your account requires a password change.',
|
||||||
@ -167,7 +176,8 @@ class ResetPasswordPage extends ConsumerWidget {
|
|||||||
.textTheme
|
.textTheme
|
||||||
.bodyMedium
|
.bodyMedium
|
||||||
?.copyWith(
|
?.copyWith(
|
||||||
color: colorScheme.onSurfaceVariant,
|
color:
|
||||||
|
colorScheme.onSurfaceVariant,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -182,8 +192,9 @@ class ResetPasswordPage extends ConsumerWidget {
|
|||||||
enabled: !state.isLoading,
|
enabled: !state.isLoading,
|
||||||
textInputAction: TextInputAction.next,
|
textInputAction: TextInputAction.next,
|
||||||
obscureText: obscure,
|
obscureText: obscure,
|
||||||
onFieldSubmitted: (_) =>
|
onFieldSubmitted: (_) => FocusScope.of(
|
||||||
FocusScope.of(context).requestFocus(confirmFocusNode),
|
context,
|
||||||
|
).requestFocus(confirmFocusNode),
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
final text = (value ?? '').trim();
|
final text = (value ?? '').trim();
|
||||||
if (text.isEmpty) {
|
if (text.isEmpty) {
|
||||||
@ -201,7 +212,8 @@ class ResetPasswordPage extends ConsumerWidget {
|
|||||||
filled: true,
|
filled: true,
|
||||||
fillColor: colorScheme.surfaceContainerHighest
|
fillColor: colorScheme.surfaceContainerHighest
|
||||||
.withOpacity(
|
.withOpacity(
|
||||||
Theme.of(context).brightness == Brightness.dark
|
Theme.of(context).brightness ==
|
||||||
|
Brightness.dark
|
||||||
? 0.55
|
? 0.55
|
||||||
: 0.9,
|
: 0.9,
|
||||||
),
|
),
|
||||||
@ -209,13 +221,16 @@ class ResetPasswordPage extends ConsumerWidget {
|
|||||||
borderRadius: BorderRadius.circular(18),
|
borderRadius: BorderRadius.circular(18),
|
||||||
),
|
),
|
||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
tooltip:
|
tooltip: obscure
|
||||||
obscure ? 'Show password' : 'Hide password',
|
? 'Show password'
|
||||||
|
: 'Hide password',
|
||||||
onPressed: state.isLoading
|
onPressed: state.isLoading
|
||||||
? null
|
? null
|
||||||
: () => ref
|
: () =>
|
||||||
|
ref
|
||||||
.read(
|
.read(
|
||||||
resetObscurePasswordProvider.notifier,
|
resetObscurePasswordProvider
|
||||||
|
.notifier,
|
||||||
)
|
)
|
||||||
.state =
|
.state =
|
||||||
!obscure,
|
!obscure,
|
||||||
@ -255,7 +270,8 @@ class ResetPasswordPage extends ConsumerWidget {
|
|||||||
filled: true,
|
filled: true,
|
||||||
fillColor: colorScheme.surfaceContainerHighest
|
fillColor: colorScheme.surfaceContainerHighest
|
||||||
.withOpacity(
|
.withOpacity(
|
||||||
Theme.of(context).brightness == Brightness.dark
|
Theme.of(context).brightness ==
|
||||||
|
Brightness.dark
|
||||||
? 0.55
|
? 0.55
|
||||||
: 0.9,
|
: 0.9,
|
||||||
),
|
),
|
||||||
@ -268,7 +284,8 @@ class ResetPasswordPage extends ConsumerWidget {
|
|||||||
: 'Hide password',
|
: 'Hide password',
|
||||||
onPressed: state.isLoading
|
onPressed: state.isLoading
|
||||||
? null
|
? null
|
||||||
: () => ref
|
: () =>
|
||||||
|
ref
|
||||||
.read(
|
.read(
|
||||||
resetObscureConfirmPasswordProvider
|
resetObscureConfirmPasswordProvider
|
||||||
.notifier,
|
.notifier,
|
||||||
@ -299,14 +316,22 @@ class ResetPasswordPage extends ConsumerWidget {
|
|||||||
? const SizedBox(
|
? const SizedBox(
|
||||||
height: 18,
|
height: 18,
|
||||||
width: 18,
|
width: 18,
|
||||||
child: CircularProgressIndicator(strokeWidth: 2),
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 2,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
: const Icon(Icons.check),
|
: const Icon(Icons.check),
|
||||||
label: Padding(
|
label: Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 12,
|
||||||
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
state.isLoading ? 'Updating...' : 'Reset password',
|
state.isLoading
|
||||||
style: const TextStyle(fontWeight: FontWeight.w600),
|
? 'Updating...'
|
||||||
|
: 'Reset password',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -314,7 +339,8 @@ class ResetPasswordPage extends ConsumerWidget {
|
|||||||
Text(
|
Text(
|
||||||
'Tip: use a unique password you don’t use elsewhere.',
|
'Tip: use a unique password you don’t use elsewhere.',
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
style: Theme.of(context).textTheme.bodySmall
|
||||||
|
?.copyWith(
|
||||||
color: colorScheme.onSurfaceVariant,
|
color: colorScheme.onSurfaceVariant,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -4,20 +4,23 @@ import 'package:e_receipt_mobile/presentation/reset_password/reset_password_stat
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
final resetPasswordViewModelProvider =
|
final resetPasswordViewModelProvider =
|
||||||
StateNotifierProvider.autoDispose<ResetPasswordViewModel, ResetPasswordState>(
|
StateNotifierProvider.autoDispose<
|
||||||
(ref) {
|
ResetPasswordViewModel,
|
||||||
|
ResetPasswordState
|
||||||
|
>((ref) {
|
||||||
return ResetPasswordViewModel(ref.watch(authRepositoryProvider));
|
return ResetPasswordViewModel(ref.watch(authRepositoryProvider));
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
class ResetPasswordViewModel extends StateNotifier<ResetPasswordState> {
|
class ResetPasswordViewModel extends StateNotifier<ResetPasswordState> {
|
||||||
ResetPasswordViewModel(this._authRepository) : super(const ResetPasswordState());
|
ResetPasswordViewModel(this._authRepository)
|
||||||
|
: super(const ResetPasswordState());
|
||||||
|
|
||||||
final AuthRepository _authRepository;
|
final AuthRepository _authRepository;
|
||||||
|
|
||||||
Future<void> resetPassword({
|
Future<void> resetPassword({
|
||||||
required String userId,
|
required String userId,
|
||||||
required String password,
|
required String password,
|
||||||
|
required String oldPassword,
|
||||||
}) async {
|
}) async {
|
||||||
if (userId.trim().isEmpty) {
|
if (userId.trim().isEmpty) {
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
@ -27,6 +30,14 @@ class ResetPasswordViewModel extends StateNotifier<ResetPasswordState> {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (oldPassword.isEmpty) {
|
||||||
|
state = state.copyWith(
|
||||||
|
isLoading: false,
|
||||||
|
errorMessage: 'Missing original login password',
|
||||||
|
clearSuccess: true,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
@ -35,7 +46,11 @@ class ResetPasswordViewModel extends StateNotifier<ResetPasswordState> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await _authRepository.resetPassword(userId: userId.trim(), password: password);
|
await _authRepository.resetPassword(
|
||||||
|
userId: userId.trim(),
|
||||||
|
password: password,
|
||||||
|
oldPassword: oldPassword,
|
||||||
|
);
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
successMessage: 'Password updated',
|
successMessage: 'Password updated',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user