diff --git a/src/main/java/cn/edu/cqwu/repair/controller/StuController.java b/src/main/java/cn/edu/cqwu/repair/controller/StuController.java index ef4e9af..3b05f6b 100644 --- a/src/main/java/cn/edu/cqwu/repair/controller/StuController.java +++ b/src/main/java/cn/edu/cqwu/repair/controller/StuController.java @@ -4,7 +4,9 @@ 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; @@ -24,34 +26,74 @@ public class StuController { @Autowired StuDao stuDao; - @RequestMapping("/regist.do") - public String Register(String userNo, String username, String password, String gender, HttpServletRequest request){ - Stu stu = new Stu(); - stu.setUserNo(userNo); - stu.setUsername(username); - stu.setPassword(password); - stu.setStatus(0); - stu.setGender(gender); - String localAddr = request.getLocalAddr(); - stu.setRegip(localAddr); - stuDao.add(stu); + @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"; + } - return "/student/success"; } -@RequestMapping("/stulogin.do") - +@PostMapping("/stulogin.do") public String login( String username, String password, HttpServletRequest request){ Stu stu = stuDao.validateLogin(username, password); - request.getSession().setAttribute("student",stu); + if(stu!=null) { + request.getSession().setAttribute("stu", stu); + request.setAttribute("stuLoginMess","登陆成功"); + return "/student/edit"; + }else{ + request.setAttribute("stuLoginMess","登陆失败"); - return "/student/success"; + 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/webapp/index.jsp b/src/main/webapp/index.jsp index afd6580..2869087 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -1,10 +1,4 @@ -<%-- - Created by IntelliJ IDEA. - User: xtaod - Date: 2023/12/9 - Time: 10:18 - To change this template use File | Settings | File Templates. ---%> + <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> @@ -12,19 +6,22 @@ <%@ page isELIgnored="false" %> - + + + + + ${title} - - +
- <%@ include file="./includes/header.jsp" %> + <%@ include file="includes/header.jsp" %>
@@ -40,9 +37,9 @@
-
+ -

请先登录

+

登录

+
+ + + diff --git a/src/main/webapp/student/edit.jsp b/src/main/webapp/student/edit.jsp new file mode 100644 index 0000000..6778995 --- /dev/null +++ b/src/main/webapp/student/edit.jsp @@ -0,0 +1,65 @@ + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ page isELIgnored="false" %> + + + + + + + + + + + ${title} + + + + + +
+ <%@ include file="../includes/header.jsp" %> + +
+
+ +

修改用户密码

+ + + + +
+ + +
+ +
+ + +
+ + + +

+
+ +
+ +
+ + + + + + + diff --git a/src/main/webapp/student/editPassword.jsp b/src/main/webapp/student/editPassword.jsp new file mode 100644 index 0000000..397a84d --- /dev/null +++ b/src/main/webapp/student/editPassword.jsp @@ -0,0 +1,16 @@ +<%-- + Created by IntelliJ IDEA. + User: Administrator + Date: 2024/5/12 + Time: 21:10 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Title + + + + + diff --git a/src/main/webapp/student/login.jsp b/src/main/webapp/student/login.jsp deleted file mode 100644 index a41c3cd..0000000 --- a/src/main/webapp/student/login.jsp +++ /dev/null @@ -1,84 +0,0 @@ - -<%@ page contentType="text/html;charset=UTF-8" language="java" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> -<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<%@ page isELIgnored="false" %> - - - - - - - - - - ${title} - - - - - -
- <%@ include file="../includes/header.jsp" %> - -
-
- -
-
- -

请先登录

- - - - - -
- - -
-
- - -
-
- - - - -
- - -

-
- - - -
- - - - - - - diff --git a/src/main/webapp/student/register.jsp b/src/main/webapp/student/register.jsp index 21d8f0c..dff5b40 100644 --- a/src/main/webapp/student/register.jsp +++ b/src/main/webapp/student/register.jsp @@ -1,14 +1,12 @@ - <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ page isELIgnored="false" %> - + - Title @@ -18,7 +16,7 @@ - +
@@ -38,54 +36,48 @@ -
+ -

请先登录

+

注册

- + -
- -
- - -
-
- - -
-
- - -
-
-
- - - - -
-
- - - - - - +
+ +
+ + +
+ + + + +
+
+ + + + +
+ + + + + + + +