密码重置功能完成
Signed-off-by: Chenx221 <chenx221@yandex.com>
This commit is contained in:
parent
1da899ccf7
commit
d113a8c415
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -8,6 +8,11 @@
|
||||
FROM user
|
||||
WHERE username = #{username}
|
||||
</select>
|
||||
<select id="getUserById" parameterType="int" resultType="cyou.chenx221.pojo.User">
|
||||
SELECT *
|
||||
FROM user
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
<insert id="insertUser" parameterType="cyou.chenx221.pojo.User">
|
||||
INSERT INTO user (username, password)
|
||||
VALUES (#{username}, #{password})
|
||||
@ -20,4 +25,9 @@
|
||||
INSERT INTO user (username, password, roles, detail)
|
||||
VALUES (#{username}, #{password}, #{roles}, #{detail})
|
||||
</insert>
|
||||
<update id="updateUserPassword" parameterType="cyou.chenx221.pojo.User">
|
||||
UPDATE user
|
||||
SET password = #{password}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
</mapper>
|
||||
|
@ -261,7 +261,7 @@
|
||||
<div class="tab-pane fade" id="ex1-tabs-2" role="tabpanel"
|
||||
aria-labelledby="ex1-tab-2">
|
||||
<div class="card-body" style="min-width: 175px">
|
||||
<form action="" method="post">
|
||||
<form action="reset" method="post">
|
||||
<div class="row mb-2">
|
||||
<div class="col-12">
|
||||
<div class="form-outline">
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
@ -15,4 +15,8 @@ public interface UserMapper {
|
||||
|
||||
|
||||
int insertUserv2(User user);
|
||||
|
||||
User getUserById(int id);
|
||||
|
||||
int updateUserPassword(User user);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -8,6 +8,11 @@
|
||||
FROM user
|
||||
WHERE username = #{username}
|
||||
</select>
|
||||
<select id="getUserById" parameterType="int" resultType="cyou.chenx221.pojo.User">
|
||||
SELECT *
|
||||
FROM user
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
<insert id="insertUser" parameterType="cyou.chenx221.pojo.User">
|
||||
INSERT INTO user (username, password)
|
||||
VALUES (#{username}, #{password})
|
||||
@ -20,4 +25,9 @@
|
||||
INSERT INTO user (username, password, roles, detail)
|
||||
VALUES (#{username}, #{password}, #{roles}, #{detail})
|
||||
</insert>
|
||||
<update id="updateUserPassword" parameterType="cyou.chenx221.pojo.User">
|
||||
UPDATE user
|
||||
SET password = #{password}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
</mapper>
|
||||
|
@ -261,7 +261,7 @@
|
||||
<div class="tab-pane fade" id="ex1-tabs-2" role="tabpanel"
|
||||
aria-labelledby="ex1-tab-2">
|
||||
<div class="card-body" style="min-width: 175px">
|
||||
<form action="" method="post">
|
||||
<form action="reset" method="post">
|
||||
<div class="row mb-2">
|
||||
<div class="col-12">
|
||||
<div class="form-outline">
|
||||
|
Reference in New Issue
Block a user