From e16302f9d475c7cc4dd18c5abf1a23cb5502e362 Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq.com> Date: 星期三, 28 五月 2025 14:57:56 +0800 Subject: [PATCH] 密码验证加- --- src/main/java/com/whyc/controller/UserController.java | 56 +++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/whyc/controller/UserController.java b/src/main/java/com/whyc/controller/UserController.java index 56356e1..ee0f80a 100644 --- a/src/main/java/com/whyc/controller/UserController.java +++ b/src/main/java/com/whyc/controller/UserController.java @@ -21,7 +21,7 @@ @RequestMapping("user") @Api(tags = "鐢ㄦ埛绠$悊-鐢ㄦ埛") @Slf4j -public class UserController { +public class UserController extends BaseController{ @Resource private UserService userService; @@ -61,16 +61,19 @@ return new Response().set(1,userService.getAllWithPage(pageNum,pageSize)); } - @PutMapping + @PostMapping("update") @ApiOperation(value = "缂栬緫") public Response update(@RequestBody UserInf user){ return userService.update(user); } - @DeleteMapping + @PostMapping("delete") @ApiOperation(value = "鍒犻櫎") public Response delete(@RequestParam int id){ - userService.delete(id); + boolean deleteFlag = userService.delete(id); + if (!deleteFlag){ + return new Response().setII(0,"鍒犻櫎澶辫触,褰撳墠鐢ㄦ埛娌℃湁鐢ㄦ埛缂栬緫鏉冮檺"); + } return new Response().setII(1,"鍒犻櫎鎴愬姛"); } @GetMapping("/searchUKeyToUName") @@ -88,17 +91,17 @@ @GetMapping("/searchUNameToUKey") @ApiOperation(value = "鏍规嵁鐢ㄦ埛鍚嶆煡缁戝畾鐨刄key") - public Response getUserByUserName(@RequestParam String uKeyId){ - UserInf userInf = userService.getUserByUKeyId(uKeyId); + public Response getUserByUserName(@RequestParam String userName){ + UserInf userInf = userService.getUserByUserName(userName); Response response = new Response(); if (userInf!=null){ if (StringUtils.isEmpty(userInf.getUkeyId())){ - response.set(0,"璇ョ敤鎴锋病鏈夌粦瀹歎key"); + response.set(-1,false,"璇ョ敤鎴锋病鏈夌粦瀹歎key"); }else { - response.set(1,userInf); + response.setII(1,true,userInf,"璇ョ敤鎴锋湁缁戝畾Ukey"); } }else{ - response.set(0,"璇ョ敤鎴蜂笉瀛樺湪"); + response.set(0,false,"璇ョ敤鎴蜂笉瀛樺湪"); } return response; } @@ -135,11 +138,12 @@ public Response checkUserPasswordOfREA(@RequestParam String pwd){ UserInf userInf = ActionUtil.getUser(); String passwordEncrypt = null; - try { + /*try { passwordEncrypt = URLDecoder.decode(pwd, "utf-8"); }catch (UnsupportedEncodingException e){ e.printStackTrace(); - } + }*/ + passwordEncrypt = pwd; String password = RSAUtil.decryptFront(passwordEncrypt, RSAUtil.fontSeparator)[0]; String passwordDB = RSAUtil.decrypt(userInf.getUpassword(),RSAUtil.getPrivateKey()); if(passwordDB.equals(password)){ @@ -148,7 +152,19 @@ return new Response().set(0); } } - + @GetMapping("/checkAndUpdatePasswordByRSA") + @ApiOperation(value = "妫�鏌ュ苟淇敼鐢ㄦ埛RSA瀵嗙爜") + public Response checkAndUpdatePasswordByRSA(@RequestParam String oldPwd,@RequestParam String newPwd){ + UserInf userInf = ActionUtil.getUser(); + String passwordEncrypt = oldPwd; + String password = RSAUtil.decryptFront(passwordEncrypt, RSAUtil.fontSeparator)[0]; + String passwordDB = RSAUtil.decrypt(userInf.getUpassword(),RSAUtil.getPrivateKey()); + if(passwordDB.equals(password)){ + return userService.updatePasswordByRSA(userInf,newPwd); + }else { + return new Response().set(0,false,"鍘熷瘑鐮佷笉姝g‘"); + } + } @PostMapping("/updatePassword") @ApiOperation(value = "淇敼瀵嗙爜") @@ -164,11 +180,17 @@ return userService.updatePasswordByRSA(userInf,password); } + @GetMapping("updatePasswordByValidity") + @ApiOperation(value = "淇敼瀵嗙爜-瀵嗙爜澶辨晥") + public Response updatePasswordByValidity(@RequestParam String uname,@RequestParam String oldPwd,@RequestParam String newPwd) throws UnsupportedEncodingException { + return userService.updatePasswordByValidity(uname,oldPwd,newPwd); + } + /** * 1.棣栨鐧诲綍,璇峰厛淇敼鍒濆鍖栧彛浠� * 2.瓒呰繃3涓湀娌℃湁淇敼鍙d护,璇蜂慨鏀瑰彛浠ゅ悗閲嶆柊鐧诲綍 */ - @PutMapping("updatePassword2") + @PostMapping("updatePassword2") @ApiOperation(value = "淇敼瀵嗙爜-3涓湀鏈櫥褰�") public Response updatePassword2(@RequestParam String passwordOld,String passwordNew){ //鏍¢獙鑰佸瘑鐮� @@ -207,7 +229,7 @@ * 璐﹀彿瑙i攣 */ @ApiOperation(value = "璐﹀彿瑙i攣",notes = "unLockType=1涓哄け璐ラ攣瀹氳В閿�,2涓轰笂涓湀鏈櫥褰曢攣瀹氳В閿�") - @PutMapping("unLock") + @PostMapping("unLock") public Response unLock(@RequestParam int uId,@RequestParam int unLockType){ userService.unLock(uId,unLockType); return new Response().setII(1,"瑙i攣鎴愬姛"); @@ -235,6 +257,10 @@ return new Response().set(1,list); } - + @ApiOperation(value = "浼崟鐐圭櫥褰�",notes = "杩斿洖鐨刣ata涓哄竷灏斿��,鏄惁鐧诲綍鎴愬姛;data2:鐢ㄦ埛鎵�鍦ㄧ殑鏉冮檺缁刬d;data3涓虹敤鎴峰璞�,鍐呭惈灞炴�id,uname,urole") + @GetMapping("loginByUId") + public Response searchSnIdByUId(@RequestParam int uId){ + return userService.loginByUId(uId); + } } -- Gitblit v1.9.1