feat(auth): align password policy and handle 429 responses

- map 429 Retry-After to a localized toast in AuthCubit
- enforce the 8-character minimum on registration v1 and add the hint
- surface errors.password in registration v2
- show password errors from 422 responses in the reset flow
- add ru/en localization strings and regenerate l10n
- add a regression test for the 429/Retry-After path
This commit is contained in:
2026-11-23 14:46:29 +03:00
parent 78192b742d
commit b0ffbd318a
17 changed files with 271 additions and 120 deletions

View File

@@ -7,6 +7,41 @@ class ResetPasswordRepository {
required this.resetPasswordService,
});
String? _lastError;
String? get lastError => _lastError;
void clearError() {
_lastError = null;
}
void _readError(dynamic data) {
_lastError = null;
if (data is! Map) {
return;
}
final errors = data['errors'];
if (errors is Map) {
final passwordErrors = errors['password'];
if (passwordErrors is List && passwordErrors.isNotEmpty) {
_lastError = passwordErrors.join('\n');
return;
}
for (final value in errors.values) {
if (value is List && value.isNotEmpty) {
_lastError = value.join('\n');
return;
}
}
}
final message = data['message'];
if (message is String) {
_lastError = message;
}
}
Future<bool> sendEmailCodeForPasswordChange(String email) async {
final response = await resetPasswordService.sendEmailCodeForPasswordChange(
data: {
@@ -15,8 +50,10 @@ class ResetPasswordRepository {
);
int statusCode = response.response.statusCode ?? 0;
if (statusCode >= 200 && statusCode < 300) {
_lastError = null;
return true;
} else {
_readError(response.response.data);
return false;
}
@@ -38,8 +75,10 @@ class ResetPasswordRepository {
);
int statusCode = response.response.statusCode ?? 0;
if (statusCode >= 200 && statusCode < 300) {
_lastError = null;
return true;
} else {
_readError(response.response.data);
return false;
}