diff --git a/pkg/api/users.go b/pkg/api/users.go index f8fa92d2..973c6aee 100644 --- a/pkg/api/users.go +++ b/pkg/api/users.go @@ -277,7 +277,7 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.WebContext) (any, *errs.Erro return nil, errs.ErrNotPermittedToPerformThisAction } - if !a.users.IsPasswordEqualsUserPassword(userUpdateReq.OldPassword, user) { + if user.Password != "" && !a.users.IsPasswordEqualsUserPassword(userUpdateReq.OldPassword, user) { return nil, errs.ErrUserPasswordWrong } diff --git a/pkg/models/user.go b/pkg/models/user.go index d76b3abc..54362e07 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -225,6 +225,7 @@ type UserProfileUpdateResponse struct { // UserProfileResponse represents a view-object of user profile type UserProfileResponse struct { *UserBasicInfo + NoPassword bool `json:"noPassword,omitempty"` LastLoginAt int64 `json:"lastLoginAt"` } @@ -313,6 +314,7 @@ func (u *User) ToUserBasicInfo(avatarProvider core.UserAvatarProviderType, avata func (u *User) ToUserProfileResponse(basicInfo *UserBasicInfo) *UserProfileResponse { return &UserProfileResponse{ UserBasicInfo: basicInfo, + NoPassword: u.Password == "", LastLoginAt: u.LastLoginUnixTime, } } diff --git a/src/models/user.ts b/src/models/user.ts index 2c2eecc2..21a3600e 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -233,6 +233,7 @@ export interface UserProfileUpdateResponse { } export interface UserProfileResponse extends UserBasicInfo { + readonly noPassword?: boolean; readonly lastLoginAt: number; } diff --git a/src/views/desktop/user/settings/tabs/UserSecuritySettingTab.vue b/src/views/desktop/user/settings/tabs/UserSecuritySettingTab.vue index 1bee2445..b22455a5 100644 --- a/src/views/desktop/user/settings/tabs/UserSecuritySettingTab.vue +++ b/src/views/desktop/user/settings/tabs/UserSecuritySettingTab.vue @@ -54,7 +54,7 @@ - + {{ tt('Save Changes') }} @@ -213,9 +213,7 @@ const sessions = computed(() => { }); const inputProblemMessage = computed(() => { - if (!currentPassword.value) { - return 'Current password cannot be blank'; - } else if (!newPassword.value && !confirmPassword.value) { + if (!newPassword.value && !confirmPassword.value) { return 'Nothing has been modified'; } else if (!newPassword.value && confirmPassword.value) { return 'New password cannot be blank'; diff --git a/src/views/mobile/users/UserProfilePage.vue b/src/views/mobile/users/UserProfilePage.vue index 3a1f147d..c88d48a2 100644 --- a/src/views/mobile/users/UserProfilePage.vue +++ b/src/views/mobile/users/UserProfilePage.vue @@ -5,7 +5,7 @@ - + @@ -551,7 +551,7 @@ :cancel-disabled="saving" v-model:show="showInputPasswordSheet" v-model="currentPassword" - @password:confirm="save()"> + @password:confirm="save(true)"> @@ -639,6 +639,7 @@ const userStore = useUserStore(); const accountsStore = useAccountsStore(); const currentPassword = ref(''); +const currentNoPassword = ref(false); const loadingError = ref(null); const showInputPasswordSheet = ref(false); const showAccountSheet = ref(false); @@ -690,6 +691,7 @@ function init(): void { Promise.all(promises).then(responses => { const profile = responses[1] as UserProfileResponse; setCurrentUserProfile(profile); + currentNoPassword.value = !!profile.noPassword; loading.value = false; }).catch(error => { if (error.processed) { @@ -701,7 +703,7 @@ function init(): void { }); } -function save(): void { +function save(confirm?: boolean): void { const router = props.f7router; showInputPasswordSheet.value = false; @@ -713,7 +715,7 @@ function save(): void { return; } - if (newProfile.value.password && !currentPassword.value) { + if (newProfile.value.password && !confirm) { showInputPasswordSheet.value = true; return; }