From f7b64e0a14322637dba2048261f8836e9aa0fc79 Mon Sep 17 00:00:00 2001 From: KUN1007 Date: Thu, 12 Oct 2023 18:05:31 +0800 Subject: [PATCH] feat: change password --- src/api/user/index.ts | 13 ++- src/api/user/types/user.ts | 9 ++ .../setting-panel/components/PageWidth.vue | 3 + src/store/modules/kungalgamer.ts | 16 ++++ src/views/kungalgamer/components/Email.vue | 0 src/views/kungalgamer/content/Password.vue | 84 +++++++++++++++---- src/views/kungalgamer/utils/check.ts | 58 +++++++++++-- 7 files changed, 157 insertions(+), 26 deletions(-) delete mode 100644 src/views/kungalgamer/components/Email.vue diff --git a/src/api/user/index.ts b/src/api/user/index.ts index ce62834b..7fe2ff5e 100644 --- a/src/api/user/index.ts +++ b/src/api/user/index.ts @@ -53,7 +53,18 @@ export async function getUserResetEmailCodeApi( export async function updateUserEmailApi( request: User.UserUpdateEmailRequestData ): Promise { - const url = `/user/:uid/email` + const url = `/user/${request.uid}/email` + + const response = fetchPut(url, request) + + return response +} + +// 更新密码 +export async function updateUserPasswordApi( + request: User.UserUpdatePasswordRequestData +): Promise { + const url = `/user/${request.uid}/password` const response = fetchPut(url, request) diff --git a/src/api/user/types/user.ts b/src/api/user/types/user.ts index 4ca0ce92..310a1188 100644 --- a/src/api/user/types/user.ts +++ b/src/api/user/types/user.ts @@ -30,6 +30,13 @@ export interface UserUpdateEmailRequestData { code: string } +// 用户更新密码 +export interface UserUpdatePasswordRequestData { + uid: number + oldPassword: string + newPassword: string +} + export type UserInfoResponseData = KUNGalgameResponseData export type UserUpdateBioResponseData = KUNGalgameResponseData<{}> @@ -41,3 +48,5 @@ export type UserGetUserEmailResponseData = KUNGalgameResponseData<{ export type UserGetEmailRestCodeResponseData = KUNGalgameResponseData<{}> export type UserUpdateEmailResponseData = KUNGalgameResponseData<{}> + +export type UserUpdatePasswordResponseData = KUNGalgameResponseData<{}> diff --git a/src/components/setting-panel/components/PageWidth.vue b/src/components/setting-panel/components/PageWidth.vue index 7ab6f61c..2678a416 100644 --- a/src/components/setting-panel/components/PageWidth.vue +++ b/src/components/setting-panel/components/PageWidth.vue @@ -108,5 +108,8 @@ onActivated(() => { .disabled { cursor: not-allowed; color: var(--kungalgame-font-color-0); + input { + cursor: not-allowed; + } } diff --git a/src/store/modules/kungalgamer.ts b/src/store/modules/kungalgamer.ts index 8f275482..fdfaa7f3 100644 --- a/src/store/modules/kungalgamer.ts +++ b/src/store/modules/kungalgamer.ts @@ -24,6 +24,8 @@ import type { UserGetEmailRestCodeResponseData, UserUpdateEmailRequestData, UserUpdateEmailResponseData, + UserUpdatePasswordRequestData, + UserUpdatePasswordResponseData, } from '@/api' import { @@ -32,6 +34,7 @@ import { getUserEmailApi, getUserResetEmailCodeApi, updateUserEmailApi, + updateUserPasswordApi, } from '@/api' // kungalgame store 类型 @@ -161,5 +164,18 @@ export const useKUNGalgameUserStore = defineStore({ } return updateUserEmailApi(requestData) }, + + // 更新密码 + async updatePassword( + oldPassword: string, + newPassword: string + ): Promise { + const requestData: UserUpdatePasswordRequestData = { + uid: this.uid, + oldPassword: oldPassword, + newPassword: newPassword, + } + return updateUserPasswordApi(requestData) + }, }, }) diff --git a/src/views/kungalgamer/components/Email.vue b/src/views/kungalgamer/components/Email.vue deleted file mode 100644 index e69de29b..00000000 diff --git a/src/views/kungalgamer/content/Password.vue b/src/views/kungalgamer/content/Password.vue index 03259a67..2704af3b 100644 --- a/src/views/kungalgamer/content/Password.vue +++ b/src/views/kungalgamer/content/Password.vue @@ -1,9 +1,13 @@