From 79d16918be64767c96ab4f2703820a09a9beea0c Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sun, 12 May 2024 22:57:54 +0800 Subject: [PATCH 1/2] feat: stu edit pass and get record --- .../controller/stu/StuLoginController.java | 2 +- .../controller/stu/StuPassController.java | 61 ++++++++++++++++ .../controller/stu/StuRecordController.java | 44 ++++++++++++ .../java/cn/edu/cqwu/repair/util/Verify.java | 15 ++++ src/main/webapp/includes/dropdown.jsp | 2 +- src/main/webapp/index.jsp | 6 +- src/main/webapp/register.jsp | 6 +- src/main/webapp/stu/main.jsp | 34 +++++++++ src/main/webapp/stu/pass.jsp | 69 +++++++++++++++++++ src/main/webapp/stu/record.jsp | 60 ++++++++++++++++ src/main/webapp/worker_login.jsp | 7 -- 11 files changed, 291 insertions(+), 15 deletions(-) create mode 100644 src/main/java/cn/edu/cqwu/repair/controller/stu/StuPassController.java create mode 100644 src/main/java/cn/edu/cqwu/repair/controller/stu/StuRecordController.java create mode 100644 src/main/webapp/stu/main.jsp create mode 100644 src/main/webapp/stu/pass.jsp create mode 100644 src/main/webapp/stu/record.jsp diff --git a/src/main/java/cn/edu/cqwu/repair/controller/stu/StuLoginController.java b/src/main/java/cn/edu/cqwu/repair/controller/stu/StuLoginController.java index cbd9f0e..a031895 100644 --- a/src/main/java/cn/edu/cqwu/repair/controller/stu/StuLoginController.java +++ b/src/main/java/cn/edu/cqwu/repair/controller/stu/StuLoginController.java @@ -46,7 +46,7 @@ public class StuLoginController { } if (recordService.add(user, request.getRemoteAddr()) != 0) { session.setAttribute("stu", user); - return "redirect:/stu/edit"; + return "redirect:/stu/main.jsp"; } else { model.addAttribute("stuLoginMess", "* 登录异常!"); return "index"; diff --git a/src/main/java/cn/edu/cqwu/repair/controller/stu/StuPassController.java b/src/main/java/cn/edu/cqwu/repair/controller/stu/StuPassController.java new file mode 100644 index 0000000..6a1c2fe --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/controller/stu/StuPassController.java @@ -0,0 +1,61 @@ +package cn.edu.cqwu.repair.controller.stu; + +import cn.edu.cqwu.repair.dao.StuDao; +import cn.edu.cqwu.repair.entity.Stu; +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 StuPassController { + StuDao stuDao; + + @Autowired + public StuPassController(StuDao stuDao) { + this.stuDao = stuDao; + } + + @RequestMapping("/stu/pass.do") + public String pass( + @SessionAttribute Stu stu, + String oldPassword, + String password, + String confirmpass, + String code, + HttpSession session, + HttpServletRequest request, + Model model + ) { + String username = stu.getUsername(); + String mess = Verify.validateForm1(username, oldPassword, password, confirmpass, code); + if (!mess.isEmpty()) { + model.addAttribute("stuPassMess", mess); + return "/stu/pass"; + } + if (!Verify.verifyCode(session, code)) { + model.addAttribute("stuPassMess", "* 验证码错误!"); + return "/stu/pass"; + } + Stu byUsername = stuDao.validateLogin(username, Encrypt.SHA(oldPassword)); + if (byUsername == null) { + model.addAttribute("stuPassMess", "* 旧密码错误!"); + return "/stu/pass"; + } + if (stuDao.passModify(username, Encrypt.SHA(password)) == 1) { + request.setAttribute("stuPassMess", "* 修改成功!"); + } else { + request.setAttribute("stuPassMess", "* 修改失败!"); + } + return "/stu/pass"; + } +} diff --git a/src/main/java/cn/edu/cqwu/repair/controller/stu/StuRecordController.java b/src/main/java/cn/edu/cqwu/repair/controller/stu/StuRecordController.java new file mode 100644 index 0000000..cc67a10 --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/controller/stu/StuRecordController.java @@ -0,0 +1,44 @@ +package cn.edu.cqwu.repair.controller.stu; + +import cn.edu.cqwu.repair.dao.StuDao; +import cn.edu.cqwu.repair.entity.Stu; +import cn.edu.cqwu.repair.service.RecordService; +import cn.edu.cqwu.repair.util.PageModel; +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; + +/** + * @author xtaod + */ +@Controller +public class StuRecordController { + StuDao stuDao; + RecordService recordService; + + @Autowired + public StuRecordController(StuDao stuDao, RecordService recordService) { + this.stuDao = stuDao; + this.recordService = recordService; + } + + @RequestMapping("/stu/record.do") + public String record(@SessionAttribute Stu stu, Model model, HttpServletRequest request) { + String pageNoS = request.getParameter("pageNo"); + int pageNo = 1; + try { + pageNo = Integer.parseInt(pageNoS); + } catch (NumberFormatException ignored) { + } + PageModel pm = recordService.pageByLogname( + stu.getUsername(), "用户", 10, pageNo + ); + pm.setPageNav("record.do"); + model.addAttribute("pm", pm); + return "/stu/record"; + } +} 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 31e9c18..0139df0 100644 --- a/src/main/java/cn/edu/cqwu/repair/util/Verify.java +++ b/src/main/java/cn/edu/cqwu/repair/util/Verify.java @@ -22,6 +22,21 @@ public class Verify { return ""; } + public static String validateForm1(String username, String oldPasswrd, String password, String confirmpass, String code) { + if (username == null || !username.matches("\\w{6,20}")) { + return "* 用户名不合法!"; + } else if (password == null || !password.matches("\\w{6,20}")) { + return "* 密码不合法!"; + } else if (password.equals(oldPasswrd)) { + return "* 新密码不能与旧密码相同!"; + } else if (!password.equals(confirmpass)) { + return "* 两次输入的密码不一致,请重新输入!"; + } else if (code == null || !code.matches("\\d{4}")) { + return "* 验证码错误!"; + } + return ""; + } + public static String validateForm(String stuNo, String username, String password, String confirmpass, String code) { if (stuNo == null || !stuNo.matches("\\d{12}")) { return "* 学号不合法!"; diff --git a/src/main/webapp/includes/dropdown.jsp b/src/main/webapp/includes/dropdown.jsp index 07c135a..51d68d6 100644 --- a/src/main/webapp/includes/dropdown.jsp +++ b/src/main/webapp/includes/dropdown.jsp @@ -22,7 +22,7 @@ ${sessionScope.stu.username}