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/dao/impl/DeviceDaoImpl.java b/src/main/java/cn/edu/cqwu/repair/dao/impl/DeviceDaoImpl.java index 72501fc..acd6c76 100644 --- a/src/main/java/cn/edu/cqwu/repair/dao/impl/DeviceDaoImpl.java +++ b/src/main/java/cn/edu/cqwu/repair/dao/impl/DeviceDaoImpl.java @@ -16,13 +16,8 @@ import java.util.ArrayList; public class DeviceDaoImpl implements DeviceDao { private static final DeviceMapper mapper = ConnectionFactory.getMapper(DeviceMapper.class); - @Override public ArrayList findAllDevice() { - - return (ArrayList) mapper.selectAll(); } - - } diff --git a/src/main/java/cn/edu/cqwu/repair/listener/MyServletContextListener.java b/src/main/java/cn/edu/cqwu/repair/listener/MyServletContextListener.java new file mode 100644 index 0000000..0c92750 --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/listener/MyServletContextListener.java @@ -0,0 +1,34 @@ +package cn.edu.cqwu.repair.listener; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; + +import cn.edu.cqwu.repair.dao.DeviceDao; +import cn.edu.cqwu.repair.util.AppInit; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + + +/** + * @author xtaod + */ +@WebListener +public class MyServletContextListener extends AppInit implements ServletContextListener { + + @Override + public void contextInitialized(ServletContextEvent sce) { + ServletContext application = sce.getServletContext(); + WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(application); + if (context != null) { + DeviceDao deviceDao = context.getBean(DeviceDao.class); + initDevice(application, deviceDao); + } + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + + } +} diff --git a/src/main/java/cn/edu/cqwu/repair/util/AppInit.java b/src/main/java/cn/edu/cqwu/repair/util/AppInit.java new file mode 100644 index 0000000..d3492f9 --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/util/AppInit.java @@ -0,0 +1,14 @@ +package cn.edu.cqwu.repair.util; + +import cn.edu.cqwu.repair.dao.DeviceDao; + +import javax.servlet.ServletContext; + +/** + * @author xtaod + */ +public class AppInit { + public static void initDevice(ServletContext servletContext, DeviceDao deviceDao) { + servletContext.setAttribute("device", deviceDao.findAllDevice()); + } +} 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}