From f095cda341fba7d5c8aab1e6def4910849ad48f3 Mon Sep 17 00:00:00 2001 From: sobear <410731299@qq.com> Date: Sun, 12 May 2024 21:30:58 +0800 Subject: [PATCH] add worker login --- .idea/uiDesigner.xml | 124 ++++++++++++++++++ .../worker/WorkerLoginController.java | 57 ++++++++ .../cn/edu/cqwu/repair/dao/WorkerDao.java | 14 ++ .../cqwu/repair/dao/impl/WorkerDaoImpl.java | 56 ++++++++ .../webapp/worker/worker_center_index.jsp | 108 +++++++++++++++ src/main/webapp/worker_login.jsp | 89 +++++++++++++ 6 files changed, 448 insertions(+) create mode 100644 .idea/uiDesigner.xml create mode 100644 src/main/java/cn/edu/cqwu/repair/controller/worker/WorkerLoginController.java create mode 100644 src/main/java/cn/edu/cqwu/repair/dao/WorkerDao.java create mode 100644 src/main/java/cn/edu/cqwu/repair/dao/impl/WorkerDaoImpl.java create mode 100644 src/main/webapp/worker/worker_center_index.jsp create mode 100644 src/main/webapp/worker_login.jsp diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/cn/edu/cqwu/repair/controller/worker/WorkerLoginController.java b/src/main/java/cn/edu/cqwu/repair/controller/worker/WorkerLoginController.java new file mode 100644 index 0000000..2fe3344 --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/controller/worker/WorkerLoginController.java @@ -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"; + } + } + + +} diff --git a/src/main/java/cn/edu/cqwu/repair/dao/WorkerDao.java b/src/main/java/cn/edu/cqwu/repair/dao/WorkerDao.java new file mode 100644 index 0000000..56aeee9 --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/dao/WorkerDao.java @@ -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 findWorkersLikeUsername(String username); +} diff --git a/src/main/java/cn/edu/cqwu/repair/dao/impl/WorkerDaoImpl.java b/src/main/java/cn/edu/cqwu/repair/dao/impl/WorkerDaoImpl.java new file mode 100644 index 0000000..c12b51f --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/dao/impl/WorkerDaoImpl.java @@ -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 findWorkersLikeUsername(String username) { + QueryWrapper qw = new QueryWrapper(); + qw.select(WORKER.ALL_COLUMNS).where(WORKER.USERNAME.like(username)); + return (ArrayList) MAPPER.selectListByQuery(qw); + } + + +} diff --git a/src/main/webapp/worker/worker_center_index.jsp b/src/main/webapp/worker/worker_center_index.jsp new file mode 100644 index 0000000..e08a07d --- /dev/null +++ b/src/main/webapp/worker/worker_center_index.jsp @@ -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" %> + + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + ${title} + + + + + + + +
+ + +
+
+
+
+
+ +

工人个人中心

+
+
+
+
个人信息
+

这里显示工人的个人信息,比如姓名、联系方式等。

+
+
+
+
+
订单信息
+

这里显示工人的订单信息,比如已接订单、待处理订单等。

+
+
+
+
+
服务记录
+

这里显示工人的服务记录,包括服务评价、历史订单等。

+
+
+
+
+
+
+
+ + diff --git a/src/main/webapp/worker_login.jsp b/src/main/webapp/worker_login.jsp new file mode 100644 index 0000000..d40b251 --- /dev/null +++ b/src/main/webapp/worker_login.jsp @@ -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" %> + + + + + + + ${title} + + + + + + +
+ <%@ include file="includes/header.jsp" %> + +
+
+ +
+
+ +

请先登录

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

+
+
+
+ + + +