Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
liyeyun-user-web
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cfld-backend
liyeyun-user-web
Commits
7dd6c4b8
Commit
7dd6c4b8
authored
Nov 20, 2023
by
zhouxudong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新代码
parent
5afb96eb
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
29 additions
and
17 deletions
+29
-17
CurrentUserInterceptor.java
...java/com/lyy/user/config/auth/CurrentUserInterceptor.java
+10
-2
RedisConfig.java
src/main/java/com/lyy/user/config/redis/RedisConfig.java
+0
-5
Constants.java
src/main/java/com/lyy/user/constant/Constants.java
+2
-0
SysPcLoginController.java
...yy/user/moudle/login/controller/SysPcLoginController.java
+1
-1
SysSmsLogEntity.java
...va/com/lyy/user/moudle/smslog/entity/SysSmsLogEntity.java
+4
-3
SysUserController.java
...om/lyy/user/moudle/user/controller/SysUserController.java
+7
-2
SysUserInfoServiceImpl.java
...user/moudle/user/service/impl/SysUserInfoServiceImpl.java
+4
-3
application-dev.yml
src/main/resources/application-dev.yml
+1
-1
No files found.
src/main/java/com/lyy/user/config/auth/CurrentUserInterceptor.java
View file @
7dd6c4b8
...
...
@@ -2,8 +2,13 @@ package com.lyy.user.config.auth;
import
com.lyy.user.config.exception.ServiceException
;
import
com.lyy.user.config.other.BaseContextHandler
;
import
com.lyy.user.constant.Constants
;
import
com.lyy.user.util.jwt.JwtTokenUtil
;
import
com.lyy.user.util.redis.RedisUtil
;
import
org.apache.commons.lang3.ObjectUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.web.servlet.AsyncHandlerInterceptor
;
import
javax.servlet.http.HttpServletRequest
;
...
...
@@ -11,16 +16,19 @@ import javax.servlet.http.HttpServletResponse;
/** 服务拦截器,根据配置的请求路径,进行请求的拦截,执行preHandle方法 */
public
class
CurrentUserInterceptor
implements
AsyncHandlerInterceptor
{
private
static
final
String
TOKEN_HEADER
=
"Authorization"
;
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
// 从header中获取权限请求头
String
token
=
request
.
getHeader
(
TOKEN_HEADER
);
String
token
=
request
.
getHeader
(
Constants
.
TOKEN_HEADER
);
if
(
StringUtils
.
isBlank
(
token
)){
throw
new
ServiceException
(
"未授权,登录失败"
);
}
Object
redisToken
=
RedisUtil
.
get
(
Constants
.
token
+
token
);
if
(
ObjectUtils
.
isEmpty
(
redisToken
)){
throw
new
ServiceException
(
"请重新登录"
);
}
// 根据token信息,生成当前登录用户信息的设置,存放容器threadlocal
BaseContextHandler
.
setCurrentUserInfo
(
JwtTokenUtil
.
getJwtUser
(
token
));
return
true
;
...
...
src/main/java/com/lyy/user/config/redis/RedisConfig.java
View file @
7dd6c4b8
...
...
@@ -3,13 +3,8 @@ package com.lyy.user.config.redis;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.JsonTypeInfo
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator
;
import
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.cache.annotation.CachingConfigurer
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
...
...
src/main/java/com/lyy/user/constant/Constants.java
View file @
7dd6c4b8
...
...
@@ -116,4 +116,6 @@ public class Constants {
public
static
final
String
token
=
"bearer "
;
//手机验证码 规则: 手机验证码:验证码类型:手机号
public
static
final
String
MSG_KEY
=
"phone:message:"
;
public
static
final
String
TOKEN_HEADER
=
"Authorization"
;
}
src/main/java/com/lyy/user/moudle/login/controller/SysPcLoginController.java
View file @
7dd6c4b8
...
...
@@ -73,7 +73,7 @@ public class SysPcLoginController {
* @return: boolean
*/
@PostMapping
(
"/sendMsg/{phone}"
)
public
boolean
sendMsg
(
String
phone
)
{
public
boolean
sendMsg
(
@PathVariable
(
"phone"
)
String
phone
)
{
return
this
.
sysUserInfoService
.
sendMsg
(
phone
);
}
...
...
src/main/java/com/lyy/user/moudle/smslog/entity/SysSmsLogEntity.java
View file @
7dd6c4b8
...
...
@@ -5,6 +5,7 @@ import lombok.*;
import
lombok.experimental.Accessors
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
java.util.Date
;
/**
...
...
@@ -22,7 +23,7 @@ import java.util.Date;
@Accessors
(
chain
=
true
)
public
class
SysSmsLogEntity
implements
Serializable
{
/** 主键id */
@TableId
private
Stri
ng
id
;
@TableId
private
Lo
ng
id
;
/** 返回标识符 */
private
String
code
;
/** 返回字段描述 */
...
...
@@ -42,11 +43,11 @@ public class SysSmsLogEntity implements Serializable {
private
String
createBy
;
/** 创建时间 */
@TableField
(
value
=
"create_time"
,
fill
=
FieldFill
.
INSERT
)
private
Dat
e
createTime
;
private
LocalDateTim
e
createTime
;
/** 更新人 */
@TableField
(
value
=
"update_by"
,
fill
=
FieldFill
.
UPDATE
)
private
String
updateBy
;
/** 更新时间 */
@TableField
(
value
=
"update_time"
,
fill
=
FieldFill
.
UPDATE
)
private
Dat
e
updateTime
;
private
LocalDateTim
e
updateTime
;
}
src/main/java/com/lyy/user/moudle/user/controller/SysUserController.java
View file @
7dd6c4b8
package
com
.
lyy
.
user
.
moudle
.
user
.
controller
;
import
com.lyy.user.config.auth.CurrentUserInterceptor
;
import
com.lyy.user.config.other.BaseContextHandler
;
import
com.lyy.user.constant.Constants
;
import
com.lyy.user.domain.JwtInfo
;
import
com.lyy.user.moudle.user.service.SysUserInfoService
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.tomcat.util.bcel.Const
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -25,8 +30,8 @@ public class SysUserController {
* @param: [request]
* @return: boolean
*/
@PostMapping
(
"logout"
)
@PostMapping
(
"
/
logout"
)
public
boolean
logout
(
HttpServletRequest
request
)
{
return
this
.
sysUserInfoService
.
logout
(
request
.
getHeader
(
"token"
));
return
this
.
sysUserInfoService
.
logout
(
request
.
getHeader
(
Constants
.
TOKEN_HEADER
));
}
}
src/main/java/com/lyy/user/moudle/user/service/impl/SysUserInfoServiceImpl.java
View file @
7dd6c4b8
...
...
@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.RandomUtil
;
import
cn.hutool.core.util.ReUtil
;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.jwt.JWT
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
...
...
@@ -139,7 +140,7 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs
private
String
getPhoneKey
(
String
phone
,
Integer
type
)
{
return
stringRedisTemplate
.
opsForValue
()
.
get
(
Constants
.
MSG_KEY
+
SendMsgTypeEnum
.
LOGIN
.
getCode
()
+
":"
+
phone
);
.
get
(
Constants
.
MSG_KEY
+
phone
);
}
/**
* @description: 退出
...
...
@@ -183,7 +184,7 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs
if
(
ObjectUtils
.
isEmpty
(
result
))
{
throw
new
ServiceException
(
"短信发送失败"
);
}
SmsVo
smsVo
=
Bean
Util
.
toBean
(
result
,
SmsVo
.
class
);
SmsVo
smsVo
=
JSON
Util
.
toBean
(
result
,
SmsVo
.
class
);
SysSmsLogEntity
sysSmsLog
=
new
SysSmsLogEntity
();
sysSmsLog
.
setCode
(
smsVo
.
getCode
())
...
...
@@ -224,7 +225,7 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs
sendPhoneVo
.
getPhone
(),
SendMsgTypeEnum
.
getTemplateId
(
sendPhoneVo
.
getType
()),
temp
.
toString
());
SmsVo
smsVo
=
Bean
Util
.
toBean
(
result
,
SmsVo
.
class
);
SmsVo
smsVo
=
JSON
Util
.
toBean
(
result
,
SmsVo
.
class
);
if
(
ObjectUtils
.
isEmpty
(
smsVo
))
{
throw
new
ServiceException
(
"短信发送失败"
);
}
...
...
src/main/resources/application-dev.yml
View file @
7dd6c4b8
...
...
@@ -17,7 +17,7 @@ spring:
host
:
r-2zekq6swp5wr808a3lpd.redis.rds.aliyuncs.com
port
:
6379
password
:
techbook4redis#&20190909
timeout
:
3
000
timeout
:
20
000
database
:
3
lettuce
:
pool
:
...
...
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