Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8timerapiv200
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
8timerv2
8timerapiv200
Commits
1903fb68
Commit
1903fb68
authored
May 20, 2022
by
陶湘宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redis存储session
parent
e4fbfcb1
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
63 additions
and
24 deletions
+63
-24
src/main/java/cn/timer/api/aspect/LogAspect.java
+4
-1
src/main/java/cn/timer/api/aspect/RoleAspect.java
+4
-1
src/main/java/cn/timer/api/config/interceptor/RedisSessionInterceptor.java
+7
-4
src/main/java/cn/timer/api/config/interceptor/UserMethodArgumentResolver.java
+5
-1
src/main/java/cn/timer/api/controller/LoginController.java
+12
-12
src/main/java/cn/timer/api/controller/qyzx/QyzxController.java
+6
-1
src/main/java/cn/timer/api/controller/superadmin/SuperLoginController.java
+8
-4
src/main/java/cn/timer/api/utils/redis/RedisUtil.java
+17
-0
No files found.
src/main/java/cn/timer/api/aspect/LogAspect.java
View file @
1903fb68
...
...
@@ -10,6 +10,7 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
cn.timer.api.utils.redis.RedisUtil
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.Signature
;
import
org.aspectj.lang.annotation.AfterReturning
;
...
...
@@ -53,6 +54,8 @@ public class LogAspect
@Resource
private
HttpSession
session
;
@Resource
private
RedisUtil
redisUtil
;
// 配置织入点
@Pointcut
(
"@annotation(cn.timer.api.aspect.lang.annotation.Log)"
)
...
...
@@ -96,7 +99,7 @@ public class LogAspect
// 获取当前的用户
// LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
QyzxEmpLogin
eld
=
(
QyzxEmpLogin
)
session
.
getAttribute
(
"ui"
);
QyzxEmpLogin
eld
=
(
QyzxEmpLogin
)
redisUtil
.
getAttribute
(
session
.
getId
(),
"ui"
);
// if (eld == null && controllerLog.businessType() == BusinessType.SEND_CODE) {
// Object[] objs = joinPoint.getArgs();
...
...
src/main/java/cn/timer/api/aspect/RoleAspect.java
View file @
1903fb68
...
...
@@ -6,6 +6,7 @@ import java.util.List;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpSession
;
import
cn.timer.api.utils.redis.RedisUtil
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.Signature
;
...
...
@@ -48,6 +49,8 @@ public class RoleAspect {
@Resource
private
HttpSession
session
;
@Resource
private
RedisUtil
redisUtil
;
// 配置织入点
@Pointcut
(
"@annotation(cn.timer.api.aspect.lang.annotation.Role)"
)
...
...
@@ -67,7 +70,7 @@ public class RoleAspect {
sysRoleType
.
add
(
t
.
getType
());
}
QyzxEmpLogin
eld
=
BeanUtil
.
toBean
(
session
.
getAttribute
(
"ui"
),
QyzxEmpLogin
.
class
);
QyzxEmpLogin
eld
=
BeanUtil
.
toBean
(
redisUtil
.
getAttribute
(
session
.
getId
(),
"ui"
),
QyzxEmpLogin
.
class
);
Integer
orgCode
=
eld
.
getOrgId
();
Integer
count
=
new
LambdaQueryChainWrapper
<
QyzxEmpEntAsso
>(
qyzxEmpEntAssoMapper
)
...
...
src/main/java/cn/timer/api/config/interceptor/RedisSessionInterceptor.java
View file @
1903fb68
...
...
@@ -51,17 +51,20 @@ public class RedisSessionInterceptor implements HandlerInterceptor {
*/
// 无论访问的地址是不是正确的,都进行登录验证,登录成功后的访问再进行分发,404的访问自然会进入到错误控制器中
HttpSession
session
=
request
.
getSession
();
Object
ai
=
session
.
getAttribute
(
"ai"
);
Object
ui
=
session
.
getAttribute
(
"ui"
);
if
(
session
.
getAttribute
(
"ui"
)==
null
&&
session
.
getAttribute
(
"ai"
)==
null
)
{
System
.
out
.
println
(
"SID===="
+
session
.
getId
());
Object
ai
=
redisUtil
.
getAttribute
(
session
.
getId
(),
"ai"
);
Object
ui
=
redisUtil
.
getAttribute
(
session
.
getId
(),
"ui"
);
if
(
ui
==
null
&&
ai
==
null
)
{
response401
(
response
);
return
false
;
}
try
{
QyzxEmpLogin
eld
=
BeanUtil
.
toBean
(
session
.
getAttribute
(
"ui"
)
,
QyzxEmpLogin
.
class
);
QyzxEmpLogin
eld
=
BeanUtil
.
toBean
(
ui
,
QyzxEmpLogin
.
class
);
if
(
redisUtil
.
get
(
"BlockUser"
+
eld
.
getId
())!=
null
){
redisUtil
.
del
(
"BlockUser"
+
eld
.
getId
());
session
.
removeAttribute
(
"ui"
);
redisUtil
.
del
(
session
.
getId
());
response302
(
response
);
return
false
;
}
...
...
src/main/java/cn/timer/api/config/interceptor/UserMethodArgumentResolver.java
View file @
1903fb68
...
...
@@ -3,6 +3,7 @@ package cn.timer.api.config.interceptor;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpSession
;
import
cn.timer.api.utils.redis.RedisUtil
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.support.WebDataBinderFactory
;
...
...
@@ -23,6 +24,8 @@ public class UserMethodArgumentResolver implements HandlerMethodArgumentResolver
@Resource
private
HttpSession
session
;
@Resource
private
RedisUtil
redisUtil
;
public
UserMethodArgumentResolver
()
{
}
...
...
@@ -42,8 +45,9 @@ public class UserMethodArgumentResolver implements HandlerMethodArgumentResolver
// String webRequestid = webRequest.getSessionId();
// String sessionid = session.getId();
QyzxEmpLogin
eld
=
BeanUtil
.
toBean
(
session
.
getAttribute
(
"ui"
),
QyzxEmpLogin
.
class
);
QyzxEmpLogin
eld
=
BeanUtil
.
toBean
(
redisUtil
.
getAttribute
(
session
.
getId
(),
"ui"
),
QyzxEmpLogin
.
class
);
String
token
=
BeanUtil
.
toBean
(
session
.
getAttribute
(
CacheKeyConstant
.
TOKEN
),
String
.
class
);
System
.
out
.
println
(
"token+++++===="
+
token
);
String
refreshToken
=
BeanUtil
.
toBean
(
session
.
getAttribute
(
CacheKeyConstant
.
REFRESH_TOKEN
),
String
.
class
);
// Object phone = webRequest.getAttribute(currentUserAnnotation.id(),
...
...
src/main/java/cn/timer/api/controller/LoginController.java
View file @
1903fb68
...
...
@@ -152,7 +152,7 @@ public class LoginController {
@Value
(
"${config-8timer.authentication-code}"
)
public
String
authentication_code
;
//2020/0517 redis缓存taoxy
@Autowired
private
HttpSession
session
;
...
...
@@ -257,7 +257,7 @@ public class LoginController {
String
message
=
j
.
getString
(
"Message"
);
if
(
"OK"
.
equals
(
message
))
{
session
.
setAttribute
(
phone
,
code
);
redisUtil
.
set
(
phone
,
code
);
// redisTemplate.set(phone, code);
// redisTemplate.expire(phone, 60);
...
...
@@ -302,7 +302,7 @@ public class LoginController {
String
message
=
j
.
getString
(
"Message"
);
if
(
"OK"
.
equals
(
message
))
{
session
.
setAttribute
(
phone
,
code
);
//
session.setAttribute(phone, code);
redisUtil
.
set
(
phone
,
code
,
60
*
5
);
return
ResultUtil
.
data
(
"发送验证码成功"
);
}
else
{
...
...
@@ -328,7 +328,7 @@ public class LoginController {
String
code
=
entRegisterDto
.
getCode
().
toString
();
String
codeRedis
=
session
.
getAttribute
(
phone
)
!=
null
?
session
.
getAttribute
(
phone
).
toString
()
:
""
;
String
codeRedis
=
redisUtil
.
get
(
phone
)
!=
null
?
redisUtil
.
get
(
phone
).
toString
()
:
""
;
if
(
authentication_code
!=
null
&&
!(
""
).
equals
(
authentication_code
))
{
if
(
authentication_code
.
equals
(
code
))
{
...
...
@@ -368,7 +368,7 @@ public class LoginController {
}
else
{
if
(
authentication_code
==
null
||
(
""
).
equals
(
authentication_code
)
||
!
authentication_code
.
equals
(
code
))
{
String
codeRedis
=
session
.
getAttribute
(
phone
)
!=
null
?
session
.
getAttribute
(
phone
).
toString
()
:
""
;
String
codeRedis
=
redisUtil
.
get
(
phone
)
!=
null
?
redisUtil
.
get
(
phone
).
toString
()
:
""
;
if
(!
code
.
equals
(
codeRedis
))
{
return
ResultUtil
.
error
(
"短信验证码错误"
);
}
...
...
@@ -403,7 +403,7 @@ public class LoginController {
String
code
=
entRegisterDto
.
getCode
();
if
(
entRegisterDto
.
getPwUpdateType
()
!=
2
)
{
String
codeRedis
=
session
.
getAttribute
(
phone
)
!=
null
?
session
.
getAttribute
(
phone
).
toString
()
:
""
;
String
codeRedis
=
redisUtil
.
get
(
phone
)!=
null
?
redisUtil
.
get
(
phone
).
toString
()
:
""
;
if
(
code
==
null
)
{
return
ResultUtil
.
error
(
"请填写验证码"
);
}
...
...
@@ -469,7 +469,7 @@ public class LoginController {
String
phone
=
entRegisterDto
.
getPhone
();
String
code
=
entRegisterDto
.
getCode
();
// String codeRedis = redisTemplate.get(phone).toString();
String
codeRedis
=
session
.
getAttribute
(
phone
)
!=
null
?
session
.
getAttribute
(
phone
).
toString
()
:
""
;
String
codeRedis
=
redisUtil
.
get
(
phone
)
!=
null
?
redisUtil
.
get
(
phone
).
toString
()
:
""
;
if
(
authentication_code
!=
null
&&
!(
""
).
equals
(
authentication_code
))
{
if
(
authentication_code
.
equals
(
code
))
{
...
...
@@ -745,7 +745,7 @@ public class LoginController {
return
ResultUtil
.
error
(
"请输入验证码"
);
}
String
phone
=
entRegisterDto
.
getPhone
();
String
codeRedis
=
session
.
getAttribute
(
phone
)
!=
null
?
session
.
getAttribute
(
phone
).
toString
()
:
""
;
String
codeRedis
=
redisUtil
.
get
(
phone
)!=
null
?
redisUtil
.
get
(
phone
).
toString
()
:
""
;
if
(
authentication_code
!=
null
&&
!(
""
).
equals
(
authentication_code
))
{
if
(
authentication_code
.
equals
(
code
))
{
...
...
@@ -908,10 +908,10 @@ public class LoginController {
// 需要更新最后一次登陆信息
// 用户信息缓存
session
.
setAttribute
(
"ui"
,
qyzxEmpLogin1
);
System
.
err
.
println
(
session
.
getId
());
Object
ui
=
session
.
getAttribute
(
"ui"
);
//
session.setAttribute("ui", qyzxEmpLogin1);
redisUtil
.
setAttribute
(
session
.
getId
(),
"ui"
,
qyzxEmpLogin1
);
System
.
err
.
println
(
"redis=>>session"
+
session
.
getId
());
Object
ui
=
redisUtil
.
getAttribute
(
session
.
getId
(),
"ui"
);
return
ResultUtil
.
data
(
qyzxEmpLogin1
);
}
...
...
src/main/java/cn/timer/api/controller/qyzx/QyzxController.java
View file @
1903fb68
...
...
@@ -23,6 +23,7 @@ import cn.timer.api.controller.spmk.service.SpmkServiceImpl;
import
cn.timer.api.dao.kqmk.KqglAssoLeaveRulesMapper
;
import
cn.timer.api.dto.qyzx.*
;
import
cn.timer.api.utils.Md5
;
import
cn.timer.api.utils.redis.RedisUtil
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -85,6 +86,9 @@ public class QyzxController {
private
HttpSession
session
;
@Autowired
private
RedisUtil
redisUtil
;
@Autowired
private
QyzxEmpEntAssoMapper
qyzxEmpEntAssoMapper
;
@Autowired
...
...
@@ -351,7 +355,8 @@ public class QyzxController {
}
}
emp
.
setOrgId
(
orgCode
);
session
.
setAttribute
(
"ui"
,
emp
);
//session.setAttribute("ui", emp);
redisUtil
.
setAttribute
(
session
.
getId
(),
"ui"
,
emp
);
qyzxEmpLoginMapper
.
updateById
(
emp
);
return
ResultUtil
.
data
(
menus
,
"切换企业成功"
);
}
else
{
...
...
src/main/java/cn/timer/api/controller/superadmin/SuperLoginController.java
View file @
1903fb68
...
...
@@ -8,6 +8,7 @@ import cn.timer.api.utils.Result;
import
cn.timer.api.utils.ResultUtil
;
import
cn.timer.api.utils.UserIp
;
import
cn.timer.api.utils.redis.RedisConfig
;
import
cn.timer.api.utils.redis.RedisUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
...
...
@@ -33,6 +34,8 @@ import javax.servlet.http.HttpSession;
public
class
SuperLoginController
{
@Autowired
private
HttpSession
session
;
@Autowired
private
RedisUtil
redisUtil
;
@PostMapping
(
value
=
"/adminLogin"
)
@ApiOperation
(
value
=
"运营后台登录"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
public
Result
<
Object
>
adminLogin
(
@RequestBody
EntRegisterDto
entRegisterDto
,
HttpServletRequest
request
){
...
...
@@ -44,16 +47,17 @@ public class SuperLoginController {
if
(
adminAccount
==
null
){
return
ResultUtil
.
error
(
"用户不存在或密码错误"
);
}
session
=
request
.
getSession
();
session
.
setAttribute
(
"ai"
,
adminAccount
);
//
session=request.getSession();
redisUtil
.
setAttribute
(
session
.
getId
(),
"ai"
,
adminAccount
);
System
.
err
.
println
(
session
.
getId
());
return
ResultUtil
.
data
(
adminAccount
);
};
@PostMapping
(
value
=
"/adminOutLogin"
)
@ApiOperation
(
value
=
"运营后台退出"
,
httpMethod
=
"POST"
,
notes
=
"接口发布说明"
)
public
Result
<
String
>
adminOutLogin
(
HttpServletRequest
request
){
session
=
request
.
getSession
();
session
.
removeAttribute
(
"ai"
);
//session= request.getSession();
// session.removeAttribute("ai");
redisUtil
.
del
(
session
.
getId
());
return
ResultUtil
.
data
(
"退出成功"
);
}
}
src/main/java/cn/timer/api/utils/redis/RedisUtil.java
View file @
1903fb68
...
...
@@ -26,6 +26,23 @@ public class RedisUtil {
}
/**
* 模拟session的getAttrubute方法
* taoxy
* 0520
*/
public
Object
getAttribute
(
String
sinkey
,
String
key
){
return
redisTemplate
.
opsForHash
().
get
(
sinkey
,
key
);
}
/**
* 模拟session的setAttrubute方法
* taoxy
* 0520
*/
public
void
setAttribute
(
String
sinkey
,
String
key
,
Object
value
){
redisTemplate
.
opsForHash
().
put
(
sinkey
,
key
,
value
);
}
/**
* 指定缓存失效时间
* @param key 键
* @param time 时间(秒)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment