mirror of
https://github.com/certd/certd.git
synced 2026-05-15 12:37:30 +08:00
chore: 支持设置初始化密码
This commit is contained in:
@@ -78,8 +78,13 @@ export default {
|
||||
passkeyRegisterFailed: "Passkey registration failed",
|
||||
title: "Change Password",
|
||||
weakPasswordWarning: "For your account security, please change your password immediately",
|
||||
initPasswordWarning: "This account does not have a login password yet. Please set one first",
|
||||
initPasswordTitle: "Set Password",
|
||||
changeNow: "Change Now",
|
||||
setNow: "Set Now",
|
||||
notNow: "Not Now",
|
||||
successMessage: "Changed successfully",
|
||||
initPasswordSuccessMessage: "Set successfully",
|
||||
oldPassword: "Old Password",
|
||||
oldPasswordRequired: "Please enter the old password",
|
||||
newPassword: "New Password",
|
||||
|
||||
@@ -79,8 +79,13 @@ export default {
|
||||
|
||||
title: "修改密码",
|
||||
weakPasswordWarning: "为了您的账户安全,请立即修改密码",
|
||||
initPasswordWarning: "当前账号还未设置登录密码,请先设置密码",
|
||||
initPasswordTitle: "设置密码",
|
||||
changeNow: "立即修改",
|
||||
setNow: "立即设置",
|
||||
notNow: "暂不设置",
|
||||
successMessage: "修改成功",
|
||||
initPasswordSuccessMessage: "设置成功",
|
||||
oldPassword: "旧密码",
|
||||
oldPasswordRequired: "请输入旧密码",
|
||||
newPassword: "新密码",
|
||||
|
||||
@@ -38,6 +38,7 @@ export interface UserInfoRes {
|
||||
avatar?: string;
|
||||
roleIds: number[];
|
||||
isWeak?: boolean;
|
||||
needInitPassword?: boolean;
|
||||
validTime?: number;
|
||||
status?: number;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,14 @@ export async function changePassword(form: any) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function initPassword(form: any) {
|
||||
return await request({
|
||||
url: "/mine/initPassword",
|
||||
method: "POST",
|
||||
data: form,
|
||||
});
|
||||
}
|
||||
|
||||
export async function UpdateProfile(form: any) {
|
||||
return await request({
|
||||
url: "/mine/updateProfile",
|
||||
|
||||
@@ -9,7 +9,7 @@ import { ref } from "vue";
|
||||
import { useI18n } from "/src/locales";
|
||||
|
||||
const { t } = useI18n();
|
||||
import { CrudOptions, useColumns, useFormWrapper } from "@fast-crud/fast-crud";
|
||||
import { compute, CrudOptions, useColumns, useFormWrapper } from "@fast-crud/fast-crud";
|
||||
import * as api from "/@/views/certd/mine/api";
|
||||
import { notification } from "ant-design-vue";
|
||||
import { useUserStore } from "/@/store/user";
|
||||
@@ -20,6 +20,11 @@ defineProps<{
|
||||
|
||||
let passwordFormRef = ref();
|
||||
|
||||
type OpenOptions = {
|
||||
password?: string;
|
||||
init?: boolean;
|
||||
};
|
||||
|
||||
const validatePass1 = async (rule: any, value: any) => {
|
||||
if (value === "") {
|
||||
throw new Error(t("authentication.enterPassword"));
|
||||
@@ -53,19 +58,33 @@ const passwordFormOptions: CrudOptions = {
|
||||
width: "500px",
|
||||
},
|
||||
async doSubmit({ form }) {
|
||||
await api.changePassword(form);
|
||||
if (form.init) {
|
||||
await api.initPassword(form);
|
||||
} else {
|
||||
await api.changePassword(form);
|
||||
}
|
||||
//重新加载用户信息
|
||||
await userStore.loadUserInfo();
|
||||
},
|
||||
async afterSubmit() {
|
||||
notification.success({ message: t("authentication.successMessage") });
|
||||
const formData = passwordFormRef.value?.getFormData?.();
|
||||
const message = formData?.init ? t("authentication.initPasswordSuccessMessage") : t("authentication.successMessage");
|
||||
notification.success({ message });
|
||||
},
|
||||
},
|
||||
columns: {
|
||||
init: {
|
||||
title: "init",
|
||||
type: "text",
|
||||
form: {
|
||||
show: false,
|
||||
},
|
||||
},
|
||||
password: {
|
||||
title: t("authentication.oldPassword"),
|
||||
type: "password",
|
||||
form: {
|
||||
show: compute(({ form }) => form.init !== true),
|
||||
rules: [{ required: true, message: t("authentication.oldPasswordRequired") }],
|
||||
},
|
||||
},
|
||||
@@ -97,12 +116,16 @@ const passwordFormOptions: CrudOptions = {
|
||||
},
|
||||
};
|
||||
|
||||
async function open(opts: { password: "" }) {
|
||||
async function open(opts: OpenOptions = {}) {
|
||||
const formOptions = buildFormOptions(passwordFormOptions);
|
||||
formOptions.newInstance = true; //新实例打开
|
||||
if (opts.init) {
|
||||
formOptions.wrapper.title = t("authentication.initPasswordTitle");
|
||||
}
|
||||
passwordFormRef.value = await openDialog(formOptions);
|
||||
passwordFormRef.value.setFormData({
|
||||
password: opts.password,
|
||||
init: opts.init === true,
|
||||
password: opts.password || "",
|
||||
});
|
||||
console.log(passwordFormRef.value);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="action-buttons gap-2">
|
||||
<change-password-button :show-button="true" />
|
||||
<change-password-button ref="changePasswordButtonRef" :show-button="true" />
|
||||
|
||||
<a-button type="primary" class="action-btn" @click="goSecuritySetting">
|
||||
{{ t("authentication.securitySettingTip") }}
|
||||
@@ -387,6 +387,7 @@ const checkPasskeySupport = () => {
|
||||
}
|
||||
};
|
||||
const userStore = useUserStore();
|
||||
const changePasswordButtonRef = ref();
|
||||
const userAvatar = computed(() => {
|
||||
if (isEmpty(userInfo.value.avatar)) {
|
||||
return "";
|
||||
@@ -400,6 +401,21 @@ const userAvatar = computed(() => {
|
||||
|
||||
onMounted(async () => {
|
||||
await getUserInfo();
|
||||
userStore.setUserInfo(userInfo.value);
|
||||
if (userInfo.value.needInitPassword === true) {
|
||||
Modal.confirm({
|
||||
title: t("authentication.initPasswordTitle"),
|
||||
content: t("authentication.initPasswordWarning"),
|
||||
okText: t("authentication.setNow"),
|
||||
cancelText: t("authentication.notNow"),
|
||||
closable: true,
|
||||
onOk: () => {
|
||||
changePasswordButtonRef.value.open({
|
||||
init: true,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
await loadContactCapability();
|
||||
await loadOauthBounds();
|
||||
await loadOauthProviders();
|
||||
|
||||
Reference in New Issue
Block a user