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

@@ -1,5 +1,6 @@
import 'dart:developer';
import 'package:dio/dio.dart';
import 'package:eatvio_app/core/firebase_api.dart';
import 'package:eatvio_app/core/prefs.dart';
import 'package:eatvio_app/core/prefs_keys.dart';
@@ -9,6 +10,7 @@ import 'package:eatvio_app/core/utils/toasts.dart';
import 'package:eatvio_app/features/auth/presentation/bloc/auth_cubit/auth_state.dart';
import 'package:eatvio_app/features/auth/repositories/auth_repository.dart';
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:eatvio_app/core/error_reporting/report_from.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
@@ -42,6 +44,25 @@ class AuthCubit extends Cubit<AuthState> {
} catch (e, st) {
await reportFrom(e, st, this);
log(e.toString());
if (e is DioException && e.response?.statusCode == 429) {
final response = e.response;
final data = response?.data;
final error = data is Map ? data['error'] : null;
final retryAfter =
response?.headers.value('retry-after') ??
(error is Map ? error['retry_after']?.toString() : null);
final serverMessage = error is Map && error['message'] is String
? error['message'] as String
: data is Map && data['message'] is String
? data['message'] as String
: null;
final message = retryAfter != null && retryAfter.isNotEmpty
? S.current.too_many_login_attempts(int.tryParse(retryAfter) ?? 0)
: serverMessage ?? S.current.too_many_login_attempts_no_retry;
showErrorToast(message);
emit(AuthState.error(errorMessage: message));
return false;
}
showErrorToast('Неверный адрес электронной почты или пароль');
emit(AuthState.error(errorMessage: '$e'));
return false;

View File

@@ -8,7 +8,10 @@ class ResetPasswordCubit extends Cubit<ResetPasswordState> {
ResetPasswordCubit({required this.resetPasswordRepository}) : super(const ResetPasswordState.empty());
String? get errorMessage => resetPasswordRepository.lastError;
Future<void> trySendEmailCode(String email) async {
resetPasswordRepository.clearError();
emit(const ResetPasswordState.loadingSendEmailCode());
try {
if (await resetPasswordRepository.sendEmailCodeForPasswordChange(email)) {
@@ -23,6 +26,7 @@ class ResetPasswordCubit extends Cubit<ResetPasswordState> {
}
Future<void> tryResetPassword(String email, String code, String password, String passwordConfirmation) async {
resetPasswordRepository.clearError();
emit(const ResetPasswordState.loadingResetPassword());
try {
if (await resetPasswordRepository.confirmPasswordChange(code, password, passwordConfirmation, email)) {

View File

@@ -108,10 +108,10 @@ class _ForgetPasswordScreenState extends State<ForgetPasswordScreen> {
showSuccessToast('Код на почту успешно отправлен');
}
if (state is ResetPasswordStateCodeSendError) {
showErrorToast('Ошибка отправки кода. Проверьте правильность ввёдной почты');
showErrorToast(context.read<ResetPasswordCubit>().errorMessage ?? 'Ошибка отправки кода. Проверьте правильность ввёдной почты');
}
if (state is ResetPasswordStateResetPasswordError) {
showErrorToast('Ошибка смены пароля. Проверьте правильность ввёднного кода и совпадение пароля');
showErrorToast(context.read<ResetPasswordCubit>().errorMessage ?? 'Ошибка смены пароля. Проверьте правильность ввёднного кода и совпадение пароля');
}
if (state is ResetPasswordStateResetPassowrdSuccess) {
GoRouter.of(context).pop();