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 5a98f97..a6ab7dc 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/UserController.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/UserController.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/UserMapper.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/UserMapper.class index e3b3425..7493dde 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/UserMapper.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/UserMapper.class differ 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 a52f3ba..c083d54 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/User.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/User.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/UserMapper.xml b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/UserMapper.xml index 618d1bf..cf40312 100644 --- a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/mapper/UserMapper.xml +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/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/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 @@
- +