Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
polysoft-nafmii
/
polysoft-parent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 0194e6f2
authored
Apr 27, 2021
by
zhoujinghao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
reids 提交
1 parent
c39b13a8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
2 deletions
nafmii-app/src/main/java/org/nafmii/app/user/service/impl/UserServiceImpl.java
nafmii-app/src/main/resources/application.yml
nafmii-common/src/main/java/org/nafmii/enums/RedisEnum.java
nafmii-app/src/main/java/org/nafmii/app/user/service/impl/UserServiceImpl.java
View file @
0194e6f
...
...
@@ -15,12 +15,16 @@ import org.nafmii.common.utils.GuavaUtil;
import
org.nafmii.common.utils.JwtUtils
;
import
org.nafmii.common.utils.SnowFlakeUtil
;
import
org.nafmii.common.constant.UserEnum
;
import
org.nafmii.enums.RedisEnum
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
/**
* @author:zhoujh
...
...
@@ -36,6 +40,12 @@ public class UserServiceImpl implements UserService {
@Resource
private
AppUserMapper
appUserMapper
;
//redis缓存快递集合-key
public
static
final
String
USER_CODE_KEY
=
"user:code"
;
@Autowired
StringRedisTemplate
stringRedisTemplate
;
/**
* 模拟用户登陆
* @return
...
...
@@ -99,8 +109,9 @@ public class UserServiceImpl implements UserService {
log
.
info
(
"用户注册参数==============>"
+
registerDto
);
//将验证码放入到缓存当中(过期时间60s)test
// GuavaUtil.putTrackGuava(registerDto.getPhone(),registerDto.getCode());
stringRedisTemplate
.
opsForValue
().
set
(
new
StringBuilder
().
append
(
USER_CODE_KEY
).
append
(
registerDto
.
getPhone
()).
toString
(),
registerDto
.
getCode
(),
RedisEnum
.
PHONECODE
.
getCode
(),
TimeUnit
.
SECONDS
);
//重缓存中获取(通过手机号获取)
String
code
=
(
String
)
GuavaUtil
.
getTrackGuava
(
registerDto
.
getPhone
());
String
code
=
stringRedisTemplate
.
opsForValue
().
get
(
USER_CODE_KEY
+
registerDto
.
getPhone
());
log
.
info
(
"冲缓存中获取的验证码===============》{}"
,
code
);
if
(
null
==
code
){
throw
new
BusinessException
(
"验证码已过期"
);
...
...
@@ -133,7 +144,8 @@ public class UserServiceImpl implements UserService {
}
}
else
{
//验证码登陆
String
code
=
(
String
)
GuavaUtil
.
getTrackGuava
(
loginDto
.
getPhone
());
String
code
=
stringRedisTemplate
.
opsForValue
().
get
(
USER_CODE_KEY
+
loginDto
.
getPhone
());
log
.
info
(
"冲redis中获取的验证码===============》{}"
,
code
);
log
.
info
(
"冲缓存中获取的验证码===============》{}"
,
code
);
if
(
null
==
code
){
throw
new
BusinessException
(
"验证码已过期"
);
...
...
nafmii-app/src/main/resources/application.yml
View file @
0194e6f
...
...
@@ -27,3 +27,19 @@ spring:
password
:
Moxi123#
url
:
jdbc:mysql://114.112.96.30:30029/NAFMII_2.1?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
username
:
root
redis
:
# Redis数据库索引(默认为0)
database
:
0
# Redis服务器地址
host
:
127.0.0.1
port
:
6379
# Redis服务器连接密码(默认为空)
password
:
jedis
:
pool
:
# 连接池最大连接数(使用负值表示没有限制)
max-active
:
20
max-wait
:
-1ms
max-idle
:
10
min-idle
:
0
timeout
:
1000ms
nafmii-common/src/main/java/org/nafmii/enums/RedisEnum.java
0 → 100644
View file @
0194e6f
package
org
.
nafmii
.
enums
;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/4/27 13:48
* @ClassName:
* @version:
* @remark:
*/
public
enum
RedisEnum
{
/**
* 验证码失效时间60s
*/
PHONECODE
(
60
,
"60秒后失效"
)
;
RedisEnum
(
Integer
code
,
String
name
){
this
.
code
=
code
;
this
.
name
=
name
;
}
private
String
name
;
private
Integer
code
;
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
Integer
getCode
()
{
return
code
;
}
public
void
setCode
(
Integer
code
)
{
this
.
code
=
code
;
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment