Bladeren bron

修复密码验证问题

leihy 2 jaren geleden
bovenliggende
commit
ccf815317e

+ 12 - 5
src/main/groovy/com/jd/brume/controller/UserController.groovy

@@ -1,5 +1,7 @@
 package com.jd.brume.controller
 
+import cn.hutool.core.codec.Base64
+
 import javax.annotation.Resource
 import javax.validation.constraints.NotNull
 
@@ -142,7 +144,7 @@ class UserController {
 	}
 
 	/**
-	 * 修改用户信息
+	 * 修改密码
 	 * @param userVo
 	 * @return
 	 */
@@ -150,25 +152,30 @@ class UserController {
 	def updatePwd(@Validated(UpdatePwdGroup) UserVo userVo) {
 		if (StrUtil.isNotBlank(userVo.password)) {
 			if (userVo.password != userVo.repeatPass) return new Result().msg(100, '密码输入不一致')
+			userVo.password = Base64.decodeStr(userVo.password);
 			userVo.password = SMUtil.sm2Encrypt(userVo.password)
 		}
 		if (StrUtil.isNotBlank(userVo.oldPass)) {
-			userVo.oldPass = SMUtil.sm2Encrypt(userVo.oldPass)
+			userVo.oldPass = Base64.decodeStr(userVo.oldPass);
+			def userEntity = userService.lambdaQuery().select(UserSelect.pwd).eq(UserFunc.userId(), userVo.userId).one();
+			def decrypt = SMUtil.sm2Decrypt(userEntity.getPassword())
+			if(!decrypt.equals(userVo.oldPass)){
+				return new Result().msg(100, '旧密码输入错误')
+			}
 		}
-		def count = userService.count(Wrappers.lambdaQuery().eq(UserFunc.userId(), userVo.userId).eq(UserFunc.password(), userVo.oldPass))
-		if (count < 1) return new Result().msg(100, '旧密码输入错误')
 
 		UserEntity user = new UserEntity(userId: userVo.userId, password: userVo.password)
 		return new Result().ok(userService.updateById(user))
 	}
 
 	/**
-	 * �޸��û���Ϣ
+	 * 修改手机号
 	 * @param userVo
 	 * @return
 	 */
 	@PostMapping('updateTel')
 	def updateTel(@Validated(UpdateTelGroup) UserVo userVo) {
+		userVo.phone = Base64.decodeStr(userVo.phone);
 		UserEntity user = new UserEntity(userId: userVo.userId, phone: userVo.phone)
 		return new Result().ok(userService.updateById(user))
 	}

+ 2 - 0
src/main/groovy/com/jd/brume/entity/resultmap/UserSelect.groovy

@@ -10,5 +10,7 @@ class UserSelect {
 	
 	static SFunction<?, ?>[] one = [UserFunc.userId(), UserFunc.userName(), UserFunc.account(), UserFunc.roleId(), UserFunc.deptId(),
 		 UserFunc.createTime(), UserFunc.phone()]
+
+	static SFunction<?, ?>[] pwd = [UserFunc.userId(), UserFunc.password()]
 	 
 }

+ 7 - 4
src/main/resources/static/web/js/index.js

@@ -72,9 +72,9 @@ layui.config({
 	form.on('submit(updatePwd)', (data) => {
 		layui.api.updatePwd({
 				userId : userId,
-				oldPass : data.field.oldPwd,
-				password : data.field.newPwd,
-				repeatPass : data.field.rePwd
+				oldPass : btoa(data.field.oldPwd),
+				password : btoa(data.field.newPwd),
+				repeatPass : btoa(data.field.rePwd)
 			},
 			(json) => {
 				if(json.code == constants.SUCCESS_CODE){
@@ -92,7 +92,7 @@ layui.config({
 	form.on('submit(updateTel)', (data) => {
 		layui.api.updateTel({
 				userId : userId,
-				phone : data.field.phone
+				phone : btoa(data.field.phone)
 			},
 			(json) => {
 				if(json.code == constants.SUCCESS_CODE){
@@ -213,6 +213,9 @@ layui.config({
 		//$(".layui-tab-title li:eq(0)").remove();
 
 		const menu = elem.data('menu');
+		if(!menu) {
+			return;
+		}
 		let has = false;
 		$(".layui-tab-title li").each((i,dom) => {
 			const layid = $(dom).attr("lay-id");