添加修改密码

This commit is contained in:
yyhouc 2023-07-10 11:02:26 +08:00
parent 4d63084f45
commit 15e9f25ff7
3 changed files with 275 additions and 4 deletions

View File

@ -91,3 +91,29 @@ export const updatePassword = (email,newPassword,tenantId,code) => {
}
});
}
//根据用户名与租户Id验证密码是否正确
export const checkPassword = (account,password,tenantId) => {
return request({
url: '/api/' + moduleName + '/ui/administrator/checkPassword',
method: 'get',
params: {
account,
tenantId,
password
}
});
}
//根据用户名、租户ID、旧密码修改密码
export const updatePasswordByOldPassword = (account,oldPassword,newPassword,tenantId) => {
return request({
url: '/api/' + moduleName + '/ui/administrator/updatePasswordByOldPassword',
method: 'put',
params: {
account,
tenantId,
oldPassword,
newPassword,
}
});
}

View File

@ -0,0 +1,238 @@
<template>
<el-dialog
v-model="state.dialogVisible"
title="Edit Password"
width="30%"
>
<el-form size="large" class="login-content-form" :rules="rules" :model="state.ruleForm">
<el-form-item class="login-animation1" prop="userName" >
<el-input text placeholder="Please input email," v-model="state.ruleForm.userName" clearable autocomplete="off">
<template #prefix>
<el-icon class="el-input__icon"><ele-User /></el-icon>
</template>
</el-input>
</el-form-item>
<el-form-item class="login-animation3" prop="oldPassword">
<el-input :type="state.isShowPassword2 ? 'text' : 'password'" placeholder="Please input new Old password" v-model="state.ruleForm.oldPassword" autocomplete="off">
<template #prefix>
<el-icon class="el-input__icon"><ele-Unlock /></el-icon>
</template>
<template #suffix>
<i
class="iconfont el-input__icon login-content-password"
:class="state.isShowPassword2 ? 'icon-yincangmima' : 'icon-xianshimima'"
@click="state.isShowPassword2 = !state.isShowPassword2"
>
</i>
</template>
</el-input>
</el-form-item>
<el-form-item class="login-animation2" prop="password">
<el-input :type="state.isShowPassword ? 'text' : 'password'" placeholder="Please input new password" v-model="state.ruleForm.password" autocomplete="off">
<template #prefix>
<el-icon class="el-input__icon"><ele-Unlock /></el-icon>
</template>
<template #suffix>
<i
class="iconfont el-input__icon login-content-password"
:class="state.isShowPassword ? 'icon-yincangmima' : 'icon-xianshimima'"
@click="state.isShowPassword = !state.isShowPassword"
>
</i>
</template>
</el-input>
</el-form-item>
<el-form-item class="login-animation2" prop="password1">
<el-input :type="state.isShowPassword1 ? 'text' : 'password'" placeholder="Please enter a confirmation password" v-model="state.ruleForm.password1" autocomplete="off">
<template #prefix>
<el-icon class="el-input__icon"><ele-Unlock /></el-icon>
</template>
<template #suffix>
<i
class="iconfont el-input__icon login-content-password"
:class="state.isShowPassword1 ? 'icon-yincangmima' : 'icon-xianshimima'"
@click="state.isShowPassword1 = !state.isShowPassword1"
>
</i>
</template>
</el-input>
</el-form-item>
<el-form-item class="login-animation4">
<el-button type="primary" class="login-content-submit" round v-waves @click="onSignIn" :loading="state.loading.signIn">
<span>Edit</span>
</el-button>
</el-form-item>
</el-form>
</el-dialog>
</template>
<script setup name="updatePassword">
import { reactive, computed, onMounted,ref } from 'vue';
import { ElMessage } from 'element-plus';
import { storeToRefs } from 'pinia';
import { useThemeConfig } from '/@/stores/themeConfig';
import {checkAccountOrEmail,checkPassword,updatePasswordByOldPassword} from '/@/api/response/administrator';
//Session
import { Local as Session } from '/@/utils/storage';
//
const storesThemeConfig = useThemeConfig();
const { website } = storeToRefs(storesThemeConfig);
const sendRef = ref(null);
//
const e =defineEmits(["success"]);
const state = reactive({
isShowPassword: false,
ruleForm: {
//ID
tenantId: website.value.tenantId,
//
userName: "792163605@qq.com",
//
password: "",
//
type: "account",
//key
key: "",
//code
code: "",
},
loading: {
signIn: false,
},
send:"Send",
captchaMode: website.value.captchaMode,
//localStroage key
captchaKey: "captchaKey",
dialogVisible: false,
});
const rules = reactive({
userName: [
{ required: true, message: "Please enter your email", trigger: "blur" },
{ type: "email", message: "Please enter the email", trigger: "blur" },
//
{
validator: (rule, value, callback) => {
checkAccountOrEmail(value,website.value.tenantId).then((res) => {
//res.data false
if (res.data || res.data == false || res.data == "") {
//
callback(new Error("The email is not registered"));
} else {
callback();
}
});
},
trigger: "blur",
},
],
password: [
{ required: true, message: "Please enter a new password", trigger: "blur" },
{ min: 6, max: 20, message: "The password length is 6-20 characters", trigger: "blur" },
],
password1: [
{ required: true, message: "Please enter a confirmation password", trigger: "blur" },
{ min: 6, max: 20, message: "The password length is 6-20 characters", trigger: "blur" },
//password
{
validator: (rule, value, callback) => {
if (value != state.ruleForm.password) {
callback(new Error("The password is inconsistent"));
} else {
callback();
}
},
trigger: "blur",
},
],
oldPassword: [
{ required: true, message: "Please enter the verification code", trigger: "blur" },
//
{
validator: (rule, value, callback) => {
//
if (value) {
//
if (state.ruleForm.userName) {
//
checkPassword(state.ruleForm.userName,value,website.value.tenantId).then((res) => {
//res.datatrue使退,
if (res && res == true) {
callback();
} else {
callback(new Error("The old password is incorrect"));
}
});
} else {
callback(new Error("Please enter your email"));
}
} else {
callback(new Error("Please enter the verification code"));
}
},
trigger: "blur",
},
],
})
const show = () => {
state.dialogVisible = true;
};
const onSignIn = () => {
state.loading.signIn = true;
updatePasswordByOldPassword(
state.ruleForm.userName,
state.ruleForm.oldPassword,
state.ruleForm.password,
website.value.tenantId
).then((res) => {
state.loading.signIn = false;
if (res) {
ElMessage.success("Password reset successfully");
state.dialogVisible = false;
e.success();
}
});
};
defineExpose({
show
})
</script>
<style scoped lang="scss">
.login-content-form {
margin-top: 12px;
@for $i from 1 through 4 {
.login-animation#{$i} {
opacity: 0;
animation-name: error-num;
animation-duration: 0.5s;
animation-fill-mode: forwards;
animation-delay: calc($i/10) + s;
}
}
.login-content-password {
display: inline-block;
width: 20px;
cursor: pointer;
&:hover {
color: #909399;
}
}
.login-content-code {
width: 100%;
padding: 0;
font-weight: bold;
letter-spacing: 5px;
}
.login-content-submit {
width: 100%;
letter-spacing: 2px;
font-weight: 300;
margin-top: 15px;
}
}
.el-form-item--large {
margin-bottom: 14px !important;
}
</style>

View File

@ -70,7 +70,7 @@
<div class="layout-navbars-breadcrumb-user-icon mr10"
@click="onScreenfullClick">
<i class="iconfont"
:title="state.isScreenfull ? '关全屏' : '开全屏'"
:title="state.isScreenfull ? 'Off full screen' : 'Full screen'"
:class="!state.isScreenfull ? 'icon-fullscreen' : 'icon-tuichuquanping'"></i>
</div>
@ -87,14 +87,15 @@
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item command="/home">Dashboard</el-dropdown-item>
<el-dropdown-item divided
command="logOut">Sign out</el-dropdown-item>
<el-dropdown-item @Click="editPassword">Edit Password</el-dropdown-item>
<!-- <el-dropdown-item command="/home">Dashboard</el-dropdown-item> -->
<el-dropdown-item divided command="logOut">Sign out</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
<Search ref="searchRef" />
<updatePassword ref="updatePasswordRef"/>
</div>
</template>
@ -110,10 +111,12 @@ import mittBus from '/@/utils/mitt';
import { Session, Local } from '/@/utils/storage';
import { refreshToken } from '/@/api/system/user.js'
import { useTranslate } from '/@/stores/translate';
//updatePassword
import other from '/@/utils/other';
//
const UserNews = defineAsyncComponent(() => import('/@/layout/navBars/breadcrumb/userNews.vue'));
const Search = defineAsyncComponent(() => import('/@/layout/navBars/breadcrumb/search.vue'));
const updatePassword =defineAsyncComponent(() => import('/@/layout/navBars/breadcrumb/updatePassword.vue'));
const useTranslateStore = useTranslate()
const onLanguageChange = (lang) => {
if (lang == "en") {
@ -133,12 +136,16 @@ const { userInfos } = storeToRefs(stores);
const { themeConfig, website } = storeToRefs(storesThemeConfig);
const searchRef = ref();
const updatePasswordRef = ref();
const state = reactive({
isScreenfull: false,
disabledSize: 'large',
setIntervalId: null,
disabledI18n: "en",
});
const editPassword = () => {
updatePasswordRef.value.show()
}
//
const layoutUserFlexNum = computed(() => {