refa: stu
This commit is contained in:
parent
3b555530ab
commit
6a810133f2
@ -7,9 +7,8 @@
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="workspaceImportForciblyTurnedOn" value="true" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="18" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -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";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -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";
|
||||
}
|
||||
}
|
||||
}
|
@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +46,8 @@ public class Encrypt {
|
||||
}
|
||||
return hexValue.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(MD5("020803"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user