用户初次登录修改密码优化

This commit is contained in:
阿辉
2024-11-20 17:55:55 +08:00
parent 9c370169d3
commit 4a68bf2f2b
2 changed files with 71 additions and 70 deletions

View File

@@ -335,7 +335,8 @@ class UserViewSet(CustomModelViewSet):
old_pwd_md5 = hashlib.md5(old_pwd_md5.encode(encoding='UTF-8')).hexdigest() old_pwd_md5 = hashlib.md5(old_pwd_md5.encode(encoding='UTF-8')).hexdigest()
verify_password = check_password(str(old_pwd_md5), request.user.password) verify_password = check_password(str(old_pwd_md5), request.user.password)
if verify_password: if verify_password:
request.user.password = make_password(hashlib.md5(new_pwd.encode(encoding='UTF-8')).hexdigest()) # request.user.password = make_password(hashlib.md5(new_pwd.encode(encoding='UTF-8')).hexdigest())
request.user.password = make_password(new_pwd)
request.user.pwd_change_count += 1 request.user.pwd_change_count += 1
request.user.save() request.user.save()
return DetailResponse(data=None, msg="修改成功") return DetailResponse(data=None, msg="修改成功")

View File

@@ -1,16 +1,17 @@
<template> <template>
<el-form ref="formRef" size="large" class="login-content-form" :model="state.ruleForm" :rules="rules" @keyup.enter="loginClick"> <el-form ref="formRef" size="large" class="login-content-form" :model="state.ruleForm" :rules="rules"
@keyup.enter="loginClick">
<el-form-item class="login-animation1" prop="username"> <el-form-item class="login-animation1" prop="username">
<el-input type="text" :placeholder="$t('message.account.accountPlaceholder1')" readonly v-model="ruleForm.username" <el-input type="text" :placeholder="$t('message.account.accountPlaceholder1')" readonly
clearable autocomplete="off"> v-model="ruleForm.username" clearable autocomplete="off">
<template #prefix> <template #prefix>
<el-icon class="el-input__icon"><ele-User /></el-icon> <el-icon class="el-input__icon"><ele-User /></el-icon>
</template> </template>
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item class="login-animation2" prop="password"> <el-form-item class="login-animation2" prop="password">
<el-input :type="isShowPassword ? 'text' : 'password'" :placeholder="$t('message.account.accountPlaceholder4')" <el-input :type="isShowPassword ? 'text' : 'password'"
v-model="ruleForm.password"> :placeholder="$t('message.account.accountPlaceholder4')" v-model="ruleForm.password">
<template #prefix> <template #prefix>
<el-icon class="el-input__icon"><ele-Unlock /></el-icon> <el-icon class="el-input__icon"><ele-Unlock /></el-icon>
</template> </template>
@@ -23,8 +24,8 @@
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item class="login-animation3" prop="password_regain"> <el-form-item class="login-animation3" prop="password_regain">
<el-input :type="isShowPassword ? 'text' : 'password'" :placeholder="$t('message.account.accountPlaceholder5')" <el-input :type="isShowPassword ? 'text' : 'password'"
v-model="ruleForm.password_regain"> :placeholder="$t('message.account.accountPlaceholder5')" v-model="ruleForm.password_regain">
<template #prefix> <template #prefix>
<el-icon class="el-input__icon"><ele-Unlock /></el-icon> <el-icon class="el-input__icon"><ele-Unlock /></el-icon>
</template> </template>
@@ -37,8 +38,7 @@
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item class="login-animation4"> <el-form-item class="login-animation4">
<el-button type="primary" class="login-content-submit" round @click="loginClick" <el-button type="primary" class="login-content-submit" round @click="loginClick" :loading="loading.signIn">
:loading="loading.signIn">
<span>{{ $t('message.account.accountBtnText') }}</span> <span>{{ $t('message.account.accountBtnText') }}</span>
</el-button> </el-button>
</el-form-item> </el-form-item>
@@ -71,8 +71,8 @@ import { SystemConfigStore } from '/@/stores/systemConfig';
import { BtnPermissionStore } from '/@/plugin/permission/store.permission'; import { BtnPermissionStore } from '/@/plugin/permission/store.permission';
import { Md5 } from 'ts-md5'; import { Md5 } from 'ts-md5';
import { errorMessage } from '/@/utils/message'; import { errorMessage } from '/@/utils/message';
import {getBaseURL} from "/@/utils/baseUrl"; import { getBaseURL } from "/@/utils/baseUrl";
import {loginChangePwd} from "/@/views/system/login/api"; import { loginChangePwd } from "/@/views/system/login/api";
export default defineComponent({ export default defineComponent({
name: 'changePwd', name: 'changePwd',
@@ -88,7 +88,7 @@ export default defineComponent({
ruleForm: { ruleForm: {
username: '', username: '',
password: '', password: '',
password_regain:'' password_regain: ''
}, },
loading: { loading: {
signIn: false, signIn: false,
@@ -111,7 +111,7 @@ export default defineComponent({
const validatePass2 = (rule, value, callback) => { const validatePass2 = (rule, value, callback) => {
if (value === '') { if (value === '') {
callback(new Error('请再次输入密码')); callback(new Error('请再次输入密码'));
} else if (value !==state.ruleForm.password) { } else if (value !== state.ruleForm.password) {
callback(new Error('两次输入密码不一致!')); callback(new Error('两次输入密码不一致!'));
} else { } else {
callback(); callback();
@@ -159,7 +159,7 @@ export default defineComponent({
if (!formRef.value) return if (!formRef.value) return
await formRef.value.validate((valid: any) => { await formRef.value.validate((valid: any) => {
if (valid) { if (valid) {
loginApi.loginChangePwd({ ...state.ruleForm, password: state.ruleForm.password,password_regain: state.ruleForm.password_regain }).then((res: any) => { loginApi.loginChangePwd({ ...state.ruleForm, password: Md5.hashStr(state.ruleForm.password), password_regain: Md5.hashStr(state.ruleForm.password_regain) }).then((res: any) => {
if (res.code === 2000) { if (res.code === 2000) {
if (!themeConfig.value.isRequestRoutes) { if (!themeConfig.value.isRequestRoutes) {
// 前端控制路由2、请注意执行顺序 // 前端控制路由2、请注意执行顺序