1
This commit is contained in:
@@ -0,0 +1,67 @@
|
|||||||
|
package com.cym.controller.page;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
|
import com.cym.ext.AdminExt;
|
||||||
|
import com.cym.model.Admin;
|
||||||
|
import com.cym.service.AdminExampleService;
|
||||||
|
import com.cym.utils.BaseController;
|
||||||
|
import com.cym.utils.JsonResult;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.UUID;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录页
|
||||||
|
*
|
||||||
|
* @author Administrator
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequestMapping("/")
|
||||||
|
@Controller
|
||||||
|
public class LoginExampleController extends BaseController {
|
||||||
|
@Autowired
|
||||||
|
AdminExampleService adminExampleService;
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping("")
|
||||||
|
public ModelAndView admin(ModelAndView modelAndView, HttpServletRequest request, String adminId) {
|
||||||
|
|
||||||
|
modelAndView.setViewName("/loginExample/index");
|
||||||
|
return modelAndView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("loginExample/login")
|
||||||
|
@ResponseBody
|
||||||
|
public JsonResult submitLogin(String name, String pass, HttpServletRequest request) {
|
||||||
|
|
||||||
|
getHttpSession().removeAttribute("adminLogin");
|
||||||
|
|
||||||
|
// 用户名密码
|
||||||
|
Admin admin = adminExampleService.login(name, pass);
|
||||||
|
if (admin == null) {
|
||||||
|
return renderError("用户名密码错误"); // 用户名密码错误
|
||||||
|
}
|
||||||
|
|
||||||
|
// 登录成功
|
||||||
|
admin.setAutoKey(UUID.randomUUID().toString()); // 生成自动登录code
|
||||||
|
jpaHelper.updateById(admin);
|
||||||
|
|
||||||
|
// 读取菜单
|
||||||
|
AdminExt adminExt = new AdminExt();
|
||||||
|
|
||||||
|
getHttpSession().setAttribute("adminLogin", adminExt);
|
||||||
|
|
||||||
|
|
||||||
|
return renderSuccess(admin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.cym.service;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.cym.model.Admin;
|
||||||
|
import com.cym.utils.ConditionAndWrapper;
|
||||||
|
import com.cym.utils.JpaHelper;
|
||||||
|
|
||||||
|
import cn.hutool.crypto.SecureUtil;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AdminExampleService {
|
||||||
|
@Autowired
|
||||||
|
JpaHelper jpaHelper;
|
||||||
|
|
||||||
|
public Admin login(String name, String pass) {
|
||||||
|
pass = SecureUtil.md5(pass);
|
||||||
|
return jpaHelper.findOneByQuery(new ConditionAndWrapper().eq(Admin::getName, name).eq(Admin::getPass, pass), Admin.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB |
@@ -0,0 +1,41 @@
|
|||||||
|
$(function() {
|
||||||
|
layer.open({
|
||||||
|
type: 1,
|
||||||
|
shade: false,
|
||||||
|
title: "管理员登录",
|
||||||
|
closeBtn: false,
|
||||||
|
area: ['450px', '350px'], //宽高
|
||||||
|
content: $('#windowDiv')
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
function login() {
|
||||||
|
showLoad();
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: ctx + 'loginExample/login',
|
||||||
|
data: $("#loginForm").serialize(),
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(data) {
|
||||||
|
closeLoad();
|
||||||
|
if (data.success) {
|
||||||
|
location.href = ctx + "adminPage/example";
|
||||||
|
} else {
|
||||||
|
layer.msg(data.msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
closeLoad();
|
||||||
|
layer.alert("请求失败,请刷新重试");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function getKey() {
|
||||||
|
if (event.keyCode == 13) {
|
||||||
|
login();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<#include '/common.html'/>
|
||||||
|
<style type="text/css">
|
||||||
|
.layui-form-label {
|
||||||
|
width: 120px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body style="background-color: #000000">
|
||||||
|
<div style="height: 0px; width: 0px; overflow: hidden;">
|
||||||
|
<!-- 弹出框 -->
|
||||||
|
<div class="layui-form" id="windowDiv" style="padding: 15px; display: none;">
|
||||||
|
<form id="loginForm">
|
||||||
|
<input type="hidden" name="id" id="id">
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">用户名</label>
|
||||||
|
<div class="layui-input-inline">
|
||||||
|
<input type="text" name="name" id="name" class="layui-input" value="">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label class="layui-form-label">密码</label>
|
||||||
|
<div class="layui-input-inline">
|
||||||
|
<input type="password" name="pass" id="pass" class="layui-input" value="" onkeyup="getKey()">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="layui-form-item" style="text-align: center;">
|
||||||
|
<button type="button" class="layui-btn layui-btn-normal" onclick="login()">登录</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<#include '/script.html'/>
|
||||||
|
<script src="${ctx}/js/loginExample/index.js?v=${jsrandom}" type="text/javascript"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user