diff --git a/.idea/misc.xml b/.idea/misc.xml
index a57100a..132404b 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -7,9 +7,8 @@
-
-
+
\ No newline at end of file
diff --git a/src/main/java/cn/edu/cqwu/repair/controller/StuController.java b/src/main/java/cn/edu/cqwu/repair/controller/StuController.java
deleted file mode 100644
index 3b05f6b..0000000
--- a/src/main/java/cn/edu/cqwu/repair/controller/StuController.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package cn.edu.cqwu.repair.controller;
-
-import cn.edu.cqwu.repair.dao.StuDao;
-import cn.edu.cqwu.repair.entity.Stu;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.SessionAttribute;
-
-import javax.servlet.http.HttpServletRequest;
-
-@Controller
-public class StuController {
-
-//
-// @Resource
-// private StudentService studentService;
-//
-// @Resource
-// private RepairService repairService;
-//
-// @Resource
-// private UrgentRepairService urgentRepairService;
-
- @Autowired
- StuDao stuDao;
-
- @PostMapping("/sturegist.do")
- public String Register(String userNo, String username, String password , HttpServletRequest request){
- Stu byUsername = stuDao.findByUsername(username);
- if(byUsername==null) {
- Stu stu = new Stu();
- stu.setUserNo(userNo);
- stu.setUsername(username);
- stu.setPassword(password);
- stu.setStatus(0);
- String localAddr = request.getLocalAddr();
- stu.setRegip(localAddr);
- int add = stuDao.add(stu);
- if(add==1) {
- request.setAttribute("stuRegistMess", "注册成功");
- return "redirect:/student/index.jsp";
- }
- request.setAttribute("stuRegistMess", "注册失败");
- return "/student/register";
-
- }else{
- return "/student/register";
- }
-
-}
-
-
-
-@PostMapping("/stulogin.do")
-public String login( String username, String password, HttpServletRequest request){
-
- Stu stu = stuDao.validateLogin(username, password);
- if(stu!=null) {
- request.getSession().setAttribute("stu", stu);
- request.setAttribute("stuLoginMess","登陆成功");
- return "/student/edit";
- }else{
- request.setAttribute("stuLoginMess","登陆失败");
-
- return "index";
- }
-}
-
-
- @RequestMapping("/stueditpassword.do")
- public String edit(String password, String oldpassword,HttpServletRequest request, @SessionAttribute Stu stu){
- if(oldpassword.equals(stu.getPassword())) {
- int i = stuDao.passModify(stu.getUsername(), password);
- if(i!=0) {
- stu.setPassword(password);
- request.getSession().setAttribute("student", stu);
- request.setAttribute("stuEditMess","修改成功");
-
- return "/student/edit";
- }else{
- request.setAttribute("stuEditMess","修改失败");
-
- return "/student/edit";
- }
- }
- request.setAttribute("stuEditMess","修改失败");
- return "/student/edit";
-
- }
-
-
-
-
-
-
-
-}
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
new file mode 100644
index 0000000..7bfc152
--- /dev/null
+++ b/src/main/java/cn/edu/cqwu/repair/controller/stu/StuLoginController.java
@@ -0,0 +1,55 @@
+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.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.PostMapping;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+/**
+ * @author wobeitaoleshigexuruo
+ */
+@Controller
+public class StuLoginController {
+ StuDao stuDao;
+ RecordService recordService;
+
+ @Autowired
+ public StuLoginController(StuDao stuDao, RecordService recordService) {
+ this.stuDao = stuDao;
+ this.recordService = recordService;
+ }
+
+ @PostMapping("/stu/login.do")
+ public String login(String username, String password, String code, Model model, HttpSession session,
+ HttpServletRequest request){
+ String mess = Verify.validateForm(username, password, code);
+ if (!mess.isEmpty()) {
+ model.addAttribute("stuLoginMess", mess);
+ return "index";
+ }
+ if (!Verify.verifyCode(session, code)) {
+ model.addAttribute("stuLoginMess", "* 验证码错误!");
+ return "index";
+ }
+ Stu user = stuDao.validateLogin(username, Encrypt.SHA(password));
+ if (user == null) {
+ model.addAttribute("stuLoginMess", "* 用户名或密码输入错误!");
+ return "index";
+ }
+ if (recordService.add(user, request.getRemoteAddr()) != 0) {
+ session.setAttribute("stu", user);
+ return "redirect:/stu/edit";
+ } else {
+ model.addAttribute("stuLoginMess", "* 登录异常!");
+ return "index";
+ }
+ }
+}
diff --git a/src/main/java/cn/edu/cqwu/repair/controller/stu/StuRegController.java b/src/main/java/cn/edu/cqwu/repair/controller/stu/StuRegController.java
new file mode 100644
index 0000000..b314357
--- /dev/null
+++ b/src/main/java/cn/edu/cqwu/repair/controller/stu/StuRegController.java
@@ -0,0 +1,47 @@
+package cn.edu.cqwu.repair.controller.stu;
+
+import cn.edu.cqwu.repair.dao.StuDao;
+import cn.edu.cqwu.repair.entity.Stu;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PostMapping;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * @author xtaod
+ */
+@Controller
+public class StuRegController {
+ StuDao stuDao;
+
+ @Autowired
+ public StuRegController(StuDao stuDao) {
+ this.stuDao = stuDao;
+ }
+
+ @PostMapping("/stu/regist.do")
+ public String reg(String userNo, String username, String password , HttpServletRequest request){
+ Stu byUsername = stuDao.findByUsername(username);
+ if(byUsername==null) {
+ Stu stu = new Stu();
+ stu.setUserNo(userNo);
+ stu.setUsername(username);
+ stu.setPassword(password);
+ stu.setStatus(0);
+ String localAddr = request.getLocalAddr();
+ stu.setRegip(localAddr);
+ int add = stuDao.add(stu);
+ if(add==1) {
+ request.setAttribute("stuRegistMess", "注册成功");
+ return "redirect:/student/index.jsp";
+ }
+ request.setAttribute("stuRegistMess", "注册失败");
+ return "/student/register";
+
+ }else{
+ return "/student/register";
+ }
+
+ }
+}
diff --git a/src/main/java/cn/edu/cqwu/repair/controller/worker/WorkerLoginController.java b/src/main/java/cn/edu/cqwu/repair/controller/worker/WorkerLoginController.java
index 2fe3344..3479f52 100644
--- a/src/main/java/cn/edu/cqwu/repair/controller/worker/WorkerLoginController.java
+++ b/src/main/java/cn/edu/cqwu/repair/controller/worker/WorkerLoginController.java
@@ -14,6 +14,9 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
+/**
+ * @author sobear
+ */
@Controller
public class WorkerLoginController {
private final WorkerDao workerDao;
@@ -39,7 +42,7 @@ public class WorkerLoginController {
model.addAttribute("workerLoginMess", "* 验证码错误!");
return "/worker_login";
}
- Worker user = workerDao.validateLogin(username, password);
+ Worker user = workerDao.validateLogin(username, Encrypt.SHA(password));
if (user == null) {
model.addAttribute("workerLoginMess", "* 用户名或密码输入错误!");
return "/worker_login";
@@ -52,6 +55,4 @@ public class WorkerLoginController {
return "/worker_login";
}
}
-
-
}
diff --git a/src/main/java/cn/edu/cqwu/repair/service/RecordService.java b/src/main/java/cn/edu/cqwu/repair/service/RecordService.java
index d4c7d44..5aba486 100644
--- a/src/main/java/cn/edu/cqwu/repair/service/RecordService.java
+++ b/src/main/java/cn/edu/cqwu/repair/service/RecordService.java
@@ -1,6 +1,7 @@
package cn.edu.cqwu.repair.service;
import cn.edu.cqwu.repair.entity.AdminUser;
+import cn.edu.cqwu.repair.entity.Stu;
import cn.edu.cqwu.repair.entity.Worker;
import cn.edu.cqwu.repair.util.PageModel;
@@ -9,4 +10,6 @@ public interface RecordService {
int add(Worker user, String ip);
PageModel pageByLogname(String logname, String group, int pageSize, int pageNo);
+
+ int add(Stu user, String remoteAddr);
}
diff --git a/src/main/java/cn/edu/cqwu/repair/service/impl/RecordServiceImpl.java b/src/main/java/cn/edu/cqwu/repair/service/impl/RecordServiceImpl.java
index 4402557..d1a13be 100644
--- a/src/main/java/cn/edu/cqwu/repair/service/impl/RecordServiceImpl.java
+++ b/src/main/java/cn/edu/cqwu/repair/service/impl/RecordServiceImpl.java
@@ -3,6 +3,7 @@ package cn.edu.cqwu.repair.service.impl;
import cn.edu.cqwu.repair.dao.RecordDao;
import cn.edu.cqwu.repair.entity.AdminUser;
import cn.edu.cqwu.repair.entity.Record;
+import cn.edu.cqwu.repair.entity.Stu;
import cn.edu.cqwu.repair.entity.Worker;
import cn.edu.cqwu.repair.service.RecordService;
import cn.edu.cqwu.repair.util.PageModel;
@@ -40,4 +41,13 @@ public class RecordServiceImpl implements RecordService {
public PageModel pageByLogname(String logname, String group, int pageSize, int pageNo) {
return recordDao.pageByLogname(logname, group, pageSize, pageNo);
}
+
+ @Override
+ public int add(Stu user, String ip) {
+ Record record = new Record();
+ record.setLogname(user.getUsername());
+ record.setUsergroup("用户");
+ record.setLogip(ip);
+ return recordDao.add(record);
+ }
}
diff --git a/src/main/java/cn/edu/cqwu/repair/util/Encrypt.java b/src/main/java/cn/edu/cqwu/repair/util/Encrypt.java
index 67f57c2..98b0b82 100644
--- a/src/main/java/cn/edu/cqwu/repair/util/Encrypt.java
+++ b/src/main/java/cn/edu/cqwu/repair/util/Encrypt.java
@@ -46,4 +46,8 @@ public class Encrypt {
}
return hexValue.toString();
}
+
+ public static void main(String[] args) {
+ System.out.println(MD5("020803"));
+ }
}