feat: stu edit pass and get record
This commit is contained in:
parent
d8ce35567e
commit
79d16918be
@ -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";
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
@ -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";
|
||||
}
|
||||
}
|
@ -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 "* 学号不合法!";
|
||||
|
@ -22,7 +22,7 @@
|
||||
<strong>${sessionScope.stu.username}</strong>
|
||||
</a>
|
||||
<ul class="dropdown-menu text-small shadow">
|
||||
<li><a class="dropdown-item" href="${webroot}/record.do">我的登录历史</a></li>
|
||||
<li><a class="dropdown-item" href="${webroot}/stu/record.do">我的登录历史</a></li>
|
||||
<li><a class="dropdown-item" href="${webroot}/stu/pass.jsp">修改密码</a></li>
|
||||
<li>
|
||||
<hr class="dropdown-divider">
|
||||
|
@ -1,8 +1,8 @@
|
||||
<%--
|
||||
Created by IntelliJ IDEA.
|
||||
User: xtaod
|
||||
Date: 2023/12/9
|
||||
Time: 10:18
|
||||
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" %>
|
||||
|
@ -1,8 +1,8 @@
|
||||
<%--
|
||||
Created by IntelliJ IDEA.
|
||||
User: xtaod
|
||||
Date: 2023/12/9
|
||||
Time: 10:18
|
||||
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" %>
|
||||
|
34
src/main/webapp/stu/main.jsp
Normal file
34
src/main/webapp/stu/main.jsp
Normal file
@ -0,0 +1,34 @@
|
||||
<%--
|
||||
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" %>
|
||||
<%@ 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" %>
|
||||
<c:set var="webroot" value="${pageContext.request.contextPath}"/>
|
||||
<c:set var="title" value="用户中心"/>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<title>${title}</title>
|
||||
<link rel="stylesheet" href="${webroot}/styles/bootstrap.min.css" crossorigin="anonymous">
|
||||
<script src="${webroot}/js/bootstrap.bundle.min.js"></script>
|
||||
<link rel="stylesheet" href="${webroot}/styles/sidebar.css" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="${webroot}/styles/index.css" crossorigin="anonymous">
|
||||
</head>
|
||||
<body>
|
||||
<main class="d-flex flex-nowrap">
|
||||
<%@ include file="../includes/header.jsp" %>
|
||||
|
||||
<main class="form-signin w-100 m-auto">
|
||||
<img class="mb-4" src="${webroot}/images/logo.jpg" alt="" width="72" height="72">
|
||||
<h1 class="h3 mb-3 fw-normal">用户中心</h1>
|
||||
</main>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
69
src/main/webapp/stu/pass.jsp
Normal file
69
src/main/webapp/stu/pass.jsp
Normal file
@ -0,0 +1,69 @@
|
||||
<%--
|
||||
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" %>
|
||||
<%@ 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" %>
|
||||
<c:set var="webroot" value="${pageContext.request.contextPath}"/>
|
||||
<c:set var="title" value="修改密码"/>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<title>${title}</title>
|
||||
<link rel="stylesheet" href="${webroot}/styles/bootstrap.min.css" crossorigin="anonymous">
|
||||
<script src="${webroot}/js/bootstrap.bundle.min.js"></script>
|
||||
<link rel="stylesheet" href="${webroot}/styles/sidebar.css" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="${webroot}/styles/index.css" crossorigin="anonymous">
|
||||
</head>
|
||||
<body>
|
||||
<main class="d-flex flex-nowrap">
|
||||
<%@ include file="../includes/header.jsp" %>
|
||||
|
||||
<main class="form-signin w-100 m-auto">
|
||||
<form action="${webroot}/stu/pass.do" method="post">
|
||||
<img class="mb-4" src="${webroot}/images/logo.jpg" alt="" width="72" height="72">
|
||||
<h1 class="h3 mb-3 fw-normal">修改密码</h1>
|
||||
|
||||
<c:if test="${not empty requestScope.stuPassMess}">
|
||||
<div class="alert alert-warning" role="alert">
|
||||
${requestScope.stuPassMess}
|
||||
</div>
|
||||
</c:if>
|
||||
|
||||
<div class="form-floating">
|
||||
<input type="password" class="form-control" name="oldPassword" id="oldPassword" value="${oldPassword}"
|
||||
required>
|
||||
<label for="oldPassword">旧密码</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input type="password" class="form-control" name="password" id="password" value="${password}" required>
|
||||
<label for="password">密码</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input type="password" class="form-control" name="confirmpass" id="confirmpass" value="${confirmpass}"
|
||||
required>
|
||||
<label for="confirmpass">确认密码</label>
|
||||
</div>
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" class="form-control" placeholder="验证码" name="code" id="code" required>
|
||||
<span class="input-group-text">
|
||||
<img src="${pageContext.request.contextPath}/includes/code.jsp" id="imagecode"
|
||||
title="点击图片可刷新验证码"
|
||||
onclick="this.src='${pageContext.request.contextPath}/includes/code.jsp?'+Math.random()">
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<input class="btn btn-primary w-100 py-2" type="submit" id="submit">
|
||||
<br/><br/>
|
||||
</form>
|
||||
</main>
|
||||
</main>
|
||||
<script src="${webroot}/js/pass.js"></script>
|
||||
</body>
|
||||
</html>
|
60
src/main/webapp/stu/record.jsp
Normal file
60
src/main/webapp/stu/record.jsp
Normal file
@ -0,0 +1,60 @@
|
||||
<%--
|
||||
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" %>
|
||||
<%@ 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" %>
|
||||
<c:set var="webroot" value="${pageContext.request.contextPath}"/>
|
||||
<c:set var="title" value="登录历史"/>
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<title>${title}</title>
|
||||
<link rel="stylesheet" href="${webroot}/styles/bootstrap.min.css" crossorigin="anonymous">
|
||||
<script src="${webroot}/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="${webroot}/js/record.js"></script>
|
||||
<link rel="stylesheet" href="${webroot}/styles/sidebar.css" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="${webroot}/styles/index.css" crossorigin="anonymous">
|
||||
</head>
|
||||
<body>
|
||||
<main class="d-flex flex-nowrap">
|
||||
<%@ include file="../includes/header.jsp" %>
|
||||
|
||||
<main class="form-signin w-100 m-auto" style="max-width: 600px;">
|
||||
<img class="mb-4" src="${webroot}/images/logo.jpg" alt="" width="72" height="72">
|
||||
<h1 class="h3 mb-3 fw-normal">${title}</h1>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">序号</th>
|
||||
<th scope="col">登录名</th>
|
||||
<th scope="col">用户组</th>
|
||||
<th scope="col">登录时间</th>
|
||||
<th scope="col">登录IP</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<c:forEach items="${pm.data}" var="recode" varStatus="row">
|
||||
<tr>
|
||||
<td>${row.index + 1}</td>
|
||||
<td>${recode.logname}</td>
|
||||
<td>${recode.usergroup}</td>
|
||||
<td>${recode.logtime}</td>
|
||||
<td>${recode.logip}</td>
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</tbody>
|
||||
</table>
|
||||
${pm.pageNav}
|
||||
</main>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
@ -5,13 +5,6 @@
|
||||
Time: 20:18
|
||||
To change this template use File | Settings | File Templates.
|
||||
--%>
|
||||
<%--
|
||||
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" %>
|
||||
|
Loading…
Reference in New Issue
Block a user