系统一共分为2个角色分别是:管理员,用户





























- html>
- <html lang="en" xmlns:th="http://www.thymeleaf.org">
- <head>
- <meta charset="UTF-8">
- <title>登录title>
- <link rel="icon" th:href="@{/public/favicon.ico}" type="image/x-icon"/>
- <link rel="bookmark" th:href="@{/public/favicon.ico}" type="image/x-icon"/>
- <link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap.css}">
- <link rel="stylesheet" type="text/css" th:href="@{/css/back.css}">
- <link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap-theme.css}">
- <script type="text/javascript" th:src="@{/js/jquery-3.6.0.js}">script>
- <script type="text/javascript" th:src="@{/js/login.js}">script>
- <script>
- $(function() {
- //防止页面后退
- history.pushState(null, null, document.URL);
- window.addEventListener('popstate', function () {
- history.pushState(null, null, document.URL);
- });
- })
- script>
- head>
- <body onload="loadTopWindow()">
- <div id="magicalDragScene" class="mc-root mc-ui-absolute-pane">
- <h1 style="margin-left: 56%;margin-top: 8%;font-family: 隶书;font-size: 60px;color: white" >社区流浪动物救助管理系统h1>
- <br>
- <div id="tmd" style="width: 25%;height: 300px;">
- <form style="margin: 0 auto;width: 80%;height: 300px;" th:action="@{/loginUser}" method="post" onsubmit="return regCheck()">
- <h1 class="h3 mb-3 font-weight-normal" style="color:white;font-family: 隶书;text-align: center;" >登录h1>
- <input id="username" name="username" class="layui-input" type="text" th:placeholder="请填写用户名"/>
- <input id="password" name="password" class="layui-input" style="margin-top: 5px" type="password" th:placeholder="请填写用户密码" origin-type="password"/>
- <br>
- <select name="type" class="form-control" style="width: 75%">
- <option value="1" selected>管理员option>
- <option value="2">用户option>
- select>
-
-
-
- <span id="statusTip" style="color: #d62727;font-size: 15px;margin-left: 40%" th:text="${status}">span>
- <br>
-
-
-
- <button class="layui-btn1" style="width: 300px;height: 40px;font-size: 16px;color: white" type="submit">登录button>
- form>
- div>
- <br>
-
-
-
- div>
-
- body>
- html>
- /**
- * 登录
- * @param username
- * @param password
- * @param type
- * @param httpSession
- * @param model
- * @return
- * @throws UnsupportedEncodingException
- */
- @RequestMapping(value = "/loginUser",method = RequestMethod.POST)
- public String loginUser( String username,String password, String type,HttpSession httpSession, Model model) throws UnsupportedEncodingException {
- Admin admin = new Admin();
- if(type !=null&& type.equals("1")){
- admin = loginService.selectAdmin(username,password);
- if (admin != null){
- httpSession.setAttribute("username",admin.getUsername());
- httpSession.setAttribute("admin",admin);
- httpSession.setAttribute("type",type);
- model.addAttribute("type",type);
- return "home/homepage";
- }else{
- model.addAttribute("status","账号或者密码输入错误!");
- return "login";
- }
- }
- else if(type.equals("2")){//用户
- User user = loginService.selectUser(username,password);
- if(user != null){
- httpSession.setAttribute("username",user.getRealname());
- httpSession.setAttribute("user",user);
- httpSession.setAttribute("type",type);
- model.addAttribute("type",type);
- return "redirect:/toIndex";
-
-
- //return "home/homepage";
- }else{
- model.addAttribute("status","账号或者密码输入错误!");
- return "login";
- }
- }else{
- model.addAttribute("status","账号或者密码输入错误!");
- return "login";
- }
- }