From d35174654360f7279e65f46c7147ee1729e903b1 Mon Sep 17 00:00:00 2001 From: sobear <410731299@qq.com> Date: Wed, 15 May 2024 23:29:38 +0800 Subject: [PATCH] add pass modify --- .../worker/WorkerPassModifyController.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/main/java/cn/edu/cqwu/repair/controller/worker/WorkerPassModifyController.java diff --git a/src/main/java/cn/edu/cqwu/repair/controller/worker/WorkerPassModifyController.java b/src/main/java/cn/edu/cqwu/repair/controller/worker/WorkerPassModifyController.java new file mode 100644 index 0000000..11fcf0a --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/controller/worker/WorkerPassModifyController.java @@ -0,0 +1,63 @@ +package cn.edu.cqwu.repair.controller.worker; + + +import cn.edu.cqwu.repair.dao.WorkerDao; + +import javax.servlet.http.*; + +import cn.edu.cqwu.repair.entity.Worker; +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; + +/** + * @author sobear + */ +@Controller +public class WorkerPassModifyController { + private final WorkerDao workerDao; + + + @Autowired + public WorkerPassModifyController(WorkerDao workerDao) { + this.workerDao = workerDao; + } + + @RequestMapping("/worker/pass.do") + public String pass( + @SessionAttribute Worker workerUser, + String oldPassword, + String password, + String confirmpass, + String code, + HttpSession session, + HttpServletRequest request, + Model model + ) { + String username = workerUser.getUsername(); + String mess = Verify.validateForm1(username, oldPassword, password, confirmpass, code); + if (!mess.isEmpty()) { + model.addAttribute("workerPassMess", mess); + return "/worker/worker_modify"; + } + if (!Verify.verifyCode(session, code)) { + model.addAttribute("workerPassMess", "* 验证码错误!"); + return "/worker/worker_modify"; + } + Worker byUsername = workerDao.validateLogin(username, Encrypt.SHA(oldPassword)); + if (byUsername == null) { + model.addAttribute("workerPassMess", "* 旧密码错误!"); + return "/worker/worker_modify"; + } + if (workerDao.passModify(username, Encrypt.SHA(password)) == 1) { + request.setAttribute("workerPassMess", "* 修改成功!"); + } else { + request.setAttribute("workerPassMess", "* 修改失败!"); + } + return "/worker/worker_modify"; + } +}