From 685544755bb848e8a8c292b5800030796c2c85f7 Mon Sep 17 00:00:00 2001 From: Raod <1130305001@qq.com> Date: Fri, 23 Jul 2021 14:22:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gaea/business/code/ResponseCode.java | 18 ++++- .../controller/AccessUserController.java | 13 +++- .../controller/dto/AccessUserDto.java | 7 +- .../controller/dto/UpdatePasswordDto.java | 25 +++++++ .../accessuser/service/AccessUserService.java | 10 ++- .../service/impl/AccessUserServiceImpl.java | 66 +++++++++++++++++- .../src/main/resources/bootstrap-dev.yml | 4 ++ .../resources/i18n/messages_en_US.properties | 3 + .../resources/i18n/messages_zh_CN.properties | 3 + report-ui/config/dev.env.js | 4 +- report-ui/src/api/login.js | 14 ++-- report-ui/src/views/accessUser/index.vue | 28 ++++---- .../src/views/layout/components/Navbar.vue | 67 ++++++++++++++----- 13 files changed, 211 insertions(+), 51 deletions(-) create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/controller/dto/UpdatePasswordDto.java diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/code/ResponseCode.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/code/ResponseCode.java index 92fb5eb2..eadf6f4c 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/code/ResponseCode.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/code/ResponseCode.java @@ -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"; diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/controller/AccessUserController.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/controller/AccessUserController.java index 49d53664..4db42aa2 100755 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/controller/AccessUserController.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/controller/AccessUserController.java @@ -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 roleCodeList; -} \ No newline at end of file +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/controller/dto/UpdatePasswordDto.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/controller/dto/UpdatePasswordDto.java new file mode 100644 index 00000000..daf84175 --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/controller/dto/UpdatePasswordDto.java @@ -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; +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/service/AccessUserService.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/service/AccessUserService.java index 3a1bbb96..900cee3a 100755 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/service/AccessUserService.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/service/AccessUserService.java @@ -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 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 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; + } + + } } diff --git a/report-core/src/main/resources/bootstrap-dev.yml b/report-core/src/main/resources/bootstrap-dev.yml index 1272340c..b9ccfea2 100644 --- a/report-core/src/main/resources/bootstrap-dev.yml +++ b/report-core/src/main/resources/bootstrap-dev.yml @@ -77,3 +77,7 @@ file: customer: # 跳过token验证和权限验证的url清单 skip-authenticate-urls: /gaeaDict/all, /login, /static, /file/download/, /index.html + user: + ##新增用户默认密码 + default: + password: 123456 diff --git a/report-core/src/main/resources/i18n/messages_en_US.properties b/report-core/src/main/resources/i18n/messages_en_US.properties index c2a9cedf..e0ac3965 100644 --- a/report-core/src/main/resources/i18n/messages_en_US.properties +++ b/report-core/src/main/resources/i18n/messages_en_US.properties @@ -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 diff --git a/report-core/src/main/resources/i18n/messages_zh_CN.properties b/report-core/src/main/resources/i18n/messages_zh_CN.properties index e68da4df..36ac0a42 100644 --- a/report-core/src/main/resources/i18n/messages_zh_CN.properties +++ b/report-core/src/main/resources/i18n/messages_zh_CN.properties @@ -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 diff --git a/report-ui/config/dev.env.js b/report-ui/config/dev.env.js index f50fc84e..ee3d90dc 100644 --- a/report-ui/config/dev.env.js +++ b/report-ui/config/dev.env.js @@ -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"' }) diff --git a/report-ui/src/api/login.js b/report-ui/src/api/login.js index 7f4eaf5f..4d97713e 100644 --- a/report-ui/src/api/login.js +++ b/report-ui/src/api/login.js @@ -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 + }) +} diff --git a/report-ui/src/views/accessUser/index.vue b/report-ui/src/views/accessUser/index.vue index aecfe41b..86baaf7f 100755 --- a/report-ui/src/views/accessUser/index.vue +++ b/report-ui/src/views/accessUser/index.vue @@ -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: '', diff --git a/report-ui/src/views/layout/components/Navbar.vue b/report-ui/src/views/layout/components/Navbar.vue index 37182b69..68fb26f2 100644 --- a/report-ui/src/views/layout/components/Navbar.vue +++ b/report-ui/src/views/layout/components/Navbar.vue @@ -15,6 +15,10 @@ + + 修改密码 + 注销登录 @@ -22,6 +26,32 @@ + + + + + + + + + + + + + + + + 取 消 + 确 定 + + @@ -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 }