-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Password reset feature #2432
base: staging
Are you sure you want to change the base?
Password reset feature #2432
Changes from all commits
ac93526
c163529
17e00fe
7211a31
c79031f
7e2864c
e9cbd2b
8c52ed7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import '../../repository/auth_repository.dart'; | ||
import 'forgot_password_event.dart'; | ||
import 'forgot_password_state.dart'; | ||
|
||
|
||
class PasswordResetBloc extends Bloc<PasswordResetEvent, PasswordResetState> { | ||
final AuthRepository authRepository; | ||
|
||
PasswordResetBloc({required this.authRepository}) : super(PasswordResetInitial()) { | ||
on<RequestPasswordReset>((event, emit) async { | ||
try { | ||
emit(PasswordResetLoading(email: event.email)); | ||
await authRepository.requestPasswordReset(event.email); | ||
emit(PasswordResetSuccess(message: '')); | ||
} catch (e) { | ||
emit(PasswordResetError(message: e.toString())); | ||
} | ||
}); | ||
|
||
on<UpdatePassword>((event, emit) async { | ||
emit(PasswordResetLoading()); | ||
try { | ||
final message = await authRepository.updatePassword( | ||
confirmPassword: event.confirmPassword, | ||
password: event.password, | ||
token: event.token, | ||
); | ||
emit(PasswordResetSuccess(message: message)); | ||
} catch (error) { | ||
emit(PasswordResetError(message: 'Failed to update password. \nPlease re-check the code you entered')); | ||
} | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,30 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import 'package:equatable/equatable.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
abstract class PasswordResetEvent extends Equatable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
List<Object?> get props => []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class RequestPasswordReset extends PasswordResetEvent { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
final String email; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
RequestPasswordReset(this.email); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
List<Object?> get props => [email]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class UpdatePassword extends PasswordResetEvent { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
final String confirmPassword; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
final String password; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
final String token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
UpdatePassword({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
required this.confirmPassword, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
required this.password, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
required this.token, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
List<Object?> get props => [confirmPassword, password, token]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+17
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add password validation in UpdatePassword event. The password and confirmPassword fields should be validated for matching values and minimum security requirements. class UpdatePassword extends PasswordResetEvent {
final String confirmPassword;
final String password;
final String token;
UpdatePassword({
required this.confirmPassword,
required this.password,
required this.token,
- });
+ }) {
+ assert(password == confirmPassword, 'Passwords do not match');
+ assert(password.length >= 8, 'Password must be at least 8 characters');
+ assert(token.isNotEmpty, 'Token cannot be empty');
+ } 📝 Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'package:equatable/equatable.dart'; | ||
|
||
abstract class PasswordResetState extends Equatable { | ||
final String? email; | ||
const PasswordResetState({this.email}); | ||
|
||
@override | ||
List<Object?> get props => [email]; | ||
} | ||
|
||
class PasswordResetInitial extends PasswordResetState { | ||
const PasswordResetInitial() : super(); | ||
} | ||
|
||
class PasswordResetLoading extends PasswordResetState { | ||
const PasswordResetLoading({String? email}) : super(email: email); // Optional email | ||
} | ||
|
||
class PasswordResetSuccess extends PasswordResetState { | ||
final String message; | ||
|
||
const PasswordResetSuccess({String? email, required this.message}) : super(email: email); | ||
|
||
@override | ||
List<Object?> get props => [email, message]; | ||
} | ||
|
||
class PasswordResetError extends PasswordResetState { | ||
final String message; | ||
|
||
const PasswordResetError({String? email, required this.message}) | ||
: super(email: email); // Optional email | ||
|
||
@override | ||
List<Object?> get props => [email, message]; // Nullable email | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Enhance error handling in RequestPasswordReset event handler.
The current implementation catches all errors generically. Consider handling specific error types and preserving the email in error state.