feat:添加邮箱重置密码功能
This commit is contained in:
@@ -282,7 +282,8 @@ const local: any = {
|
||||
passwordLength: 'Password must be at least 6 characters',
|
||||
resetSuccess: 'Password reset successfully',
|
||||
resetFailed: 'Password reset failed, please try again',
|
||||
byPassword:'reset by current Password'
|
||||
byPassword:'Reset by current Password',
|
||||
byEmail: 'Reset by email verification code',
|
||||
},
|
||||
bindWeChat: {
|
||||
title: 'Bind WeChat'
|
||||
|
||||
@@ -198,7 +198,14 @@ export function resetPassword(data: { oldPassword: string; newPassword: string }
|
||||
params: data
|
||||
});
|
||||
}
|
||||
|
||||
/** Reset password by email */
|
||||
export function resetPasswordByEmail(data: { email: string; code: string; password: string }) {
|
||||
return request({
|
||||
url: '/u/user/profile/forgotPwd',
|
||||
method: 'put',
|
||||
params: data
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
1
src/typings/auto-imports.d.ts
vendored
1
src/typings/auto-imports.d.ts
vendored
@@ -197,6 +197,7 @@ declare global {
|
||||
const refWithControl: typeof import('@vueuse/core')['refWithControl']
|
||||
const removeEmptyChildren: typeof import('../utils/menu')['removeEmptyChildren']
|
||||
const resetPassword: typeof import('../service/api/auth')['resetPassword']
|
||||
const resetPasswordByEmail: typeof import('../service/api/auth')['resetPasswordByEmail']
|
||||
const resolveComponent: typeof import('vue')['resolveComponent']
|
||||
const resolveRef: typeof import('@vueuse/core')['resolveRef']
|
||||
const resolveUnref: typeof import('@vueuse/core')['resolveUnref']
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
Radio,
|
||||
} from 'ant-design-vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { resetPassword } from '@/service/api/auth';
|
||||
import { resetPassword, resetPasswordByEmail } from '@/service/api/auth';
|
||||
|
||||
const AInputPassword = Input.Password;
|
||||
const ARadioGroup = Radio.Group;
|
||||
@@ -47,10 +47,28 @@ const formModel = reactive<FormModel>({
|
||||
const formRules = computed<Record<string, Rule | Rule[]>>(() => {
|
||||
const { createConfirmPwdRule } = useFormRules();
|
||||
|
||||
// 密码验证规则
|
||||
const passwordValidateRule: Rule = {
|
||||
validator: (_rule: Rule, value: string) => {
|
||||
if (!value) {
|
||||
return Promise.reject(t('page.login.register.passwordRequired'));
|
||||
}
|
||||
// 长度验证:6-20位
|
||||
if (value.length < 6 || value.length > 20) {
|
||||
return Promise.reject(t('page.login.register.passwordLength'));
|
||||
}
|
||||
// 格式验证:必须包含字母和数字
|
||||
if (!/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,20}$/.test(value)) {
|
||||
return Promise.reject(t('page.login.register.passwordFormat'));
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
};
|
||||
|
||||
const baseRules = {
|
||||
password: [
|
||||
{ required: true, message: t('page.login.register.passwordRequired') },
|
||||
{ min: 6, message: t('page.login.resetPwd.passwordLength') }
|
||||
passwordValidateRule
|
||||
],
|
||||
confirmPassword: createConfirmPwdRule(formModel.password)
|
||||
};
|
||||
@@ -107,7 +125,12 @@ async function handleSubmit() {
|
||||
newPassword: formModel.password
|
||||
});
|
||||
} else {
|
||||
// TODO: 通过邮箱验证码重置的接口
|
||||
// 通过邮箱验证码重置
|
||||
await resetPasswordByEmail({
|
||||
email: formModel.email,
|
||||
code: formModel.code,
|
||||
password: formModel.password
|
||||
});
|
||||
}
|
||||
|
||||
window.$message?.success(t('page.login.resetPwd.resetSuccess'));
|
||||
@@ -137,7 +160,7 @@ const handleBack = () => {
|
||||
|
||||
<a-radio-group v-model:value="resetType" class="mb-24px">
|
||||
<a-radio value="password">{{ t('page.login.resetPwd.byPassword') }}</a-radio>
|
||||
<!-- <a-radio value="email">{{ t('page.login.resetPwd.byEmail') }}</a-radio>-->
|
||||
<a-radio value="email">{{ t('page.login.resetPwd.byEmail') }}</a-radio>
|
||||
</a-radio-group>
|
||||
|
||||
<a-form
|
||||
|
||||
Reference in New Issue
Block a user