修改密码

Raod 3 years ago
parent e27256bdc4
commit 685544755b

@ -19,6 +19,23 @@ public interface ResponseCode {
*/
String LOGIN_ERROR = "login.error";
/**
*
*/
String USER_PASSWORD_CONFIG_PASSWORD_CANOT_EQUAL = "user.password.config.password.canot.equal";
/**
*
*/
String USER_INCONSISTENT_PASSWORD_ERROR = "user.inconsistent.password.error";
/**
*
*/
String USER_OLD_PASSWORD_ERROR = "user.old.password.error";
/**
* token
*/
@ -84,7 +101,6 @@ public interface ResponseCode {
String COMPONENT_NOT_LOAD = "Component.load.check.error";
String AUTH_PASSWORD_NOTSAME = "1001";
String USER_PASSWORD_CONFIG_PASSWORD_CANOT_EQUAL = "1002";
String OLD_PASSWORD_ERROR = "1003";
String USER_ONTEXIST_ORGINFO = "1004";
String USER_ONTEXIST_ROLEINFO = "1005";

@ -7,6 +7,7 @@ import com.anji.plus.gaea.curd.controller.GaeaBaseController;
import com.anji.plus.gaea.curd.service.GaeaBaseService;
import com.anji.plus.gaea.holder.UserContentHolder;
import com.anjiplus.template.gaea.business.modules.accessuser.controller.dto.GaeaUserDto;
import com.anjiplus.template.gaea.business.modules.accessuser.controller.dto.UpdatePasswordDto;
import com.anjiplus.template.gaea.business.modules.accessuser.dao.entity.AccessUser;
import com.anjiplus.template.gaea.business.modules.accessuser.service.AccessUserService;
import com.anjiplus.template.gaea.business.modules.accessuser.controller.dto.AccessUserDto;
@ -99,4 +100,14 @@ public class AccessUserController extends GaeaBaseController<AccessUserParam, Ac
return responseSuccessWithData(accessUserService.login(dto));
}
}
/**
*
* @param dto
* @return
*/
@PostMapping("/updatePassword")
public ResponseBean updatePassword(@RequestBody UpdatePasswordDto dto) {
return responseSuccessWithData(accessUserService.updatePassword(dto));
}
}

@ -27,11 +27,6 @@ public class AccessUserDto extends GaeaBaseDTO implements Serializable {
@NotEmpty(message = "6002")
private String loginName;
/** 密码 */
@ApiModelProperty(value = "密码")
@NotEmpty(message = "6002")
private String password;
/** 真实用户 */
@ApiModelProperty(value = "真实用户")
@NotEmpty(message = "6002")
@ -68,4 +63,4 @@ public class AccessUserDto extends GaeaBaseDTO implements Serializable {
/** 用户勾选的角色 */
private List<String> roleCodeList;
}
}

@ -0,0 +1,25 @@
package com.anjiplus.template.gaea.business.modules.accessuser.controller.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.util.List;
@ApiModel(value = "修改密码")
@Data
public class UpdatePasswordDto {
@ApiModelProperty(value = "旧密码密码")
@NotBlank
private String oldPassword;
@ApiModelProperty(value = "密码")
@NotBlank
private String password;
@ApiModelProperty(value = "密码")
@NotBlank
private String confirmPassword;
}

@ -3,6 +3,7 @@ package com.anjiplus.template.gaea.business.modules.accessuser.service;
import com.anjiplus.template.gaea.business.modules.accessuser.controller.dto.AccessUserDto;
import com.anjiplus.template.gaea.business.modules.accessuser.controller.dto.GaeaUserDto;
import com.anjiplus.template.gaea.business.modules.accessuser.controller.dto.UpdatePasswordDto;
import com.anjiplus.template.gaea.business.modules.accessuser.dao.entity.AccessUser;
import com.anjiplus.template.gaea.business.modules.accessuser.controller.param.AccessUserParam;
import com.anji.plus.gaea.curd.service.GaeaBaseService;
@ -41,4 +42,11 @@ public interface AccessUserService extends GaeaBaseService<AccessUserParam, Acce
* @return
*/
GaeaUserDto login(GaeaUserDto gaeaUserDto);
}
/**
*
* @param dto
* @return
*/
Boolean updatePassword(UpdatePasswordDto dto);
}

@ -4,9 +4,11 @@ package com.anjiplus.template.gaea.business.modules.accessuser.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.anji.plus.gaea.bean.TreeNode;
import com.anji.plus.gaea.cache.CacheHelper;
import com.anji.plus.gaea.constant.BaseOperationEnum;
import com.anji.plus.gaea.exception.BusinessException;
import com.anji.plus.gaea.exception.BusinessExceptionBuilder;
import com.anji.plus.gaea.utils.GaeaBeanUtils;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import com.anji.plus.gaea.holder.UserContentHolder;
import com.anji.plus.gaea.utils.GaeaUtils;
import com.anji.plus.gaea.utils.JwtBean;
import com.anjiplus.template.gaea.business.code.ResponseCode;
@ -15,6 +17,7 @@ import com.anjiplus.template.gaea.business.modules.accessrole.dao.AccessRoleMapp
import com.anjiplus.template.gaea.business.modules.accessrole.dao.entity.AccessRole;
import com.anjiplus.template.gaea.business.modules.accessuser.controller.dto.AccessUserDto;
import com.anjiplus.template.gaea.business.modules.accessuser.controller.dto.GaeaUserDto;
import com.anjiplus.template.gaea.business.modules.accessuser.controller.dto.UpdatePasswordDto;
import com.anjiplus.template.gaea.business.modules.accessuser.dao.AccessUserRoleMapper;
import com.anjiplus.template.gaea.business.modules.accessuser.dao.entity.AccessUser;
import com.anjiplus.template.gaea.business.modules.accessuser.dao.entity.AccessUserRole;
@ -23,9 +26,9 @@ import com.anjiplus.template.gaea.business.modules.accessuser.dao.AccessUserMapp
import com.anjiplus.template.gaea.business.util.MD5Util;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -51,6 +54,9 @@ public class AccessUserServiceImpl implements AccessUserService {
@Autowired
private AccessUserRoleMapper accessUserRoleMapper;
@Value("${customer.user.default.password:'123456'}")
private String defaultPassword;
@Override
public GaeaBaseMapper<AccessUser> getMapper() {
return accessUserMapper;
@ -172,4 +178,60 @@ public class AccessUserServiceImpl implements AccessUserService {
return gaeaUser;
}
/**
*
*
* @param dto
* @return
*/
@Override
public Boolean updatePassword(UpdatePasswordDto dto) {
if (!dto.getConfirmPassword().equals(dto.getPassword())) {
//密码和确认密码不一致
throw BusinessExceptionBuilder.build(ResponseCode.USER_INCONSISTENT_PASSWORD_ERROR);
}
//新密码不能与老密码一样
if(StringUtils.equals(dto.getOldPassword(), dto.getPassword())){
throw BusinessExceptionBuilder.build(ResponseCode.USER_PASSWORD_CONFIG_PASSWORD_CANOT_EQUAL);
}
String username = UserContentHolder.getUsername();
LambdaQueryWrapper<AccessUser> wrapper = Wrappers.lambdaQuery();
wrapper.eq(AccessUser::getLoginName, username);
AccessUser accessUser = selectOne(wrapper);
String password = accessUser.getPassword();
if (!MD5Util.encrypt(dto.getOldPassword()).equals(password)) {
throw BusinessExceptionBuilder.build(ResponseCode.USER_OLD_PASSWORD_ERROR);
}
accessUser.setPassword(MD5Util.encrypt(dto.getPassword()));
accessUserMapper.updateById(accessUser);
return true;
}
/**
*
*
* @param entity
* @param operationEnum
* @throws BusinessException
*/
@Override
public void processBeforeOperation(AccessUser entity, BaseOperationEnum operationEnum) throws BusinessException {
//过滤密码
switch (operationEnum) {
case INSERT:
//gaea是为了和前端加密保持一致
entity.setPassword(MD5Util.encrypt(MD5Util.encrypt(defaultPassword.concat("gaea"))));
break;
case UPDATE:
//更新用户不允许修改密码
entity.setPassword(null);
break;
}
}
}

@ -77,3 +77,7 @@ file:
customer:
# 跳过token验证和权限验证的url清单
skip-authenticate-urls: /gaeaDict/all, /login, /static, /file/download/, /index.html
user:
##新增用户默认密码
default:
password: 123456

@ -2,6 +2,9 @@
200=success
User.password.error=Password error
user.password.config.password.canot.equal=user password config password canot equal
user.inconsistent.password.error=user inconsistent password error
user.old.password.error=user old password error
1013=The code does not allow duplication
2001=File names are not allowed to be empty

@ -2,6 +2,9 @@
200=\u64CD\u4F5C\u6210\u529F
User.password.error=\u5BC6\u7801\u4E0D\u6B63\u786E
user.password.config.password.canot.equal=\u65B0\u5BC6\u7801\u4E0D\u80FD\u548C\u539F\u5BC6\u7801\u4E00\u81F4
user.inconsistent.password.error=\u5BC6\u7801\u548C\u786E\u8BA4\u5BC6\u7801\u4E0D\u4E00\u81F4
user.old.password.error=\u65E7\u5BC6\u7801\u4E0D\u6B63\u786E
1013=\u7F16\u7801\u4E0D\u5141\u8BB8\u91CD\u590D
2001=\u6587\u4EF6\u540D\u4E0D\u5141\u8BB8\u4E3A\u7A7A
2002=\u6587\u4EF6\u7C7B\u578B\u4E0D\u652F\u6301

@ -4,6 +4,6 @@ const prodEnv = require('./prod.env')
module.exports = merge(prodEnv, {
NODE_ENV: '"development"',
// BASE_API: '"http://127.0.0.1:9095"'
BASE_API: '"http://10.108.26.197:9095"'
BASE_API: '"http://127.0.0.1:9095"'
// BASE_API: '"http://10.108.26.197:9095"'
})

@ -1,4 +1,4 @@
import request from './axios'
import request from '@/utils/request'
export function login (data) {
return request({
@ -16,8 +16,10 @@ export function logout () {
}
// 登录之后 根据旧修改密码
export const reqUpdatePassword = data => request({
url: '/auth-service/user/updatePassword',
method: 'post',
data: data
})
export function reqUpdatePassword (data) {
return request({
url: '/accessUser/updatePassword',
method: 'post',
data
})
}

@ -126,20 +126,20 @@ export default {
],
disabled: false,
},
{
label: '密码',
placeholder: '',
field: 'password',
tableHide: true, //
editHide: true,
editField: 'password',
inputType: 'input',
rules: [
// { required: true, message: '', trigger: 'blur' },
{ min: 1, max: 128, message: '不超过128个字符', trigger: 'blur' },
],
disabled: false,
},
// {
// label: '',
// placeholder: '',
// field: 'password',
// tableHide: true, //
// editHide: true,
// editField: 'password',
// inputType: 'input',
// rules: [
// // { required: true, message: '', trigger: 'blur' },
// { min: 1, max: 128, message: '128', trigger: 'blur' },
// ],
// disabled: false,
// },
{
label: '手机号码',
placeholder: '',

@ -15,6 +15,10 @@
</div>
<el-dropdown-menu slot="dropdown"
class="user-dropdown">
<el-dropdown-item divided>
<span style="display:block;"
@click="updatePassword">修改密码</span>
</el-dropdown-item>
<el-dropdown-item divided>
<span style="display:block;"
@click="logout">注销登录</span>
@ -22,6 +26,32 @@
</el-dropdown-menu>
</el-dropdown>
</el-menu>
<!-- 修改密码弹框 -->
<el-dialog
title="修改密码"
:visible.sync="wordVisible"
width="40%"
:close-on-click-modal='false'
top="20vh"
class="password-box"
>
<el-form ref="form" :model="form" label-width="100px" :rules="rules" :close-on-click-modal="false">
<el-form-item label="原密码" prop="oldPassword">
<el-input v-model.trim="form.oldPassword" type="password" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="新密码" prop="password">
<el-input v-model.trim="form.password" type="password" autocomplete="off"></el-input>
<!-- <span class="password-tips"><i class="el-icon-warning-outline"> 密码至少8位,切包含大写小写字母数字特殊字符中的3种</i></span> -->
</el-form-item>
<el-form-item label="确认新密码" prop="confirmPassword">
<el-input v-model.trim="form.confirmPassword" type="password" autocomplete="off"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="wordVisible = false"> </el-button>
<el-button type="primary" @click="confrimUpdate"> </el-button>
</span>
</el-dialog>
</div>
</template>
@ -30,8 +60,8 @@ import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
import { getStorageItem } from '@/utils/storage'
import { aesEncrypt } from '@/utils/aes'
import { reqUpdatePassword } from '@/api/login'
import { transPsw } from '@/utils/encrypted'
export default {
data () {
@ -41,17 +71,19 @@ export default {
callback(new Error('请再次输入密码'))
} else if (value !== this.form.password) {
callback(new Error('两次输入密码不一致!'))
} else if (value.length < 6 || value.length > 20) {
callback(new Error('密码长度需要再6-20之间!'));
} else {
callback()
callback();
}
}
// const validatePass = (rule, value, callback) => {
// if (!/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?![0-9\W_]+$)[a-zA-Z0-9\W_]{6,}$/.test(value)) {
// callback(new Error(''))
// } else {
// callback()
// }
// };
const validatePass = (rule, value, callback) => {
if (!/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?![0-9\W_]+$)[a-zA-Z0-9\W_]{6,}$/.test(value)) {
callback(new Error('请按要求输入密码'))
} else {
callback()
}
};
const validateOldPass = (rule, value, callback) => {
if (value.length < 6 || value.length > 30) {
callback(new Error('请输入原密码'))
@ -111,23 +143,22 @@ export default {
},
//
confrimUpdate () {
this.$refs.form.validate((valid) => {
this.$refs.form.validate(async (valid) => {
if (valid) {
const { oldPassword, password, confirmPassword } = this.form
const {oldPassword, password, confirmPassword} = this.form
let data = {
oldPassword: aesEncrypt(oldPassword),
password: aesEncrypt(password),
confirmPassword: aesEncrypt(confirmPassword),
oldPassword: transPsw(oldPassword),
password: transPsw(password),
confirmPassword: transPsw(confirmPassword),
}
reqUpdatePassword(data).then((res) => {
if (res.repCode == '0000') {
const { code } = await reqUpdatePassword(data);
if (code != '200') return
this.wordVisible = false
this.$message.success('修改密码成功,请重新登录')
sessionStorage.clear()
localStorage.clear()
this.$router.push('/login')
}
})
} else {
return false
}

Loading…
Cancel
Save