Compare commits

...

2 Commits

Author SHA1 Message Date
wobeitaoleshigexuruo
3b555530ab Merge remote-tracking branch 'origin/master'
# Conflicts:
#	src/main/webapp/index.jsp
2024-05-12 21:33:10 +08:00
wobeitaoleshigexuruo
67e377d373 student登录注册 2024-05-12 21:32:25 +08:00
6 changed files with 188 additions and 157 deletions

View File

@ -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";
}
}

View File

@ -1,10 +1,4 @@
<%--
Created by IntelliJ IDEA.
User: xtaod
Date: 2024/5/12
Time: 下午8:21
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" %>
<c:set var="title" value="登录"/>
<c:set var="webroot" value="${pageContext.request.contextPath}"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="${webroot}/styles/bootstrap.min.css">
<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>
<link rel="stylesheet" href="${webroot}/styles/index.css" crossorigin="anonymous"></head>
<body>
<main class="d-flex flex-nowrap">
<%@ include file="./includes/header.jsp" %>
<%@ include file="includes/header.jsp" %>
<main class="form-signin w-100 m-auto">
<div class="toast-container position-fixed bottom-0 end-0 p-3">
@ -40,9 +37,9 @@
</div>
</div>
</div>
<form action="${webroot}/login.do" method="post" >
<form action="${webroot}/stulogin.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>
<h1 class="h3 mb-3 fw-normal">登录</h1>
<c:if test="${not empty requestScope.stuLoginMess}">
<div class="alert alert-warning" role="alert">
@ -51,11 +48,11 @@
</c:if>
<div class="form-floating">
<input type="text" class="form-control" name="username" id="username" value="${username}" required>
<input type="text" class="form-control" name="username" id="username" required>
<label for="username">用户名</label>
</div>
<div class="form-floating">
<input type="password" class="form-control" name="password" id="password" value="${password}" required>
<input type="password" class="form-control" name="password" id="password" required>
<label for="password">密码</label>
</div>
<div class="input-group mb-3">
@ -67,13 +64,13 @@
</span>
</div>
<input class="btn btn-primary w-100 py-2" type="submit" id="submit">
<button class="btn btn-primary w-100 py-2" type="submit" id="submit">登录</button>
<br/><br/>
</form>
<a href="${webroot}/register.jsp">
<a href="${webroot}/student/register.jsp">
<button class="btn btn-primary w-100 py-2">去注册</button>
</a>
</main>
</main>
</main>
<script src="${webroot}/js/pass.js" type="javascript"></script>
<script>
@ -82,5 +79,8 @@
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample)
toastBootstrap.show()
</script>
</body>
</html>

View File

@ -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" %>
<c:set var="title" value="用户主页"/>
<c:set var="webroot" value="${pageContext.request.contextPath}"/>
<html>
<head>
<link rel="stylesheet" href="${webroot}/styles/bootstrap.min.css">
<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}/stueditpassword.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.stuEditMess}">
<div class="alert alert-warning" role="alert">
${requestScope.stuEditMess}
</div>
</c:if>
<div class="form-floating">
<input type="password" class="form-control" name="oldpassword" id="oldpassword" required>
<label for="oldpassword">旧密码</label>
</div>
<div class="form-floating">
<input type="password" class="form-control" name="password" id="password" required>
<label for="password">新密码</label>
</div>
<button class="btn btn-primary w-100 py-2" type="submit" id="submit">确定</button>
<br/><br/>
</form>
</main>
</main>
<script src="${webroot}/js/pass.js" type="javascript"></script>
<script>
const toastLiveExample = document.getElementById('liveToast')
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample)
toastBootstrap.show()
</script>
</body>
</html>

View File

@ -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" %>
<html>
<head>
<title>Title</title>
</head>
<body>
</body>
</html>

View File

@ -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" %>
<c:set var="title" value="登录"/>
<c:set var="webroot" value="${pageContext.request.contextPath}"/>
<html>
<head>
<link rel="stylesheet" href="${webroot}/styles/bootstrap.min.css">
<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">
<div class="toast-container position-fixed bottom-0 end-0 p-3">
<div id="liveToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="${webroot}/images/logo.jpg" class="rounded me-2" width="32" height="32">
<strong class="me-auto">提示</strong>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
1、请牢记您注册时填写的用户名和密码登录本系统时您需要提供正确的用户名和密码</br>
2、忘记用户名或者密码请联系学校管理员
</div>
</div>
</div>
<form action="${webroot}/stulogin.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.stuLoginMess}">
<div class="alert alert-warning" role="alert">
${requestScope.stuLoginMess}
</div>
</c:if>
<div class="form-floating">
<input type="text" class="form-control" name="username" id="username" value="${username}" required>
<label for="username">用户名</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="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>
<a href="${webroot}/register.jsp">
<button class="btn btn-primary w-100 py-2">去注册</button>
</a>
</main>
<script src="${webroot}/js/pass.js" type="javascript"></script>
<script>
const toastLiveExample = document.getElementById('liveToast')
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample)
toastBootstrap.show()
</script>
</body>
</html>

View File

@ -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" %>
<c:set var="title" value="登录"/>
<c:set var="title" value="注册"/>
<c:set var="webroot" value="${pageContext.request.contextPath}"/>
<html>
<head>
<title>Title</title>
<link rel="stylesheet" href="${webroot}/styles/bootstrap.min.css">
@ -18,7 +16,7 @@
<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">
<link rel="stylesheet" href="${webroot}/styles/index.css" crossorigin="anonymous"></head>
</head>
<body>
<main class="d-flex flex-nowrap">
@ -38,54 +36,48 @@
</div>
</div>
</div>
<form action="${webroot}/login.do" method="post" >
<form action="${webroot}/sturegist.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>
<h1 class="h3 mb-3 fw-normal">注册</h1>
<c:if test="${not empty requestScope.stuLoginMess}">
<c:if test="${not empty requestScope.stuRegistMess}">
<div class="alert alert-warning" role="alert">
${requestScope.stuLoginMess}
${requestScope.stuRegistMess}
</div>
</c:if>
<div class="form-bottom">
<form role="form" id="myForm" method="post" class="login-form" action="${webroot}/regist.do">
<div class="form-floating">
<label for="userNo">学号</label>
<input type="text" class="form-control" name="userNo" id="userNo" required>
</div>
<div class="form-floating">
<label for="username">用户名</label>
<input type="text" class="form-control" name="username" id="username" required>
</div>
<div class="form-floating">
<label for="password">密码</label>
<input type="password" class="form-control" name="password" id="password" required>
</div>
<div>
<div class="form-floating">
<label for="gender">性别:</label>
<select id="gender" name="gender" required>
<option value="male">男</option>
<option value="female">女</option>
</select>
</div>
</div>
<button class="btn btn-primary w-100 py-2" type="submit" id="submit">注册</button>
</form>
<a href="${webroot}/student/login.jsp">
<button class="btn btn-primary w-100 py-2">去登录</button>
</a>
<div class="form-floating">
<input type="text" class="form-control" name="userNo" id="userNo" required>
<label for="userNo">学号</label>
</div>
<div class="form-floating">
<input type="text" class="form-control" name="username" id="username" required>
<label for="username">用户名</label>
</div>
<div class="form-floating">
<input type="password" class="form-control" name="password" id="password" required>
<label for="password">密码</label>
</div>
<button class="btn btn-primary w-100 py-2" type="submit" id="submit">注册</button>
</form>
<a href="${webroot}/index.jsp">
<button class="btn btn-primary w-100 py-2">去登录</button>
</a>
</main>
</main>
<script src="${webroot}/js/pass.js" type="javascript"></script>