add worker login

This commit is contained in:
sobear 2024-05-12 21:30:58 +08:00
parent 2c28d19806
commit f095cda341
6 changed files with 448 additions and 0 deletions

124
.idea/uiDesigner.xml Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

View File

@ -0,0 +1,57 @@
package cn.edu.cqwu.repair.controller.worker;
import cn.edu.cqwu.repair.dao.WorkerDao;
import javax.servlet.http.*;
import cn.edu.cqwu.repair.entity.Worker;
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.RequestMapping;
@Controller
public class WorkerLoginController {
private final WorkerDao workerDao;
private final RecordService recordService;
@Autowired
public WorkerLoginController(WorkerDao workerDao, RecordService recordService) {
this.workerDao = workerDao;
this.recordService = recordService;
}
@RequestMapping("/workerLogin.do")
public String workerLogin(
String username, String password, String code, Model model, HttpSession session,
HttpServletRequest request
) {
String mess = Verify.validateForm(username, password, code);
if (!mess.isEmpty()) {
model.addAttribute("workerLoginMess", mess);
return "/worker_login";
}
if (!Verify.verifyCode(session, code)) {
model.addAttribute("workerLoginMess", "* 验证码错误!");
return "/worker_login";
}
Worker user = workerDao.validateLogin(username, password);
if (user == null) {
model.addAttribute("workerLoginMess", "* 用户名或密码输入错误!");
return "/worker_login";
}
if (recordService.add(user, request.getRemoteAddr()) != 0) {
session.setAttribute("workerUser", user);
return "redirect:/worker/worker_center_index.jsp";
} else {
model.addAttribute("adminLoginMess", "* 登录异常!");
return "/worker_login";
}
}
}

View File

@ -0,0 +1,14 @@
package cn.edu.cqwu.repair.dao;
import cn.edu.cqwu.repair.entity.Stu;
import cn.edu.cqwu.repair.entity.Worker;
import java.util.ArrayList;
public interface WorkerDao {
public Worker findByUserName(String username);
public Worker validateLogin(String username, String password);
public int passModify(String username, String newpass);
public ArrayList<Worker> findWorkersLikeUsername(String username);
}

View File

@ -0,0 +1,56 @@
package cn.edu.cqwu.repair.dao.impl;
import cn.edu.cqwu.repair.dao.WorkerDao;
import cn.edu.cqwu.repair.db.ConnectionFactory;
import cn.edu.cqwu.repair.entity.Stu;
import cn.edu.cqwu.repair.entity.Worker;
import cn.edu.cqwu.repair.entity.mapper.StuMapper;
import cn.edu.cqwu.repair.entity.mapper.WorkerMapper;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import static cn.edu.cqwu.repair.entity.table.StuTableDef.STU;
import static cn.edu.cqwu.repair.entity.table.WorkerTableDef.WORKER;
@Component
public class WorkerDaoImpl implements WorkerDao {
private static final WorkerMapper MAPPER = ConnectionFactory.getMapper(WorkerMapper.class);
@Override
public Worker findByUserName(String username){
QueryWrapper qw = new QueryWrapper();
qw.select(WORKER.ALL_COLUMNS).where(WORKER.USERNAME.eq(username));
return MAPPER.selectOneByQuery(qw);
}
// 判断用户密码组是否匹配
@Override
public Worker validateLogin(String username, String password) {
QueryWrapper qw = new QueryWrapper();
qw.select(WORKER.ALL_COLUMNS).where(WORKER.USERNAME.eq(username)).and(WORKER.PASSWORD.eq(password));
return MAPPER.selectOneByQuery(qw);
}
@Override
public int passModify(String username, String newpass) {
QueryWrapper qw = new QueryWrapper();
qw.select(WORKER.ALL_COLUMNS).where(WORKER.USERNAME.eq(username));
Worker s = MAPPER.selectOneByQuery(qw);
if (s == null) {
return 0;
}
s.setPassword(newpass);
return MAPPER.update(s);
}
@Override
public ArrayList<Worker> findWorkersLikeUsername(String username) {
QueryWrapper qw = new QueryWrapper();
qw.select(WORKER.ALL_COLUMNS).where(WORKER.USERNAME.like(username));
return (ArrayList<Worker>) MAPPER.selectListByQuery(qw);
}
}

View File

@ -0,0 +1,108 @@
<%--
Created by IntelliJ IDEA.
User: sobear
Date: 2024/5/12
Time: 19:35
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="title" value="工人端个人中心"/>
<c:set var="webroot" value="${pageContext.request.contextPath}"/>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<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">
<style>
/* 添加一个红色边框 */
.highlight {
border: 2px solid red;
padding: 10px;
}
</style>
</head>
<body>
<header>
<!-- 导航栏部分 -->
<div class="d-flex flex-column flex-shrink-0 p-3 bg-body-tertiary" style="width: 280px;">
<a href="${webroot}/"
class="d-flex align-items-center mb-3 mb-md-0 me-md-auto link-body-emphasis text-decoration-none">
<img src="${webroot}/images/logo.jpg" alt="" width="32" height="32" class="rounded-circle me-2">
<span class="fs-4">维修管理系统</span>
</a>
<hr>
<ul class="nav nav-pills flex-column mb-auto">
<c:choose>
<c:when test="${not empty sessionScope.username}">
<li class="nav-item">
<a href="${webroot}/stu/notice.jsp" class="nav-link link-body-emphasis" aria-current="page">
>> 主页
</a>
</li>
<li class="nav-item">
<a href="${webroot}/xx.jsp" class="nav-link link-body-emphasis" aria-current="page">
>> 个人中心
</a>
</li>
<li class="nav-item">
<a href="${webroot}/xx.jsp" class="nav-link link-body-emphasis" aria-current="page">
>> 已接任务
</a>
</li>
<li class="nav-item">
<a href="${webroot}/xx.jsp" class="nav-link link-body-emphasis" aria-current="page">
>> 历史任务
</a>
</li>
</c:when>
<c:otherwise>
<li class="nav-item">
<a href="${webroot}/" class="nav-link link-body-emphasis" aria-current="page">
>> 主页
</a>
</li>
</c:otherwise>
</c:choose>
</ul>
</div>
</header>
<main>
<div class="container">
<div class="row">
<div class="col-md-8 offset-md-2">
<!-- 工人个人中心主页内容 -->
<h1 class="text-center">工人个人中心</h1>
<div class="highlight"> <!-- 添加了红色边框的容器 -->
<div class="card">
<div class="card-body">
<h5 class="card-title">个人信息</h5>
<p class="card-text">这里显示工人的个人信息,比如姓名、联系方式等。</p>
</div>
</div>
<div class="card mt-3">
<div class="card-body">
<h5 class="card-title">订单信息</h5>
<p class="card-text">这里显示工人的订单信息,比如已接订单、待处理订单等。</p>
</div>
</div>
<div class="card mt-3">
<div class="card-body">
<h5 class="card-title">服务记录</h5>
<p class="card-text">这里显示工人的服务记录,包括服务评价、历史订单等。</p>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
</body>
</html>

View File

@ -0,0 +1,89 @@
<%--
Created by IntelliJ IDEA.
User: sobear
Date: 2024/5/12
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" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<c:set var="title" value="worker_Login"/>
<c:set var="webroot" value="${pageContext.request.contextPath}"/>
<!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>
<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}/workerLogin.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.workerLoginMess}">
<div class="alert alert-warning" role="alert">
${requestScope.workerLoginMess}
</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>
</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>