Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
P
pica-cloud-account
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
Close sidebar
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
com.pica.cloud.account
pica-cloud-account
提交
b17bb585
提交
b17bb585
编写于
1月 09, 2020
作者:
rushui.chen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
“20200109 校验验证码的原子操作
上级
f7935d22
流水线
#20531
已失败 于阶段
in 1 second
变更
7
流水线
1
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
65 行增加
和
8 行删除
+65
-8
AccountController.java
.../account/account/server/controller/AccountController.java
+4
-2
AutoCodeController.java
...account/account/server/controller/AutoCodeController.java
+8
-3
LoginController.java
...ud/account/account/server/controller/LoginController.java
+0
-1
RegisterController.java
...account/account/server/controller/RegisterController.java
+2
-1
LoginServiceImpl.java
...account/account/server/service/impl/LoginServiceImpl.java
+3
-0
AccountUtils.java
.../pica/cloud/account/account/server/util/AccountUtils.java
+20
-1
RegisterCodeKeyUtils.java
...oud/account/account/server/util/RegisterCodeKeyUtils.java
+28
-0
未找到文件。
server/src/main/java/com/pica/cloud/account/account/server/controller/AccountController.java
浏览文件 @
b17bb585
...
...
@@ -9,6 +9,7 @@ import com.pica.cloud.account.account.server.req.AccountReq;
import
com.pica.cloud.account.account.server.req.BaseRequest
;
import
com.pica.cloud.account.account.server.service.AccountService
;
import
com.pica.cloud.account.account.server.service.CaptchaService
;
import
com.pica.cloud.account.account.server.util.AccountUtils
;
import
com.pica.cloud.account.account.server.util.CryptoUtil
;
import
com.pica.cloud.foundation.encryption.common.constants.EncryptConstants
;
import
com.pica.cloud.foundation.encryption.util.EncryptUtils
;
...
...
@@ -53,8 +54,9 @@ public class AccountController extends AccountBaseController {
@Autowired
private
CaptchaService
captchaService
;
@Autowired
private
ICacheClient
redisClient
;
@Autowired
private
AccountUtils
accountUtils
;
@GetMapping
(
"/test"
)
public
String
test
()
{
...
...
@@ -159,7 +161,7 @@ public class AccountController extends AccountBaseController {
// @PostMapping("/register")
public
PicaResponse
<
LoginResult
>
register
(
@RequestBody
AccountReq
req
)
{
this
.
checkMobilePhone
(
req
.
getMobilePhone
());
this
.
checkAuthCode
(
req
);
accountUtils
.
checkRegisterMobilePhoneAndAuthCode
(
req
.
getMobilePhone
(),
req
.
getFlag
(),
req
.
getAuthCode
()
);
String
deviceType
=
super
.
getDeviceInfo
(
"device_type"
);
//1:pc 2:android 3:ios
Account
account
=
new
Account
();
account
.
setMobilePhone
(
EncryptUtils
.
encryptContent
(
req
.
getMobilePhone
(),
EncryptConstants
.
ENCRYPT_TYPE_MOBILE
));
...
...
server/src/main/java/com/pica/cloud/account/account/server/controller/AutoCodeController.java
浏览文件 @
b17bb585
...
...
@@ -15,6 +15,7 @@ import com.pica.cloud.account.account.server.service.CaptchaService;
import
com.pica.cloud.account.account.server.util.AESUtil
;
import
com.pica.cloud.account.account.server.util.AccountUtils
;
import
com.pica.cloud.account.account.server.util.CryptoUtil
;
import
com.pica.cloud.account.account.server.util.RegisterCodeKeyUtils
;
import
com.pica.cloud.foundation.entity.PicaException
;
import
com.pica.cloud.foundation.entity.PicaResponse
;
import
com.pica.cloud.foundation.entity.PicaResultCode
;
...
...
@@ -150,9 +151,13 @@ public class AutoCodeController extends AccountBaseController {
String
message
=
"您的验证码是"
+
authCode
+
",在10分钟内有效。如非本人操作,请忽略本短信!"
;
Integer
accountIdByMobilePhone
=
accountService
.
getAccountIdByMobilePhone
(
mobilePhone
);
long
senderId
=
accountIdByMobilePhone
==
null
?
0L
:
accountIdByMobilePhone
;
cacheClient
.
set
(
this
.
getAuthCodeKey
(
mobilePhone
,
flag
.
toString
()),
authCode
,
600
);
logger
.
info
(
"验证码缓存信息----->:"
+
this
.
getAuthCodeKey
(
mobilePhone
,
flag
.
toString
()));
cacheClient
.
set
(
authCodeKeySecure
,
System
.
currentTimeMillis
(),
60
);
if
(
flag
==
1
){
cacheClient
.
set
(
RegisterCodeKeyUtils
.
getRegisterKey
(
mobilePhone
,
flag
.
toString
(),
authCode
),
mobilePhone
,
600
);
}
else
{
cacheClient
.
set
(
this
.
getAuthCodeKey
(
mobilePhone
,
flag
.
toString
()),
authCode
,
600
);
logger
.
info
(
"验证码缓存信息----->:"
+
this
.
getAuthCodeKey
(
mobilePhone
,
flag
.
toString
()));
cacheClient
.
set
(
authCodeKeySecure
,
System
.
currentTimeMillis
(),
60
);
}
super
.
sendMobileMessage
(
mobilePhone
,
message
,
senderId
);
}
...
...
server/src/main/java/com/pica/cloud/account/account/server/controller/LoginController.java
浏览文件 @
b17bb585
...
...
@@ -84,7 +84,6 @@ public class LoginController extends AccountBaseController {
@PostMapping
(
value
=
"/login-register"
)
public
PicaResponse
<
LoginResult
>
loginAndRegister
(
@RequestBody
EncryptEntity
entity
)
throws
Exception
{
BaseRequest
request
=
CryptoUtil
.
decrypt
(
entity
,
BaseRequest
.
class
);
accountUtils
.
checkMobilePhoneAndAuthCode
(
request
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_LOGIN
.
getCode
()
+
""
,
request
.
getAuthCode
());
request
.
setProductType
(
super
.
getProductType
());
Integer
sourceType
=
super
.
getSourceType
();
request
.
setSourceType
(
sourceType
);
...
...
server/src/main/java/com/pica/cloud/account/account/server/controller/RegisterController.java
浏览文件 @
b17bb585
...
...
@@ -41,7 +41,8 @@ public class RegisterController extends AccountBaseController {
//接口幂等性处理(redis中没有就进行注册逻辑,如果已经存在,就不处理)
String
authCode
=
request
.
getAuthCode
();
String
flag
=
AccountTypeEnum
.
SYSCODE_TYPE_REGISTER
.
getCode
()
+
""
;
accountUtils
.
checkMobilePhoneAndAuthCode
(
mobile
,
flag
,
authCode
);
//验证码验证的原子操作
accountUtils
.
checkRegisterMobilePhoneAndAuthCode
(
mobile
,
flag
,
authCode
);
accountUtils
.
checkPassword
(
request
.
getPassword
());
LoginResult
result
=
null
;
request
.
setFlag
(
AccountTypeEnum
.
SYSCODE_TYPE_REGISTER
.
getCode
());
...
...
server/src/main/java/com/pica/cloud/account/account/server/service/impl/LoginServiceImpl.java
浏览文件 @
b17bb585
...
...
@@ -151,8 +151,11 @@ public class LoginServiceImpl implements LoginService {
String
mobile
=
baseRequest
.
getMobile
();
AccountInfoEntity
accountInfoEntity
=
accountInfoDetailMapper
.
selectByMobile
(
AESUtil
.
encryptV0
(
mobile
));
if
(
accountInfoEntity
==
null
)
{
//一键注册和登录验证码的逻辑不同
accountUtils
.
checkRegisterMobilePhoneAndAuthCode
(
baseRequest
.
getMobile
(),
baseRequest
.
getFlag
()+
""
,
baseRequest
.
getAuthCode
());
return
registerService
.
register
(
baseRequest
);
}
else
{
accountUtils
.
checkMobilePhoneAndAuthCode
(
baseRequest
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_LOGIN
.
getCode
()
+
""
,
baseRequest
.
getAuthCode
());
return
processLogin
(
baseRequest
,
accountInfoEntity
.
getId
(),
AccountTypeEnum
.
LOGIN_CODE
.
getCode
());
}
}
...
...
server/src/main/java/com/pica/cloud/account/account/server/util/AccountUtils.java
浏览文件 @
b17bb585
...
...
@@ -89,7 +89,7 @@ public class AccountUtils {
//验证码3次校验测试不通过,直接删除
String
authCodeCount
=
AUTH_CODE_COUNT_PREFIX
+
flag
+
"-"
+
AESUtil
.
encryptV0
(
mobile
);
logger
.
info
(
"验证码缓存信息----->:"
+
this
.
getAuthCodeKey
(
mobile
,
flag
));
logger
.
info
(
"验证码缓存信息----->:"
+
this
.
getAuthCodeKey
(
mobile
,
flag
));
if
(
cacheClient
.
exists
(
authCodeCount
)
&&
Integer
.
parseInt
(
cacheClient
.
get
(
authCodeCount
))
>
2
)
{
cacheClient
.
del
(
authCodeKey
);
...
...
@@ -108,6 +108,25 @@ public class AccountUtils {
cacheClient
.
del
(
authCodeKey
);
}
public
void
checkRegisterMobilePhoneAndAuthCode
(
String
mobile
,
String
type
,
String
sysCode
)
{
if
(
StringUtils
.
isBlank
(
mobile
)
||
!
ValidateUtils
.
isMobile
(
mobile
))
{
throw
new
PicaException
(
PicaResultCode
.
PARAM_IS_INVALID
.
code
(),
"请输入正确的手机号"
);
}
String
flag
=
org
.
apache
.
commons
.
lang
.
StringUtils
.
isBlank
(
type
)
?
"0"
:
type
;
if
(
org
.
apache
.
commons
.
lang
.
StringUtils
.
isBlank
(
sysCode
))
{
throw
new
PicaException
(
PicaResultCode
.
PARAM_IS_INVALID
.
code
(),
"短信验证码错误"
);
}
String
authCodeKey
=
RegisterCodeKeyUtils
.
getRegisterKey
(
mobile
,
flag
,
sysCode
);
//从redis中删除短信验证码,如果能够删除成功,说明验证码正确
Long
num
=
cacheClient
.
del
(
authCodeKey
);
logger
.
info
(
"key"
+
authCodeKey
);
logger
.
info
(
"success"
+
num
);
if
(
num
!=
1
)
{
throw
new
PicaException
(
PicaResultCode
.
RESULE_DATA_NONE
.
code
(),
"短信验证码错误"
);
}
}
/**
* 请求参数解密、反序列化
*
...
...
server/src/main/java/com/pica/cloud/account/account/server/util/RegisterCodeKeyUtils.java
0 → 100644
浏览文件 @
b17bb585
package
com
.
pica
.
cloud
.
account
.
account
.
server
.
util
;
/**
* Created on 2020/1/9 16:18
* author:crs
* Description:注册验证码的key规则
*/
public
class
RegisterCodeKeyUtils
{
private
static
final
String
AUTH_CODE_PREFIX
=
"authCode-"
;
/**
* 获取注册验证码的key
*
* @param mobilePhone
* @param flag
* @param authCode
* @return
*/
public
static
String
getRegisterKey
(
String
mobilePhone
,
String
flag
,
String
authCode
)
{
return
AUTH_CODE_PREFIX
+
flag
+
"-"
+
AESUtil
.
encryptV0
(
mobilePhone
)
+
authCode
;
}
}
写
预览
Markdown
格式
0%
请重试
or
附加一个文件
附加文件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录