Skip to content

High performance self-hosted photo and video management solution.

refactor: migrate to new changePassword endpoint (#31277)

shenlongd2928cecce2a
diff --git a/mobile/lib/providers/auth.provider.dart b/mobile/lib/providers/auth.provider.dart
index 2ed4cbcf00..23bfb2b71d 100644
--- a/mobile/lib/providers/auth.provider.dart
+++ b/mobile/lib/providers/auth.provider.dart
@@ -115,9 +115,9 @@ class AuthNotifier extends StateNotifier<AuthState> {
state = state.copyWith(profileImagePath: path);
}
- Future<bool> changePassword(String newPassword) async {
+ Future<bool> changePassword({required String currentPassword, required String newPassword}) async {
try {
- await _authService.changePassword(newPassword);
+ await _authService.changePassword(currentPassword: currentPassword, newPassword: newPassword);
return true;
} catch (_) {
return false;
diff --git a/mobile/lib/repositories/auth_api.repository.dart b/mobile/lib/repositories/auth_api.repository.dart
index 447826b9aa..66393a19ce 100644
--- a/mobile/lib/repositories/auth_api.repository.dart
+++ b/mobile/lib/repositories/auth_api.repository.dart
@@ -12,8 +12,10 @@ class AuthApiRepository extends ApiRepository {
AuthApiRepository(this._apiService);
- Future<void> changePassword(String newPassword) async {
- await _apiService.usersApi.updateMyUser(UserUpdateMeDto(password: Optional.present(newPassword)));
+ Future<void> changePassword({required String currentPassword, required String newPassword}) async {
+ await _apiService.authenticationApi.changePassword(
+ ChangePasswordDto(password: currentPassword, newPassword: newPassword),
+ );
}
Future<LoginResponse> login(String email, String password) async {
diff --git a/mobile/lib/services/auth.service.dart b/mobile/lib/services/auth.service.dart
index 0e02c7b1b9..f22777d522 100644
--- a/mobile/lib/services/auth.service.dart
+++ b/mobile/lib/services/auth.service.dart
@@ -129,9 +129,9 @@ class AuthService {
]);
}
- Future<void> changePassword(String newPassword) {
+ Future<void> changePassword({required String currentPassword, required String newPassword}) async {
try {
- return _authApiRepository.changePassword(newPassword);
+ await _authApiRepository.changePassword(currentPassword: currentPassword, newPassword: newPassword);
} catch (error, stackTrace) {
_log.severe("Error changing password", error, stackTrace);
rethrow;
diff --git a/mobile/lib/widgets/forms/change_password_form.dart b/mobile/lib/widgets/forms/change_password_form.dart
index 65a4c6f88e..d106f68d80 100644
--- a/mobile/lib/widgets/forms/change_password_form.dart
+++ b/mobile/lib/widgets/forms/change_password_form.dart
@@ -14,6 +14,7 @@ class ChangePasswordForm extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
+ final currentPasswordController = useTextEditingController.fromValue(TextEditingValue.empty);
final passwordController = useTextEditingController.fromValue(TextEditingValue.empty);
final confirmPasswordController = useTextEditingController.fromValue(TextEditingValue.empty);
final authState = ref.watch(authProvider);
@@ -43,7 +44,11 @@ class ChangePasswordForm extends HookConsumerWidget {
key: formKey,
child: Column(
children: [
- PasswordInput(controller: passwordController),
+ Padding(
+ padding: const EdgeInsets.only(bottom: 16.0),
+ child: PasswordInput(controller: currentPasswordController, label: context.t.password),
+ ),
+ PasswordInput(controller: passwordController, label: context.t.change_password_form_new_password),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: ConfirmPasswordInput(
@@ -57,7 +62,10 @@ class ChangePasswordForm extends HookConsumerWidget {
if (formKey.currentState!.validate()) {
final isSuccess = await ref
.read(authProvider.notifier)
- .changePassword(passwordController.value.text);
+ .changePassword(
+ currentPassword: currentPasswordController.text,
+ newPassword: passwordController.text,
+ );
if (!isSuccess && context.mounted) {
ImmichToast.show(
@@ -107,19 +115,16 @@ class ChangePasswordForm extends HookConsumerWidget {
class PasswordInput extends StatelessWidget {
final TextEditingController controller;
+ final String label;
- const PasswordInput({super.key, required this.controller});
+ const PasswordInput({super.key, required this.controller, required this.label});
@override
Widget build(BuildContext context) {
return TextFormField(
obscureText: true,
controller: controller,
- decoration: InputDecoration(
- labelText: context.t.change_password_form_new_password,
- border: const OutlineInputBorder(),
- hintText: context.t.change_password_form_new_password,
- ),
+ decoration: InputDecoration(labelText: label, border: const OutlineInputBorder(), hintText: label),
);
}
}
diff --git a/mobile/lib/widgets/forms/login/login_form.dart b/mobile/lib/widgets/forms/login/login_form.dart
index aa9750a2a5..ae5b5285ae 100644
--- a/mobile/lib/widgets/forms/login/login_form.dart
+++ b/mobile/lib/widgets/forms/login/login_form.dart
@@ -264,6 +264,7 @@ class LoginForm extends HookConsumerWidget {
if (result.shouldChangePassword && !result.isAdmin) {
unawaited(context.pushRoute(const ChangePasswordRoute()));
+ passwordController.clear();
} else {
await ref.read(galleryPermissionNotifier.notifier).requestGalleryPermission();
if (isSyncRemoteDeletionsMode()) {