forked from eatvio/eatvio_app
feat(auth): reset password
This commit is contained in:
@@ -2,7 +2,7 @@ import 'dart:developer';
|
||||
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/core/utils/toasts.dart';
|
||||
import 'package:eatvio_app/features/auth/presentation/bloc/auth_state.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:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:eatvio_app/features/auth/presentation/bloc/reset_password_cubit/reset_password_state.dart';
|
||||
import 'package:eatvio_app/features/auth/repositories/reset_password_repository.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class ResetPasswordCubit extends Cubit<ResetPasswordState> {
|
||||
final ResetPasswordRepository resetPasswordRepository;
|
||||
|
||||
ResetPasswordCubit({required this.resetPasswordRepository}) : super(const ResetPasswordState.empty());
|
||||
|
||||
trySendEmailCode(String email) async {
|
||||
emit(const ResetPasswordState.loadingSendEmailCode());
|
||||
try {
|
||||
if (await resetPasswordRepository.sendEmailCodeForPasswordChange(email)) {
|
||||
emit(const ResetPasswordState.codeSendSuccess());
|
||||
} else {
|
||||
emit(const ResetPasswordState.codeSendError());
|
||||
}
|
||||
} catch (e) {
|
||||
emit(const ResetPasswordState.codeSendError());
|
||||
}
|
||||
}
|
||||
|
||||
tryResetPassword(String email, String code, String password, String passwordConfirmation) async {
|
||||
emit(const ResetPasswordState.loadingResetPassword());
|
||||
try {
|
||||
if (await resetPasswordRepository.confirmPasswordChange(code, password, passwordConfirmation, email)) {
|
||||
emit(const ResetPasswordState.resetPasswordSuccess());
|
||||
} else {
|
||||
emit(const ResetPasswordState.resetPasswordError());
|
||||
}
|
||||
} catch (e) {
|
||||
emit(const ResetPasswordState.resetPasswordError());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'reset_password_state.freezed.dart';
|
||||
|
||||
@freezed
|
||||
abstract class ResetPasswordState with _$ResetPasswordState {
|
||||
const factory ResetPasswordState() = _ResetPasswordState;
|
||||
|
||||
const factory ResetPasswordState.empty() = ResetPasswordStateEmpty;
|
||||
|
||||
const factory ResetPasswordState.loadingSendEmailCode() = ResetPasswordStateLoadingSendEmailCode;
|
||||
|
||||
const factory ResetPasswordState.codeSendSuccess() = ResetPasswordStateCodeSendSuccess;
|
||||
|
||||
const factory ResetPasswordState.codeSendError() = ResetPasswordStateCodeSendError;
|
||||
|
||||
const factory ResetPasswordState.loadingResetPassword() = ResetPasswordStateLoadingResetPassword;
|
||||
|
||||
const factory ResetPasswordState.resetPasswordError() = ResetPasswordStateResetPasswordError;
|
||||
|
||||
const factory ResetPasswordState.resetPasswordSuccess() = ResetPasswordStateResetPassowrdSuccess;
|
||||
}
|
||||
Reference in New Issue
Block a user