add pass modify

This commit is contained in:
sobear 2024-05-15 23:29:38 +08:00
parent c3da2231e1
commit d351746543

View File

@ -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";
}
}