diff --git a/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminPassController.java b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminPassController.java
new file mode 100644
index 0000000..6925108
--- /dev/null
+++ b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminPassController.java
@@ -0,0 +1,61 @@
+package cn.edu.cqwu.repair.controller.admin;
+
+import cn.edu.cqwu.repair.dao.AdminUserDao;
+import cn.edu.cqwu.repair.entity.AdminUser;
+import cn.edu.cqwu.repair.util.Encrypt;
+import cn.edu.cqwu.repair.util.Verify;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.SessionAttribute;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+/**
+ * @author xtaod
+ */
+@Controller
+public class AdminPassController {
+ AdminUserDao adminUserDao;
+
+ @Autowired
+ public AdminPassController(AdminUserDao adminUserDao) {
+ this.adminUserDao = adminUserDao;
+ }
+
+ @RequestMapping("/admin/pass.do")
+ public String pass(
+ @SessionAttribute AdminUser adminUser,
+ String oldPassword,
+ String password,
+ String confirmpass,
+ String code,
+ HttpSession session,
+ HttpServletRequest request,
+ Model model
+ ) {
+ String username = adminUser.getAdminName();
+ String mess = Verify.validateForm1(username, oldPassword, password, confirmpass, code);
+ if (!mess.isEmpty()) {
+ model.addAttribute("adminPassMess", mess);
+ return "/admin/pass";
+ }
+ if (!Verify.verifyCode(session, code)) {
+ model.addAttribute("adminPassMess", "* 验证码错误!");
+ return "/admin/pass";
+ }
+ AdminUser byUsername = adminUserDao.validateLogin(username, Encrypt.SHA(oldPassword));
+ if (byUsername == null) {
+ model.addAttribute("adminPassMess", "* 旧密码错误!");
+ return "/admin/pass";
+ }
+ if (adminUserDao.passModify(username, Encrypt.SHA(password)) == 1) {
+ request.setAttribute("adminPassMess", "* 修改成功!");
+ } else {
+ request.setAttribute("adminPassMess", "* 修改失败!");
+ }
+ return "/admin/pass";
+ }
+}
diff --git a/src/main/java/cn/edu/cqwu/repair/util/Verify.java b/src/main/java/cn/edu/cqwu/repair/util/Verify.java
index 0139df0..91fae50 100644
--- a/src/main/java/cn/edu/cqwu/repair/util/Verify.java
+++ b/src/main/java/cn/edu/cqwu/repair/util/Verify.java
@@ -23,9 +23,9 @@ public class Verify {
}
public static String validateForm1(String username, String oldPasswrd, String password, String confirmpass, String code) {
- if (username == null || !username.matches("\\w{6,20}")) {
+ if (username == null || !username.matches("\\w{5,20}")) {
return "* 用户名不合法!";
- } else if (password == null || !password.matches("\\w{6,20}")) {
+ } else if (password == null || !password.matches("\\w{5,20}")) {
return "* 密码不合法!";
} else if (password.equals(oldPasswrd)) {
return "* 新密码不能与旧密码相同!";
@@ -41,9 +41,9 @@ public class Verify {
if (stuNo == null || !stuNo.matches("\\d{12}")) {
return "* 学号不合法!";
}
- if (username == null || !username.matches("\\w{6,20}")) {
+ if (username == null || !username.matches("\\w{5,20}")) {
return "* 用户名不合法!";
- } else if (password == null || !password.matches("\\w{6,20}")) {
+ } else if (password == null || !password.matches("\\w{5,20}")) {
return "* 密码不合法!";
} else if (!password.equals(confirmpass)) {
return "* 两次输入的密码不一致,请重新输入!";
diff --git a/src/main/webapp/admin/pass.jsp b/src/main/webapp/admin/pass.jsp
new file mode 100644
index 0000000..1801025
--- /dev/null
+++ b/src/main/webapp/admin/pass.jsp
@@ -0,0 +1,69 @@
+<%--
+ Created by IntelliJ IDEA.
+ User: xtaod
+ Date: 2024/5/16
+ Time: 上午8:29
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ page isELIgnored="false" %>
+