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
提交
6e1f6e82
提交
6e1f6e82
编写于
9月 17, 2019
作者:
rushui.chen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
20190917 控制验证码的发送逻辑和检验测试
上级
3e62a3e1
流水线
#14592
已失败 于阶段
in 0 second
变更
8
流水线
1
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
55 行增加
和
55 行删除
+55
-55
LoginController.java
...ud/account/account/server/controller/LoginController.java
+2
-4
ModifyMobileController.java
...unt/account/server/controller/ModifyMobileController.java
+1
-2
PasswordController.java
...account/account/server/controller/PasswordController.java
+1
-2
RegisterController.java
...account/account/server/controller/RegisterController.java
+5
-3
SysCodeController.java
.../account/account/server/controller/SysCodeController.java
+28
-13
AccountExceptionEnum.java
...ud/account/account/server/enums/AccountExceptionEnum.java
+2
-1
LoginServiceImpl.java
...account/account/server/service/impl/LoginServiceImpl.java
+5
-28
AccountUtils.java
.../pica/cloud/account/account/server/util/AccountUtils.java
+11
-2
未找到文件。
server/src/main/java/com/pica/cloud/account/account/server/controller/LoginController.java
浏览文件 @
6e1f6e82
...
...
@@ -78,8 +78,7 @@ public class LoginController extends AccountBaseController {
@PostMapping
(
value
=
"/login-register"
)
public
PicaResponse
loginAndRegister
(
@RequestBody
EncryptEntity
entity
)
throws
Exception
{
BaseRequest
request
=
CryptoUtil
.
decrypt
(
entity
,
BaseRequest
.
class
);
accountUtils
.
checkMobilePhone
(
request
.
getMobile
());
accountUtils
.
getAuthCodeKey
(
request
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_LOGIN
.
getCode
()
+
""
);
accountUtils
.
checkMobilePhoneAndAuthCode
(
request
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_LOGIN
.
getCode
()
+
""
,
request
.
getSysCode
());
request
.
setProductType
(
super
.
getProductType
());
request
.
setSourceType
(
super
.
getSourceType
());
request
.
setLoginIp
(
super
.
getIpAddr
());
...
...
@@ -102,8 +101,7 @@ public class LoginController extends AccountBaseController {
@PostMapping
(
value
=
"/login/wechat/step2"
)
public
PicaResponse
loginByWeChatStep
(
@RequestBody
EncryptEntity
entity
)
throws
Exception
{
BaseRequest
request
=
CryptoUtil
.
decrypt
(
entity
,
BaseRequest
.
class
);
accountUtils
.
checkMobilePhone
(
request
.
getMobile
());
accountUtils
.
checkAuthCode
(
request
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_WE_CHAT
.
getCode
()
+
""
,
request
.
getSysCode
());
accountUtils
.
checkMobilePhoneAndAuthCode
(
request
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_WE_CHAT
.
getCode
()
+
""
,
request
.
getSysCode
());
request
.
setProductType
(
super
.
getProductType
());
request
.
setSourceType
(
super
.
getSourceType
());
request
.
setLoginIp
(
super
.
getIpAddr
());
...
...
server/src/main/java/com/pica/cloud/account/account/server/controller/ModifyMobileController.java
浏览文件 @
6e1f6e82
...
...
@@ -30,8 +30,7 @@ public class ModifyMobileController extends AccountBaseController {
Integer
acctId
=
super
.
getAcctId
();
BaseRequest
request
=
CryptoUtil
.
decrypt
(
entity
,
BaseRequest
.
class
);
String
mobile
=
request
.
getMobile
();
accountUtils
.
checkMobilePhone
(
mobile
);
accountUtils
.
checkAuthCode
(
mobile
,
AccountTypeEnum
.
SYSCODE_TYPE_MODIFY_MOBILE
.
getCode
()
+
""
,
request
.
getSysCode
());
accountUtils
.
checkMobilePhoneAndAuthCode
(
mobile
,
AccountTypeEnum
.
SYSCODE_TYPE_MODIFY_MOBILE
.
getCode
()
+
""
,
request
.
getSysCode
());
modifyMobileService
.
modify
(
acctId
,
mobile
);
return
PicaResponse
.
toResponse
();
}
...
...
server/src/main/java/com/pica/cloud/account/account/server/controller/PasswordController.java
浏览文件 @
6e1f6e82
...
...
@@ -62,8 +62,7 @@ public class PasswordController extends AccountBaseController {
@PostMapping
(
value
=
"/reset"
)
public
PicaResponse
forgetPassword
(
@RequestBody
EncryptEntity
entity
)
throws
Exception
{
BaseRequest
request
=
CryptoUtil
.
decrypt
(
entity
,
BaseRequest
.
class
);
accountUtils
.
checkMobilePhone
(
request
.
getMobile
());
accountUtils
.
checkAuthCode
(
request
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_RESET_PASSWORD
.
getCode
()
+
""
,
request
.
getSysCode
());
accountUtils
.
checkMobilePhoneAndAuthCode
(
request
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_RESET_PASSWORD
.
getCode
()
+
""
,
request
.
getSysCode
());
if
(
StringUtils
.
isEmpty
(
request
.
getPassword
()))
{
throw
new
AccountException
(
AccountExceptionEnum
.
PICA_PASSWORD_ERROR
);
}
...
...
server/src/main/java/com/pica/cloud/account/account/server/controller/RegisterController.java
浏览文件 @
6e1f6e82
...
...
@@ -23,13 +23,15 @@ public class RegisterController extends AccountBaseController {
@Autowired
private
RegisterService
registerService
;
@Autowired
private
AccountUtils
accountUtils
;
@ApiOperation
(
"注册接口"
)
@PostMapping
(
value
=
""
)
public
PicaResponse
<
String
>
register
(
@RequestBody
EncryptEntity
entity
)
throws
Exception
{
BaseRequest
request
=
CryptoUtil
.
decrypt
(
entity
,
BaseRequest
.
class
);
AccountUtils
.
checkMobilePhone
(
request
.
getMobile
());
AccountUtils
.
getAuthCodeKey
(
request
.
getSysCode
(),
AccountTypeEnum
.
SYSCODE_TYPE_REGISTER
.
getCode
()
+
""
);
AccountUtils
.
checkPassword
(
request
.
getPassword
());
accountUtils
.
checkMobilePhoneAndAuthCode
(
request
.
getMobile
(),
AccountTypeEnum
.
SYSCODE_TYPE_REGISTER
.
getCode
()+
""
,
request
.
getSysCode
());
accountUtils
.
checkPassword
(
request
.
getPassword
());
request
.
setFlag
(
AccountTypeEnum
.
SYSCODE_TYPE_REGISTER
.
getCode
());
request
.
setProductType
(
super
.
getProductType
());
request
.
setSourceType
(
super
.
getSourceType
());
...
...
server/src/main/java/com/pica/cloud/account/account/server/controller/SysCodeController.java
浏览文件 @
6e1f6e82
package
com
.
pica
.
cloud
.
account
.
account
.
server
.
controller
;
import
com.pica.cloud.account.account.server.entity.Account
;
import
com.pica.cloud.account.account.server.entity.AccountInfoEntity
;
import
com.pica.cloud.account.account.server.entity.AccountUnionEntity
;
import
com.pica.cloud.account.account.server.entity.EncryptEntity
;
...
...
@@ -15,8 +16,10 @@ import com.pica.cloud.foundation.entity.PicaResponse;
import
com.pica.cloud.foundation.redis.ICacheClient
;
import
com.pica.cloud.foundation.utils.utils.CommonUtil
;
import
com.pica.cloud.foundation.utils.utils.EncryptCreateUtil
;
import
com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
...
@@ -41,7 +44,6 @@ public class SysCodeController extends AccountBaseController {
@Qualifier
(
"cacheMigrateClient"
)
private
ICacheClient
cacheClient
;
/**
* 必须要传递flag类型
*
...
...
@@ -75,27 +77,40 @@ public class SysCodeController extends AccountBaseController {
/**
* 验证码发送逻辑
* 1)随机数生成验证码;
* 2)验证码失效时间十分钟;
* 3)同一个业务一个手机号一分钟只能发送一次:提示:请X秒后重试.(用手机号区别用户,用flag区别业务类型)
*
* @param mobilePhone
* @param flag
*/
private
void
processSysCode
(
String
mobilePhone
,
Integer
flag
)
{
//随机生成验证码
String
authCode
=
CommonUtil
.
createValidateCode
();
String
message
=
"您的验证码是"
+
authCode
+
",在10分钟内有效。如非本人操作,请忽略本短信!"
;
//判断账号是否已经存在
AccountInfoEntity
accountInfoEntity
=
accountInfoDetailMapper
.
selectByMobile
(
mobilePhone
);
long
senderId
=
accountInfoEntity
==
null
?
0L
:
accountInfoEntity
.
getId
();
//验证码保存到redis,失效时间10分钟
cacheClient
.
set
(
this
.
getAuthCodeKey
(
mobilePhone
,
flag
+
""
),
authCode
,
600
);
//发送短信
super
.
sendMobileMessage
(
mobilePhone
,
message
,
senderId
);
String
authCodeKey
=
this
.
getAuthCodeKey
(
mobilePhone
,
flag
.
toString
());
String
authCodeKeySecure
=
authCodeKey
+
"-secure"
;
//如果存在,说明刚刚发送过验证码
if
(
cacheClient
.
exists
(
authCodeKey
))
{
Long
time
=
cacheClient
.
get
(
this
.
getAuthCodeKey
(
mobilePhone
,
flag
.
toString
())
+
"-secure"
,
Long
.
class
);
if
(
time
==
null
)
{
time
=
0L
;
}
int
remainTime
=
59
-
(
int
)
(
System
.
currentTimeMillis
()
-
time
)
/
1000
;
if
(
remainTime
>
0
)
{
throw
new
AccountException
(
AccountExceptionEnum
.
PICA_SYSCODE_RETRY
.
getCode
(),
AccountExceptionEnum
.
PICA_SYSCODE_RETRY
.
getMessage
().
replace
(
"X"
,
String
.
valueOf
(
remainTime
)));
}
}
else
{
String
authCode
=
CommonUtil
.
createValidateCode
();
String
message
=
"您的验证码是"
+
authCode
+
",在10分钟内有效。如非本人操作,请忽略本短信!"
;
AccountInfoEntity
accountInfoEntity
=
accountInfoDetailMapper
.
selectByMobile
(
mobilePhone
);
long
senderId
=
accountInfoEntity
==
null
?
0L
:
accountInfoEntity
.
getId
();
cacheClient
.
set
(
this
.
getAuthCodeKey
(
mobilePhone
,
flag
.
toString
()),
authCode
,
600
);
cacheClient
.
set
(
authCodeKeySecure
,
System
.
currentTimeMillis
(),
60
);
super
.
sendMobileMessage
(
mobilePhone
,
message
,
senderId
);
}
}
//获取验证码redis key
private
String
getAuthCodeKey
(
String
mobilePhone
,
String
flag
)
{
return
AUTH_CODE_PREFIX
+
flag
+
"-"
+
EncryptCreateUtil
.
encrypt
(
mobilePhone
);
}
}
server/src/main/java/com/pica/cloud/account/account/server/enums/AccountExceptionEnum.java
浏览文件 @
6e1f6e82
...
...
@@ -22,7 +22,8 @@ public enum AccountExceptionEnum {
PICA_PASSWORD_EQUAL
(
"216514"
,
"旧密码与新密码不能相同"
),
PICA_UNBIND_MOBILE
(
"216515"
,
"该手机号未绑定微信"
),
PICA_MOBILE_SAME
(
"216516"
,
"新手机号与旧手机号不能相同"
),
PICA_PARAMS_ERROR
(
"216517"
,
"传递参数有误"
);
PICA_PARAMS_ERROR
(
"216517"
,
"传递参数有误"
),
PICA_SYSCODE_RETRY
(
"216518"
,
"请X秒后重试"
);
private
String
code
;
...
...
server/src/main/java/com/pica/cloud/account/account/server/service/impl/LoginServiceImpl.java
浏览文件 @
6e1f6e82
...
...
@@ -4,11 +4,14 @@ package com.pica.cloud.account.account.server.service.impl;
import
com.alibaba.fastjson.JSONObject
;
import
com.pica.cloud.account.account.server.constants.Constants
;
import
com.pica.cloud.account.account.server.entity.*
;
import
com.pica.cloud.account.account.server.enums.AccountTypeEnum
;
import
com.pica.cloud.account.account.server.enums.AccountExceptionEnum
;
import
com.pica.cloud.account.account.server.enums.AccountTypeEnum
;
import
com.pica.cloud.account.account.server.log.AccountLogEntityUtils
;
import
com.pica.cloud.account.account.server.log.AccountLogUtils
;
import
com.pica.cloud.account.account.server.mapper.*
;
import
com.pica.cloud.account.account.server.mapper.AccountInfoDetailMapper
;
import
com.pica.cloud.account.account.server.mapper.AccountUnionMapper
;
import
com.pica.cloud.account.account.server.mapper.AccountWeChatInfoMapper
;
import
com.pica.cloud.account.account.server.mapper.DoctorMapper
;
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.LoginService
;
...
...
@@ -17,10 +20,8 @@ import com.pica.cloud.account.account.server.util.AccountUtils;
import
com.pica.cloud.account.account.server.util.TokenUtils
;
import
com.pica.cloud.account.account.server.util.WeChatUtils
;
import
com.pica.cloud.foundation.entity.PicaException
;
import
com.pica.cloud.foundation.entity.PicaResultCode
;
import
com.pica.cloud.foundation.redis.ICacheClient
;
import
com.pica.cloud.foundation.utils.utils.EncryptCreateUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -136,12 +137,6 @@ public class LoginServiceImpl implements LoginService {
private
String
processLogin
(
BaseRequest
baseRequest
,
Integer
acctId
,
Integer
loginType
)
{
Date
currentTime
=
new
Date
();
Long
userId
=
accountUtils
.
getUserIdByAcctId
(
baseRequest
.
getProductType
(),
acctId
);
//验证码登陆:只要相同即可成功
AccountReq
accountReq
=
new
AccountReq
();
accountReq
.
setAuthCode
(
baseRequest
.
getSysCode
());
accountReq
.
setMobilePhone
(
baseRequest
.
getMobile
());
accountReq
.
setFlag
(
"0"
);
checkAuthCode
(
accountReq
);
Account
account
=
new
Account
();
account
.
setId
(
userId
);
account
.
setAcctId
(
acctId
);
...
...
@@ -297,22 +292,4 @@ public class LoginServiceImpl implements LoginService {
accountWeChatInfoEntity
.
setLanguage
(
weChatUserInfoEntity
.
getLanguage
());
accountWeChatInfoMapper
.
insertSelective
(
accountWeChatInfoEntity
);
}
//校验验证码
private
void
checkAuthCode
(
AccountReq
req
)
{
String
flag
=
StringUtils
.
isBlank
(
req
.
getFlag
())
?
"0"
:
req
.
getFlag
();
if
(
StringUtils
.
isBlank
(
req
.
getAuthCode
()))
{
throw
new
PicaException
(
PicaResultCode
.
PARAM_IS_INVALID
.
code
(),
"短信验证码错误"
);
}
String
authCodeKey
=
AccountUtils
.
getAuthCodeKey
(
req
.
getMobilePhone
(),
flag
);
String
cacheCode
=
redisClient
.
get
(
authCodeKey
);
//从redis获取验证码
if
(
StringUtils
.
isBlank
(
cacheCode
))
{
throw
new
PicaException
(
PicaResultCode
.
RESULE_DATA_NONE
.
code
(),
"短信验证码已过期,请重新获取"
);
}
if
(!
StringUtils
.
equals
(
req
.
getAuthCode
(),
cacheCode
))
{
throw
new
PicaException
(
PicaResultCode
.
PARAM_IS_INVALID
.
code
(),
"短信验证码错误"
);
}
//清除验证码
redisClient
.
del
(
authCodeKey
);
}
}
server/src/main/java/com/pica/cloud/account/account/server/util/AccountUtils.java
浏览文件 @
6e1f6e82
...
...
@@ -33,6 +33,7 @@ public class AccountUtils {
private
DoctorMapper
doctorInfoMapper
;
private
static
final
String
AUTH_CODE_PREFIX
=
"authCode-"
;
private
static
final
String
AUTH_CODE_COUNT_PREFIX
=
"authCode-count-"
;
//手机格式校验
public
static
void
checkMobilePhone
(
String
mobilePhone
)
{
...
...
@@ -81,11 +82,19 @@ public class AccountUtils {
throw
new
PicaException
(
PicaResultCode
.
PARAM_IS_INVALID
.
code
(),
"短信验证码错误"
);
}
String
authCodeKey
=
AccountUtils
.
getAuthCodeKey
(
mobile
,
flag
);
//验证码3次校验测试不通过,直接删除
String
authCodeCount
=
AUTH_CODE_COUNT_PREFIX
+
flag
+
"-"
+
EncryptCreateUtil
.
encrypt
(
mobile
);
if
(
cacheClient
.
exists
(
authCodeCount
)
&&
Integer
.
parseInt
(
cacheClient
.
get
(
authCodeCount
))
>
2
)
{
cacheClient
.
del
(
authCodeKey
);
}
String
cacheCode
=
cacheClient
.
get
(
authCodeKey
);
//从redis获取验证码
if
(
org
.
apache
.
commons
.
lang
.
StringUtils
.
isBlank
(
cacheCode
))
{
throw
new
PicaException
(
PicaResultCode
.
RESULE_DATA_NONE
.
code
(),
"短信验证码已过期,请重新获取"
);
//第四次删除计数器
cacheClient
.
del
(
authCodeCount
);
throw
new
PicaException
(
PicaResultCode
.
RESULE_DATA_NONE
.
code
(),
"短信验证码已失效,请重新获取"
);
}
if
(!
org
.
apache
.
commons
.
lang
.
StringUtils
.
equals
(
sysCode
,
cacheCode
))
{
cacheClient
.
incr
(
authCodeCount
);
throw
new
PicaException
(
PicaResultCode
.
PARAM_IS_INVALID
.
code
(),
"短信验证码错误"
);
}
cacheClient
.
del
(
authCodeKey
);
...
...
@@ -111,7 +120,7 @@ public class AccountUtils {
* @return
*/
public
static
String
getSourceType
(
Integer
registerSource
)
{
String
sourceType
=
null
;
String
sourceType
=
StringUtils
.
EMPTY
;
switch
(
registerSource
)
{
case
3
:
sourceType
=
"web"
;
...
...
写
预览
Markdown
格式
0%
请重试
or
附加一个文件
附加文件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录