明文加解密

This commit is contained in:
binbin_pan 2024-06-05 14:01:33 +08:00
parent 82d80aa1b7
commit fd668b51ee
6 changed files with 240 additions and 233 deletions

View File

@ -105,8 +105,11 @@ export const constantRoutes = [
path: '/qrCode/qrCodePage', path: '/qrCode/qrCodePage',
component: () => import('@/views/qrCode/qrCode'), component: () => import('@/views/qrCode/qrCode'),
hidden: true hidden: true
},
{
path: '/resetPassword',
component: () => import('@/views/resetPassword'),
hidden: true
} }
] ]

View File

@ -48,7 +48,7 @@ const user = {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
login(username, password, code, uuid).then(res => { login(username, password, code, uuid).then(res => {
let data = res.data let data = res.data
localStorage.setItem('isCode', data.code) localStorage.setItem('isCode', data.code || '')
setToken(data.access_token) setToken(data.access_token)
commit('SET_TOKEN', data.access_token) commit('SET_TOKEN', data.access_token)
localStorage.setItem('token', data.access_token) localStorage.setItem('token', data.access_token)
@ -155,6 +155,7 @@ const user = {
commit('SET_ROLES', []) commit('SET_ROLES', [])
commit('SET_PERMISSIONS', []) commit('SET_PERMISSIONS', [])
removeToken() removeToken()
localStorage.removeItem('isCode')
resolve() resolve()
}).catch(error => { }).catch(error => {
reject(error) reject(error)

View File

@ -19,6 +19,7 @@
type="password" type="password"
auto-complete="off" auto-complete="off"
placeholder="密码" placeholder="密码"
show-password
@keyup.enter.native="handleLogin" @keyup.enter.native="handleLogin"
> >
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
@ -299,7 +300,13 @@ export default {
this.$store this.$store
.dispatch('Login', this.loginForm) .dispatch('Login', this.loginForm)
.then(() => { .then(() => {
this.$router.push({ path: '/' }).catch(() => {}) if (localStorage.getItem('isCode') == 1) {
this.$router
.push({ path: '/resetPassword' })
.catch(() => {})
} else {
this.$router.push({ path: '/' }).catch(() => {})
}
}) })
.catch(() => { .catch(() => {
this.loading = false this.loading = false

View File

@ -1,246 +1,237 @@
<template> <template>
<div class="login"> <div class="login">
<div class="login-bar"> <div class="login-bar">
<div class="form-bar"> <div class="form-bar">
<h3 class="title">请重置登录密码</h3> <h3 class="title">请重置登录密码</h3>
<el-form <el-form ref="form" :model="user" :rules="rules">
ref="form" <el-form-item label="旧密码" prop="oldPassword">
:model="user" <el-input
:rules="rules" v-model="user.oldPassword"
> placeholder="请输入旧密码"
<el-form-item label="旧密码" prop="oldPassword"> type="password"
<el-input show-password
v-model="user.oldPassword" />
placeholder="请输入旧密码" </el-form-item>
type="password" <el-form-item label="新密码" prop="newPassword">
show-password <el-input
/> v-model="user.newPassword"
</el-form-item> placeholder="请输入新密码"
<el-form-item label="新密码" prop="newPassword"> type="password"
<el-input show-password
v-model="user.newPassword" />
placeholder="请输入新密码" </el-form-item>
type="password" <el-form-item label="确认密码" prop="confirmPassword">
show-password <el-input
/> v-model="user.confirmPassword"
</el-form-item> placeholder="请确认新密码"
<el-form-item label="确认密码" prop="confirmPassword"> type="password"
<el-input show-password
v-model="user.confirmPassword" />
placeholder="请确认新密码" </el-form-item>
type="password" <el-form-item>
show-password <el-button
/> type="primary"
</el-form-item> style="width: 48.5%"
<el-form-item> @click="submit"
<el-button type="primary" style="width: 48.5%;" @click="submit" >确认修改</el-button
>确认修改</el-button >
> <el-button style="width: 48.5%" @click="close"
<el-button style="width: 48.5%;" @click="close">返回登录页</el-button> >返回登录页</el-button
</el-form-item> >
</el-form> </el-form-item>
</div> </el-form>
</div> </div>
</div> </div>
</div>
</template> </template>
<script> <script>
import { updateUserPwd } from '@/api/system/user' import { updateUserPwd } from '@/api/system/user'
import { validPassword } from '@/utils/validate' import { validPassword } from '@/utils/validate'
import { encrypt } from '@/utils/jsencrypt.js'
export default { export default {
data() { data() {
const passwordRegex = (rule, value, callback) => { const passwordRegex = (rule, value, callback) => {
if (value.length < 8 || value.length > 20) { if (value.length < 8 || value.length > 20) {
callback(new Error('密码长度在 8 到 20 个字符')) callback(new Error('密码长度在 8 到 20 个字符'))
} else if (!validPassword(value)) { } else if (!validPassword(value)) {
callback( callback(
new Error('密码须包含数字、字母、特殊符号中的两种以上'), new Error('密码须包含数字、字母、特殊符号中的两种以上'),
) )
} else if (this.user.oldPassword === value) { } else if (this.user.oldPassword === value) {
callback(new Error('新密码不能与旧密码相同')) callback(new Error('新密码不能与旧密码相同'))
} else { } else {
callback() callback()
} }
} }
const equalToPassword = (rule, value, callback) => { const equalToPassword = (rule, value, callback) => {
if (this.user.newPassword !== value) { if (this.user.newPassword !== value) {
callback(new Error('两次输入的密码不一致')) callback(new Error('两次输入的密码不一致'))
} else { } else {
callback() callback()
} }
} }
return { return {
user: { user: {
oldPassword: undefined, oldPassword: undefined,
newPassword: undefined, newPassword: undefined,
confirmPassword: undefined, confirmPassword: undefined,
}, },
// //
rules: { rules: {
oldPassword: [ oldPassword: [
{ {
required: true, required: true,
message: '旧密码不能为空', message: '旧密码不能为空',
trigger: 'blur', trigger: 'blur',
}, },
], ],
newPassword: [ newPassword: [
{ {
required: true, required: true,
message: '新密码不能为空', message: '新密码不能为空',
trigger: 'blur', trigger: 'blur',
}, },
{ {
required: true, required: true,
validator: passwordRegex, validator: passwordRegex,
trigger: 'blur', trigger: 'blur',
}, },
], ],
confirmPassword: [ confirmPassword: [
{ {
required: true, required: true,
message: '确认密码不能为空', message: '确认密码不能为空',
trigger: 'blur', trigger: 'blur',
}, },
{ {
required: true, required: true,
validator: equalToPassword, validator: equalToPassword,
trigger: 'blur', trigger: 'blur',
}, },
], ],
}, },
} }
}, },
methods: { methods: {
submit() { submit() {
this.$refs['form'].validate((valid) => { this.$refs['form'].validate((valid) => {
if (valid) { if (valid) {
updateUserPwd( const oldPassword = encrypt(this.user.oldPassword)
this.user.oldPassword, const newPassword = encrypt(this.user.newPassword)
this.user.newPassword, updateUserPwd(oldPassword, newPassword).then(
).then((response) => { (response) => {
this.$modal.msgSuccess('修改成功') this.$modal.msgSuccess('修改成功')
// //
this.$store.dispatch('LogOut').then(() => { this.$store.dispatch('LogOut').then(() => {
// location.href = '/login'; location.href = '/login'
// location.href = '/gl/login'; })
},
location.href = )
process.env.NODE_ENV === 'production-nw' }
? '/gl/login' })
: '/login' },
}) close() {
}) this.$store.dispatch('LogOut').then(() => {
} location.href = '/login'
}) })
}, },
close() { },
this.$store.dispatch('LogOut').then(() => { }
// location.href = '/login';
// location.href = '/gl/login';
location.href =
process.env.NODE_ENV === 'production-nw'
? '/gl/login'
: '/login'
})
},
},
}
</script> </script>
<style rel="stylesheet/scss" lang="scss"> <style rel="stylesheet/scss" lang="scss">
.login { .login {
//display: flex; //display: flex;
//justify-content: center; //justify-content: center;
//align-items: center; //align-items: center;
position: relative; position: relative;
height: 100%; height: 100%;
background-image: url('../assets/images/login.png'); background-image: url('../assets/images/login.png');
background-size: 100% 100%; background-size: 100% 100%;
//background: #1891FF; //background: #1891FF;
} }
.title { .title {
margin: 0px auto 30px auto; margin: 0px auto 30px auto;
//text-align: center; //text-align: center;
color: #707070; color: #707070;
} }
.login-bar { .login-bar {
position: absolute; position: absolute;
height: auto; height: auto;
top: 20%; top: 20%;
left: 14%; left: 14%;
width: auto; width: auto;
height: 500px; height: 500px;
border-radius: 6px; border-radius: 6px;
display: flex; display: flex;
background: #fff; background: #fff;
text-align: center; text-align: center;
padding-top: 40px; padding-top: 40px;
} }
.form-bar { .form-bar {
//height: 500px; //height: 500px;
width: 360px; width: 360px;
background: #fff; background: #fff;
} }
.login-form { .login-form {
//border-radius: 6px; //border-radius: 6px;
//height: 100%; //height: 100%;
background: #ffffff; background: #ffffff;
width: 400px; width: 400px;
padding: 25px 25px 5px 25px; padding: 25px 25px 5px 25px;
.el-input { .el-input {
height: 45px; height: 45px;
input { input {
height: 38px; height: 38px;
} }
} }
.input-icon { .input-icon {
height: 39px; height: 39px;
width: 14px; width: 14px;
margin-left: 2px; margin-left: 2px;
} }
} }
.login-tip { .login-tip {
font-size: 13px; font-size: 13px;
text-align: center; text-align: center;
color: #bfbfbf; color: #bfbfbf;
} }
.login-code { .login-code {
width: 33%; width: 33%;
height: 38px; height: 38px;
float: right; float: right;
img { img {
cursor: pointer; cursor: pointer;
vertical-align: middle; vertical-align: middle;
} }
} }
.el-login-footer { .el-login-footer {
height: 40px; height: 40px;
line-height: 40px; line-height: 40px;
position: fixed; position: fixed;
bottom: 0; bottom: 0;
width: 100%; width: 100%;
text-align: center; text-align: center;
color: #fff; color: #fff;
font-family: Arial; font-family: Arial;
font-size: 12px; font-size: 12px;
letter-spacing: 1px; letter-spacing: 1px;
} }
.login-code-img { .login-code-img {
height: 38px; height: 38px;
} }
</style> </style>

View File

@ -551,6 +551,7 @@ import {
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import Treeselect from '@riophae/vue-treeselect' import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css' import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { encrypt, decrypt } from '@/utils/jsencrypt'
export default { export default {
name: 'User', name: 'User',
@ -698,7 +699,7 @@ export default {
this.getList() this.getList()
this.getDeptTree() this.getDeptTree()
this.getConfigKey('sys.user.initPassword').then((response) => { this.getConfigKey('sys.user.initPassword').then((response) => {
this.initPassword = response.msg this.initPassword = decrypt(response.msg)
}) })
}, },
methods: { methods: {
@ -837,8 +838,9 @@ export default {
inputErrorMessage: '用户密码长度必须介于 5 和 20 之间', inputErrorMessage: '用户密码长度必须介于 5 和 20 之间',
}) })
.then(({ value }) => { .then(({ value }) => {
resetUserPwd(row.userId, value).then((response) => { const password = encrypt(value)
this.$modal.msgSuccess('修改成功,新密码是:' + value) resetUserPwd(row.userId, password).then((response) => {
this.$modal.msgSuccess('修改成功')
}) })
}) })
.catch(() => {}) .catch(() => {})

View File

@ -19,6 +19,7 @@
<script> <script>
import { updateUserPwd } from "@/api/system/user"; import { updateUserPwd } from "@/api/system/user";
import { validPassword } from '@/utils/validate' import { validPassword } from '@/utils/validate'
import { encrypt } from '@/utils/jsencrypt.js'
export default { export default {
data() { data() {
@ -66,7 +67,9 @@ export default {
submit() { submit() {
this.$refs["form"].validate(valid => { this.$refs["form"].validate(valid => {
if (valid) { if (valid) {
updateUserPwd(this.user.oldPassword, this.user.newPassword).then(response => { const oldPassword = encrypt(this.user.oldPassword)
const newPassword = encrypt(this.user.newPassword)
updateUserPwd(oldPassword, newPassword).then(response => {
this.$modal.msgSuccess("修改成功"); this.$modal.msgSuccess("修改成功");
}); });
} }