From d113a8c41589d07d3a875f04ea2e625865687221 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Thu, 15 Jun 2023 11:36:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=86=E7=A0=81=E9=87=8D=E7=BD=AE=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chenx221 --- .../chenx221/controller/UserController.class | Bin 6176 -> 7035 bytes .../cyou/chenx221/mapper/UserMapper.class | Bin 496 -> 578 bytes .../classes/cyou/chenx221/pojo/User.class | Bin 2398 -> 2544 bytes .../WEB-INF/classes/mapper/UserMapper.xml | 10 ++++++ .../WEB-INF/views/usermanage.jsp | 2 +- .../chenx221/controller/UserController.java | 30 +++++++++++++++++- .../java/cyou/chenx221/mapper/UserMapper.java | 4 +++ .../main/java/cyou/chenx221/pojo/User.java | 5 +++ .../src/main/resources/mapper/UserMapper.xml | 10 ++++++ project2/web/WEB-INF/views/usermanage.jsp | 2 +- 10 files changed, 60 insertions(+), 3 deletions(-) diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/UserController.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/UserController.class index 5a98f97e2d98c3fe00c51ed5789613e11e1d73ab..a6ab7dc3729e66ab24e302eda1caff29194923b3 100644 GIT binary patch delta 1801 zcmaJ>ZBSHY6n@_Qy36jeG?x!sAx4764W+GVw1!fg1ZQ?e#%go`X`0!Im9dPRU99X! zTMaH&Qq~0_vI2voOo2d_54AGOB+WkTyDXChtY(_&S2HnA&wKX+Y#M&-z0W!KocBEE zJnz|#8~<5u8^1hy48RKf(Qn(W=?exQc_>h0#ft)Yml~UxG8$DExNZS$#im0-}Espx}%$X1svYGI)7mG7IN|j6-;ZD&O*~~ z0=ZhXGgs?!=7d_PfdvA4;%~EVwbJs?EBH1SMj-kL3}}l70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AuWRd3m)`^U6S}Y|&T^QfB;L7N-_DReGi{GRSCnPRy4P7Ah@BNi0bP zi3cPW7nkQ3rA&5W%x7eqyopgmjfIhcpFx0u0Z0on@Bz(YVh{q8!VDrnnvH>xL6m_3 E0JSw2bpQYW delta 52 zcmX@a@`0J_)W2Q(7#J9A8H6`-Susv-W6Wh_nf!%OLyUomfgdQr#2~;R2&CB<7#V~Z F7yy6U3F!a; diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/User.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/User.class index a52f3baab9661511ce6354af89254d9efba01a3a..c083d540b70e893a71c6e2b1bf2c62a868ca5d0f 100644 GIT binary patch delta 240 zcmca7^g)>G)W2Q(7#J9A8C*7UJz`?in7n~WZSo7I3+%!Sj0{Q)%9Ag02yec`Jdc@C zesUqZrKlo<98iLRfuBK~L4<(`$mVCTo*coh$Lqwv!r;un$>74k$KX17GP@?T4TBL# zyO8__pav!eRUpX**6cBP1FI;b?c`tV>a0EttPH-B*K>$Zw&mbpw3~dMLv(U9hah7B zSdIPU32b7MXL1O#h5*%t0@cYgIsnzEF-Cyp9YOM9q8s5BZ~-l1V2A-Kjs+X)&&k2= I1eSFM0A#r_z5oCK delta 181 zcmew$d{2n$)W2Q(7#J9A8JstAJz| + INSERT INTO user (username, password) VALUES (#{username}, #{password}) @@ -20,4 +25,9 @@ INSERT INTO user (username, password, roles, detail) VALUES (#{username}, #{password}, #{roles}, #{detail}) + + UPDATE user + SET password = #{password} + WHERE id = #{id} + diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/usermanage.jsp b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/usermanage.jsp index 4a27629..42db1a2 100644 --- a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/usermanage.jsp +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/usermanage.jsp @@ -261,7 +261,7 @@
-
+
diff --git a/project2/src/main/java/cyou/chenx221/controller/UserController.java b/project2/src/main/java/cyou/chenx221/controller/UserController.java index 4d4696a..07f2754 100644 --- a/project2/src/main/java/cyou/chenx221/controller/UserController.java +++ b/project2/src/main/java/cyou/chenx221/controller/UserController.java @@ -136,7 +136,7 @@ public class UserController { // start to create Password pw = new Password(password); System.out.println("username:" + username + " password:" + pw.getEncryptedPassword() + " role:" + role + " roleid:" + roleid); //debug - user = new User(username, pw.getEncryptedPassword(), role, (roleid==-1?null:roleid)); + user = new User(username, pw.getEncryptedPassword(), role, (roleid == -1 ? null : roleid)); int status_code = userMapper.insertUserv2(user); if (status_code == 0) { model.addAttribute("errorMessage", "创建用户失败,请重试。"); @@ -150,4 +150,32 @@ public class UserController { return "redirect:/user/usermanage"; } } + + @RequestMapping(path = "/user/reset", method = {RequestMethod.POST}) + public String resetpassword(@RequestParam("id") int id, + @RequestParam("password") String password, + @RequestParam("re_password") String repassword, + Model model) throws NoSuchAlgorithmException { + //check password + if (!password.equals(repassword)) { + model.addAttribute("errorMessage", "两次输入的密码不一致,请重新输入。"); + return "redirect:/user/usermanage"; + } + //check if user exists + User user = userMapper.getUserById(id); + if (user == null) { + model.addAttribute("errorMessage", "ID为" + id + "的用户不存在,请重新输入。"); + return "redirect:/user/usermanage"; + } else { + Password pw = new Password(password); + User user1 = new User(id, pw.getEncryptedPassword()); + int status_code = userMapper.updateUserPassword(user1); + if (status_code == 0) { + model.addAttribute("errorMessage", "重置密码失败,请重试。"); + } else { + model.addAttribute("successMessage", "重置密码成功"); + } + } + return "redirect:/user/usermanage"; + } } diff --git a/project2/src/main/java/cyou/chenx221/mapper/UserMapper.java b/project2/src/main/java/cyou/chenx221/mapper/UserMapper.java index ea54969..7bc7874 100644 --- a/project2/src/main/java/cyou/chenx221/mapper/UserMapper.java +++ b/project2/src/main/java/cyou/chenx221/mapper/UserMapper.java @@ -15,4 +15,8 @@ public interface UserMapper { int insertUserv2(User user); + + User getUserById(int id); + + int updateUserPassword(User user); } diff --git a/project2/src/main/java/cyou/chenx221/pojo/User.java b/project2/src/main/java/cyou/chenx221/pojo/User.java index bb4b97a..44425a6 100644 --- a/project2/src/main/java/cyou/chenx221/pojo/User.java +++ b/project2/src/main/java/cyou/chenx221/pojo/User.java @@ -58,6 +58,11 @@ public class User { this.password = password; } + public User(Integer id, String password) { + this.id = id; + this.password = password; + } + public User(String username, String password) { this.username = username; this.password = password; diff --git a/project2/src/main/resources/mapper/UserMapper.xml b/project2/src/main/resources/mapper/UserMapper.xml index 618d1bf..cf40312 100644 --- a/project2/src/main/resources/mapper/UserMapper.xml +++ b/project2/src/main/resources/mapper/UserMapper.xml @@ -8,6 +8,11 @@ FROM user WHERE username = #{username} + INSERT INTO user (username, password) VALUES (#{username}, #{password}) @@ -20,4 +25,9 @@ INSERT INTO user (username, password, roles, detail) VALUES (#{username}, #{password}, #{roles}, #{detail}) + + UPDATE user + SET password = #{password} + WHERE id = #{id} + diff --git a/project2/web/WEB-INF/views/usermanage.jsp b/project2/web/WEB-INF/views/usermanage.jsp index 4a27629..42db1a2 100644 --- a/project2/web/WEB-INF/views/usermanage.jsp +++ b/project2/web/WEB-INF/views/usermanage.jsp @@ -261,7 +261,7 @@
- +