去掉url中带有sessionid,记录免登录两周

This commit is contained in:
meng 2020-08-29 17:06:49 +08:00
parent 7b3fe06d64
commit ead0c57521
6 changed files with 43 additions and 85 deletions

View File

@ -78,10 +78,14 @@
layui.use('table', function () {
var table = layui.table;
//方法级渲染
var arr=[];
if(${leaveDetail}){
arr=${leaveDetail};
}
table.render({
id: 'leaveDetail',
elem: '#leaveDetail'
, data: ${leaveDetail}
, data:arr
, cols: [[
{field: 'taskId', title: '任务编码', width: '20%'}
,{field: 'opName', title: '审批人', width: '20%'}

View File

@ -10,6 +10,7 @@ import com.len.util.VerifyCodeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.ExcessiveAttemptsException;
import org.apache.shiro.authc.IncorrectCredentialsException;
@ -39,6 +40,7 @@ public class LoginController {
@Autowired
SysUserService userService;
private static final String CODE_ERROR = "code.error";
private static final Long TWO_WEEK = 1000 * 60 * 60 * 24 * 14L;
@GetMapping(value = "")
public String login() {
@ -77,10 +79,10 @@ public class LoginController {
@PostMapping("/login")
public String login(SysUser user, Model model, String rememberMe, HttpServletRequest request) {
String codeMsg = (String) request.getAttribute("shiroLoginFailure");
/*if (CODE_ERROR.equals(codeMsg)) {
if (CODE_ERROR.equals(codeMsg)) {
model.addAttribute("message", "验证码错误");
return "/login2";
}*/
}
CustomUsernamePasswordToken token = new CustomUsernamePasswordToken(user.getUsername().trim(),
user.getPassword(), LoginType.SYS);
Subject subject = Principal.getSubject();
@ -88,7 +90,13 @@ public class LoginController {
try {
subject.login(token);
if (subject.isAuthenticated()) {
token.getUsername();
String isRemember = request.getParameter("isRemember");
if (!StringUtils.isEmpty(isRemember)) {
if ("true".equals(isRemember)) {
subject.getSession().setTimeout(TWO_WEEK);
}
}
return "redirect:/main";
}
} catch (UnknownAccountException | IncorrectCredentialsException e) {

View File

@ -11,7 +11,6 @@
<link rel="stylesheet" href="/plugin/layui/css/layui.css" media="all">
</head>
<script src="/plugin/login/hawkEye.min.js"></script>
<script type="text/javascript" src="/plugin/login/jquery-core.min.js"></script>
<script type="text/javascript" src="/plugin/login/jquery-ui-core.min.js"></script>
<script type="text/javascript" src="/plugin/login/fai.min.js"></script>
@ -55,6 +54,7 @@
<span class="icon icon-3"></span>
<input name="password" lay-verify="password" type="password" id="loginPwd" placeholder="请输入密码" maxlength="20">
<input type="text" id="loginPwdText" placeholder="请输入密码" maxlength="20" class="hide">
<input type="hidden" id="isRemember" name="isRemember" value="false"/>
<span class="icon icon-4"></span>
</div>
<div id="validatePanel" class="item" style="width: 137px;">
@ -66,11 +66,8 @@
<div class="tip">
<span class="icon-nocheck" id="autoLogin"></span>
<span class="login-tip">两周内自动登录</span>
<a href="javascript:" onclick="openPassword()" class="no-pwd">忘记密码?</a>
<!-- <a href="javascript:" onclick="openPassword()" class="no-pwd">忘记密码?</a>-->
</div>
<!--<div id="loginBtn" lay-filter="login" lay-submit class="deal" >
立即登录
</div>-->
<div style="width: 300px;height: 50px;text-align: center;margin: 24px auto 0;">
<input id="loginBtn" class="deal" value="立即登录" lay-submit lay-filter="login" type="submit">
</div>
@ -88,9 +85,16 @@
// 是否两周内自动登录
/* $('.icon-nocheck, .login-tip').click(function () {
$('.icon-nocheck, .login-tip').click(function () {
$('.icon-nocheck').toggleClass('icon-check');
});*/
var isRemember=$('#isRemember').val();
if(isRemember==='false'){
isRemember='true';
}else{
isRemember='false'
}
$('#isRemember').val(isRemember);
});
layui.use(['form','layer'], function(){
var form = layui.form;
form.verify({

File diff suppressed because one or more lines are too long

View File

@ -1,62 +0,0 @@
package com.len.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class RConfig {
@Value("${spring.redis.port}")
private String host;
@Value("${spring.redis.port}")
private int port;
@Value("${spring.redis.timeout}")
private int timeout;
@Value("${spring.redis.maxRetryCount}")
private int maxRetryCount;
@Value("${spring.redis.second}")
private Long second;
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public int getTimeout() {
return timeout;
}
public void setTimeout(int timeout) {
this.timeout = timeout;
}
public int getMaxRetryCount() {
return maxRetryCount;
}
public void setMaxRetryCount(int maxRetryCount) {
this.maxRetryCount = maxRetryCount;
}
public Long getSecond() {
return second;
}
public void setSecond(Long second) {
this.second = second;
}
}

View File

@ -19,8 +19,8 @@ import org.crazycake.shiro.RedisCacheManager;
import org.crazycake.shiro.RedisManager;
import org.crazycake.shiro.RedisSessionDAO;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -41,8 +41,12 @@ import java.util.*;
@Configuration
public class ShiroConfig {
@Autowired
RConfig redisConfig;
@Value("${spring.redis.host}")
private String host;
@Value("${spring.redis.port}")
private int port;
@Value("${spring.redis.timeout}")
private int timeout;
@Bean
@ -86,7 +90,7 @@ public class ShiroConfig {
/*==========ehcache 缓存 end============*/
@Bean
public LifecycleBeanPostProcessor getLifecycleBeanPostProcessor() {
public static LifecycleBeanPostProcessor getLifecycleBeanPostProcessor() {
return new LifecycleBeanPostProcessor();
}
@ -152,6 +156,7 @@ public class ShiroConfig {
filterMap.put("/login", "verCode,anon");
filterMap.put("/blogLogin", "verCode,anon");
filterMap.put("/getCode", "anon");
filterMap.put("/oauth", "anon");
filterMap.put("/actuator/**", "anon");
filterMap.put("/eureka/**", "anon");
filterMap.put("/img/**", "anon");
@ -192,24 +197,23 @@ public class ShiroConfig {
public RedisCacheManager cacheManager() {
RedisCacheManager redisCacheManager = new RedisCacheManager();
redisCacheManager.setRedisManager(redisManager());
redisCacheManager.setRedisManager(getRedisManager());
redisCacheManager.setPrincipalIdFieldName("id");
return redisCacheManager;
}
private RedisManager redisManager() {
// @Bean
public RedisManager getRedisManager() {
RedisManager redisManager = new RedisManager();
// redisManager.setHost(redisConfig.getHost());
// redisManager.setPort(redisConfig.getPort());
// redisManager.setExpire(1800);
// redisManager.setTimeout(redisConfig.getTimeout());
redisManager.setHost(host + ":" + port);
redisManager.setTimeout(timeout);
return redisManager;
}
@Bean
public RedisSessionDAO redisSessionDAO() {
RedisSessionDAO redisSessionDAO = new RedisSessionDAO();
redisSessionDAO.setRedisManager(redisManager());
redisSessionDAO.setRedisManager(getRedisManager());
return redisSessionDAO;
}
@ -217,6 +221,7 @@ public class ShiroConfig {
@Bean
public DefaultWebSessionManager sessionManager() {
DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
sessionManager.setSessionIdUrlRewritingEnabled(false);
sessionManager.setSessionDAO(redisSessionDAO());
return sessionManager;
}