| | |
| | | saving: false, |
| | | passwordDialogVisible: false, |
| | | passwordSaving: false, |
| | | mfaDialogVisible: false, |
| | | mfaDialogMode: "enable", |
| | | mfaSetupLoading: false, |
| | | mfaSubmitting: false, |
| | | form: { |
| | | id: "", |
| | | roleName: "", |
| | | username: "", |
| | | mobile: "", |
| | | password: "", |
| | | createTime$: "" |
| | | createTime$: "", |
| | | mfaAllow: 0, |
| | | mfaAllow$: "否", |
| | | mfaEnabled: 0, |
| | | mfaEnabled$: "否", |
| | | mfaBoundTime$: "", |
| | | mfaMaskedSecret: "" |
| | | }, |
| | | passwordForm: { |
| | | oldPassword: "", |
| | | password: "", |
| | | rePassword: "" |
| | | }, |
| | | mfaForm: { |
| | | currentPassword: "", |
| | | code: "" |
| | | }, |
| | | mfaSetup: { |
| | | secret: "", |
| | | qrCode: "", |
| | | otpAuth: "" |
| | | }, |
| | | rules: { |
| | | username: [ |
| | |
| | | }, |
| | | passwordRules: { |
| | | oldPassword: [ |
| | | { required: true, message: "请输入当前密码", trigger: "blur" }, |
| | | { |
| | | validator: function (rule, value, callback) { |
| | | if (!value) { |
| | | callback(new Error("请输入当前密码")); |
| | | return; |
| | | } |
| | | if (!this.form.password) { |
| | | callback(new Error("未读取到当前用户密码")); |
| | | return; |
| | | } |
| | | if (hex_md5(value) !== this.form.password) { |
| | | callback(new Error("密码不匹配")); |
| | | return; |
| | | } |
| | | callback(); |
| | | }.bind(this), |
| | | trigger: "blur" |
| | | } |
| | | { required: true, message: "请输入当前密码", trigger: "blur" } |
| | | ], |
| | | password: [ |
| | | { required: true, message: "请输入新密码", trigger: "blur" }, |
| | |
| | | callback(new Error("不能少于4个字符")); |
| | | return; |
| | | } |
| | | if (this.form.password && hex_md5(value) === this.form.password) { |
| | | if (value === this.passwordForm.oldPassword) { |
| | | callback(new Error("与旧密码不能相同")); |
| | | return; |
| | | } |
| | |
| | | } |
| | | callback(); |
| | | }.bind(this), |
| | | trigger: "blur" |
| | | } |
| | | ] |
| | | }, |
| | | mfaRules: { |
| | | currentPassword: [ |
| | | { required: true, message: "请输入当前密码", trigger: "blur" } |
| | | ], |
| | | code: [ |
| | | { required: true, message: "请输入6位验证码", trigger: "blur" }, |
| | | { |
| | | validator: function (rule, value, callback) { |
| | | if (!/^\d{6}$/.test(String(value || "").trim())) { |
| | | callback(new Error("请输入6位数字验证码")); |
| | | return; |
| | | } |
| | | callback(); |
| | | }, |
| | | trigger: "blur" |
| | | } |
| | | ] |
| | |
| | | var vm = this; |
| | | vm.passwordSaving = true; |
| | | $.ajax({ |
| | | url: baseUrl + "/user/update/auth", |
| | | url: baseUrl + "/user/password/update/auth", |
| | | headers: { token: localStorage.getItem("token") }, |
| | | data: { |
| | | id: vm.form.id, |
| | | oldPassword: hex_md5(vm.passwordForm.oldPassword), |
| | | password: hex_md5(vm.passwordForm.password) |
| | | }, |
| | | method: "POST", |
| | |
| | | vm.$message.error(res.msg || "密码修改失败"); |
| | | return; |
| | | } |
| | | vm.form.password = hex_md5(vm.passwordForm.password); |
| | | vm.passwordDialogVisible = false; |
| | | vm.$alert("密码修改成功,请重新登录", "提示", { |
| | | confirmButtonText: "确定", |
| | |
| | | } |
| | | }); |
| | | }, |
| | | openMfaEnableDialog: function () { |
| | | if (Number(this.form.mfaAllow) !== 1) { |
| | | this.$message.warning("当前账号未开通MFA使用权限"); |
| | | return; |
| | | } |
| | | this.mfaDialogMode = "enable"; |
| | | this.resetMfaDialogState(); |
| | | this.mfaDialogVisible = true; |
| | | this.loadMfaSetup(); |
| | | }, |
| | | openMfaDisableDialog: function () { |
| | | this.mfaDialogMode = "disable"; |
| | | this.resetMfaDialogState(); |
| | | this.mfaDialogVisible = true; |
| | | }, |
| | | closeMfaDialog: function () { |
| | | this.mfaDialogVisible = false; |
| | | this.resetMfaDialogState(); |
| | | }, |
| | | resetMfaDialogState: function () { |
| | | this.mfaSubmitting = false; |
| | | this.mfaSetupLoading = false; |
| | | this.mfaForm = { |
| | | currentPassword: "", |
| | | code: "" |
| | | }; |
| | | this.mfaSetup = { |
| | | secret: "", |
| | | qrCode: "", |
| | | otpAuth: "" |
| | | }; |
| | | if (this.$refs.mfaForm) { |
| | | this.$refs.mfaForm.clearValidate(); |
| | | } |
| | | }, |
| | | loadMfaSetup: function () { |
| | | var vm = this; |
| | | vm.mfaSetupLoading = true; |
| | | $.ajax({ |
| | | url: baseUrl + "/user/mfa/setup/auth", |
| | | headers: { token: localStorage.getItem("token") }, |
| | | method: "POST", |
| | | success: function (res) { |
| | | if (handleForbidden(res)) { |
| | | return; |
| | | } |
| | | if (Number(res.code) !== 200) { |
| | | vm.$message.error(res.msg || "MFA配置加载失败"); |
| | | return; |
| | | } |
| | | vm.mfaSetup = Object.assign({}, vm.mfaSetup, res.data || {}); |
| | | }, |
| | | error: function () { |
| | | vm.$message.error("MFA配置加载失败"); |
| | | }, |
| | | complete: function () { |
| | | vm.mfaSetupLoading = false; |
| | | } |
| | | }); |
| | | }, |
| | | handleMfaSubmit: function () { |
| | | var vm = this; |
| | | if (!vm.$refs.mfaForm) { |
| | | return; |
| | | } |
| | | vm.$refs.mfaForm.validate(function (valid) { |
| | | if (!valid) { |
| | | return false; |
| | | } |
| | | if (vm.mfaDialogMode === "enable" && !vm.mfaSetup.secret) { |
| | | vm.$message.error("MFA密钥尚未生成,请稍后重试"); |
| | | return false; |
| | | } |
| | | vm.submitMfaAction(); |
| | | return true; |
| | | }); |
| | | }, |
| | | submitMfaAction: function () { |
| | | var vm = this; |
| | | vm.mfaSubmitting = true; |
| | | $.ajax({ |
| | | url: baseUrl + (vm.mfaDialogMode === "enable" ? "/user/mfa/enable/auth" : "/user/mfa/disable/auth"), |
| | | headers: { token: localStorage.getItem("token") }, |
| | | data: { |
| | | currentPassword: hex_md5(vm.mfaForm.currentPassword), |
| | | code: vm.mfaForm.code, |
| | | secret: vm.mfaSetup.secret |
| | | }, |
| | | method: "POST", |
| | | success: function (res) { |
| | | if (handleForbidden(res)) { |
| | | return; |
| | | } |
| | | if (Number(res.code) !== 200) { |
| | | vm.$message.error(res.msg || "MFA操作失败"); |
| | | return; |
| | | } |
| | | vm.$message.success(vm.mfaDialogMode === "enable" ? "MFA已启用" : "MFA已停用"); |
| | | vm.closeMfaDialog(); |
| | | vm.loadDetail(); |
| | | }, |
| | | error: function () { |
| | | vm.$message.error("MFA操作失败"); |
| | | }, |
| | | complete: function () { |
| | | vm.mfaSubmitting = false; |
| | | } |
| | | }); |
| | | }, |
| | | copySecret: function () { |
| | | var vm = this; |
| | | var text = vm.mfaSetup.secret || ""; |
| | | if (!text) { |
| | | return; |
| | | } |
| | | if (navigator.clipboard && navigator.clipboard.writeText) { |
| | | navigator.clipboard.writeText(text).then(function () { |
| | | vm.$message.success("密钥已复制"); |
| | | }).catch(function () { |
| | | vm.fallbackCopy(text); |
| | | }); |
| | | return; |
| | | } |
| | | vm.fallbackCopy(text); |
| | | }, |
| | | fallbackCopy: function (text) { |
| | | try { |
| | | var textarea = document.createElement("textarea"); |
| | | textarea.value = text; |
| | | textarea.style.position = "fixed"; |
| | | textarea.style.opacity = "0"; |
| | | document.body.appendChild(textarea); |
| | | textarea.select(); |
| | | document.execCommand("copy"); |
| | | document.body.removeChild(textarea); |
| | | this.$message.success("密钥已复制"); |
| | | } catch (err) { |
| | | this.$message.error("复制失败"); |
| | | } |
| | | }, |
| | | handleSave: function () { |
| | | var vm = this; |
| | | vm.$refs.profileForm.validate(function (valid) { |