admin pass
This commit is contained in:
parent
d351746543
commit
387ed61777
@ -0,0 +1,61 @@
|
|||||||
|
package cn.edu.cqwu.repair.controller.admin;
|
||||||
|
|
||||||
|
import cn.edu.cqwu.repair.dao.AdminUserDao;
|
||||||
|
import cn.edu.cqwu.repair.entity.AdminUser;
|
||||||
|
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 AdminPassController {
|
||||||
|
AdminUserDao adminUserDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public AdminPassController(AdminUserDao adminUserDao) {
|
||||||
|
this.adminUserDao = adminUserDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/admin/pass.do")
|
||||||
|
public String pass(
|
||||||
|
@SessionAttribute AdminUser adminUser,
|
||||||
|
String oldPassword,
|
||||||
|
String password,
|
||||||
|
String confirmpass,
|
||||||
|
String code,
|
||||||
|
HttpSession session,
|
||||||
|
HttpServletRequest request,
|
||||||
|
Model model
|
||||||
|
) {
|
||||||
|
String username = adminUser.getAdminName();
|
||||||
|
String mess = Verify.validateForm1(username, oldPassword, password, confirmpass, code);
|
||||||
|
if (!mess.isEmpty()) {
|
||||||
|
model.addAttribute("adminPassMess", mess);
|
||||||
|
return "/admin/pass";
|
||||||
|
}
|
||||||
|
if (!Verify.verifyCode(session, code)) {
|
||||||
|
model.addAttribute("adminPassMess", "* 验证码错误!");
|
||||||
|
return "/admin/pass";
|
||||||
|
}
|
||||||
|
AdminUser byUsername = adminUserDao.validateLogin(username, Encrypt.SHA(oldPassword));
|
||||||
|
if (byUsername == null) {
|
||||||
|
model.addAttribute("adminPassMess", "* 旧密码错误!");
|
||||||
|
return "/admin/pass";
|
||||||
|
}
|
||||||
|
if (adminUserDao.passModify(username, Encrypt.SHA(password)) == 1) {
|
||||||
|
request.setAttribute("adminPassMess", "* 修改成功!");
|
||||||
|
} else {
|
||||||
|
request.setAttribute("adminPassMess", "* 修改失败!");
|
||||||
|
}
|
||||||
|
return "/admin/pass";
|
||||||
|
}
|
||||||
|
}
|
@ -23,9 +23,9 @@ public class Verify {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String validateForm1(String username, String oldPasswrd, String password, String confirmpass, String code) {
|
public static String validateForm1(String username, String oldPasswrd, String password, String confirmpass, String code) {
|
||||||
if (username == null || !username.matches("\\w{6,20}")) {
|
if (username == null || !username.matches("\\w{5,20}")) {
|
||||||
return "* 用户名不合法!";
|
return "* 用户名不合法!";
|
||||||
} else if (password == null || !password.matches("\\w{6,20}")) {
|
} else if (password == null || !password.matches("\\w{5,20}")) {
|
||||||
return "* 密码不合法!";
|
return "* 密码不合法!";
|
||||||
} else if (password.equals(oldPasswrd)) {
|
} else if (password.equals(oldPasswrd)) {
|
||||||
return "* 新密码不能与旧密码相同!";
|
return "* 新密码不能与旧密码相同!";
|
||||||
@ -41,9 +41,9 @@ public class Verify {
|
|||||||
if (stuNo == null || !stuNo.matches("\\d{12}")) {
|
if (stuNo == null || !stuNo.matches("\\d{12}")) {
|
||||||
return "* 学号不合法!";
|
return "* 学号不合法!";
|
||||||
}
|
}
|
||||||
if (username == null || !username.matches("\\w{6,20}")) {
|
if (username == null || !username.matches("\\w{5,20}")) {
|
||||||
return "* 用户名不合法!";
|
return "* 用户名不合法!";
|
||||||
} else if (password == null || !password.matches("\\w{6,20}")) {
|
} else if (password == null || !password.matches("\\w{5,20}")) {
|
||||||
return "* 密码不合法!";
|
return "* 密码不合法!";
|
||||||
} else if (!password.equals(confirmpass)) {
|
} else if (!password.equals(confirmpass)) {
|
||||||
return "* 两次输入的密码不一致,请重新输入!";
|
return "* 两次输入的密码不一致,请重新输入!";
|
||||||
|
69
src/main/webapp/admin/pass.jsp
Normal file
69
src/main/webapp/admin/pass.jsp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<%--
|
||||||
|
Created by IntelliJ IDEA.
|
||||||
|
User: xtaod
|
||||||
|
Date: 2024/5/16
|
||||||
|
Time: 上午8:29
|
||||||
|
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}/admin/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.adminPassMess}">
|
||||||
|
<div class="alert alert-warning" role="alert">
|
||||||
|
${requestScope.adminPassMess}
|
||||||
|
</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>
|
Loading…
Reference in New Issue
Block a user