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
提交
9d008dd3
提交
9d008dd3
编写于
3月 10, 2020
作者:
Chongwen.jiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
短信服务调用失败抛异常,密码登录-锁定24小时逻辑添加
上级
640e6b8f
流水线
#22577
已失败 于阶段
in 0 second
变更
5
流水线
1
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
50 行增加
和
14 行删除
+50
-14
Constants.java
...ica/cloud/account/account/server/constants/Constants.java
+2
-0
AccountBaseController.java
...ount/account/server/controller/AccountBaseController.java
+20
-4
PasswordController.java
...account/account/server/controller/PasswordController.java
+1
-1
LoginServiceImpl.java
...account/account/server/service/impl/LoginServiceImpl.java
+15
-7
PasswordServiceImpl.java
...ount/account/server/service/impl/PasswordServiceImpl.java
+12
-2
未找到文件。
server/src/main/java/com/pica/cloud/account/account/server/constants/Constants.java
浏览文件 @
9d008dd3
...
...
@@ -47,6 +47,8 @@ public class Constants {
/** 密码登录错误次数缓存key */
public
static
final
String
PWD_ERROR_NUM_KEY
=
"pwd-error-{mobile}"
;
/** 账号锁定缓存key */
public
static
final
String
ACCOUNT_LOCK_KEY
=
"account-lock-{mobile}"
;
/** 密码登录错误次数缓存时长*/
public
static
final
int
PWD_ERROR_NUM_SECONDS
=
24
*
60
*
60
;
...
...
server/src/main/java/com/pica/cloud/account/account/server/controller/AccountBaseController.java
浏览文件 @
9d008dd3
package
com
.
pica
.
cloud
.
account
.
account
.
server
.
controller
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONException
;
import
com.alibaba.fastjson.JSONObject
;
import
com.pica.cloud.account.account.server.configuration.PropertiesConfiguration
;
import
com.pica.cloud.account.account.server.constants.Constants
;
...
...
@@ -9,6 +10,7 @@ import com.pica.cloud.account.account.server.enums.AccountExceptionEnum;
import
com.pica.cloud.account.account.server.exception.AccountException
;
import
com.pica.cloud.account.account.server.util.PICAPSendMsgModel
;
import
com.pica.cloud.foundation.entity.PicaException
;
import
com.pica.cloud.foundation.entity.PicaResponse
;
import
com.pica.cloud.foundation.entity.PicaResultCode
;
import
com.pica.cloud.foundation.entity.PicaWarnException
;
import
com.pica.cloud.foundation.utils.constants.SysCode
;
...
...
@@ -129,13 +131,27 @@ public abstract class AccountBaseController extends BaseController {
String
postData
=
JSON
.
toJSONString
(
picapSendMsgModel
);
String
jsonObj
=
HttpClientUtil
.
httpExecute
(
messageUrl
,
postData
);
if
(
StringUtils
.
isNotBlank
(
jsonObj
))
{
logger
.
info
(
"发送短信成功,返回结果:{}"
,
jsonObj
);
}
else
{
logger
.
error
(
"发送短信失败"
);
if
(
StringUtils
.
isEmpty
(
jsonObj
))
{
logger
.
error
(
"send message fail, response is empty"
);
throw
new
PicaWarnException
(
AccountExceptionEnum
.
PICA_MESSAGE_SERVICE_CALL_FAIL
.
getCode
(),
AccountExceptionEnum
.
PICA_MESSAGE_SERVICE_CALL_FAIL
.
getMessage
());
}
try
{
PicaResponse
resp
=
JSON
.
parseObject
(
jsonObj
,
PicaResponse
.
class
);
if
(
Objects
.
nonNull
(
resp
)
&&
PicaResultCode
.
SUCCESS
.
code
().
equals
(
resp
.
getCode
())){
logger
.
info
(
"send message success, the result is: {}"
,
jsonObj
);
}
else
{
logger
.
error
(
"send message fail, response code not equals success code"
);
throw
new
PicaWarnException
(
AccountExceptionEnum
.
PICA_MESSAGE_SERVICE_CALL_FAIL
.
getCode
(),
AccountExceptionEnum
.
PICA_MESSAGE_SERVICE_CALL_FAIL
.
getMessage
());
}
}
catch
(
JSONException
e
)
{
logger
.
error
(
"send message fail, response object is not a json object"
);
throw
new
PicaWarnException
(
AccountExceptionEnum
.
PICA_MESSAGE_SERVICE_CALL_FAIL
.
getCode
(),
AccountExceptionEnum
.
PICA_MESSAGE_SERVICE_CALL_FAIL
.
getMessage
());
}
}
/**
...
...
server/src/main/java/com/pica/cloud/account/account/server/controller/PasswordController.java
浏览文件 @
9d008dd3
...
...
@@ -104,7 +104,7 @@ public class PasswordController extends AccountBaseController {
}
else
{
// 新版-已注册了的则找回密码
reSetPwd
(
request
,
account
);
// 后台生成token返回
// 后台生成token返回
,删除账号锁定缓存
return
PicaResponse
.
toResponse
(
passwordService
.
findPwdLogin
(
request
,
account
));
}
}
else
{
...
...
server/src/main/java/com/pica/cloud/account/account/server/service/impl/LoginServiceImpl.java
浏览文件 @
9d008dd3
...
...
@@ -136,25 +136,33 @@ public class LoginServiceImpl implements LoginService {
AccountExceptionEnum
.
PICA_PASSWORD_RULE_ERROR
.
getMessage
()
.
replace
(
"{mobile}"
,
mobile
));
}
else
{
// 判断账号是否已锁
logger
.
info
(
"new login failure:"
+
mobile
);
String
lockKey
=
Constants
.
ACCOUNT_LOCK_KEY
.
replace
(
"{mobile}"
,
mobile
);
if
(
redisClient
.
exists
(
lockKey
))
{
throw
new
PicaException
(
AccountExceptionEnum
.
PICA_PWD_MISMATCH_5
.
getCode
(),
AccountExceptionEnum
.
PICA_PWD_MISMATCH_5
.
getMessage
().
replace
(
"{mobile}"
,
mobile
));
}
if
(
password
.
equals
(
oldPwd
))
{
return
pwdLoginCorrect
(
request
,
mobile
,
encrypt
,
accountInfoEntity
);
}
else
{
// 从缓存取出当前账号密码错误次数
logger
.
info
(
"new login failure:"
+
mobile
);
String
key
=
Constants
.
PWD_ERROR_NUM_KEY
.
replace
(
"{mobile}"
,
mobile
);
if
(
redisClient
.
exists
(
key
))
{
int
errorCount
=
Integer
.
parseInt
(
redisClient
.
get
(
key
));
String
errorKey
=
Constants
.
PWD_ERROR_NUM_KEY
.
replace
(
"{mobile}"
,
mobile
);
if
(
redisClient
.
exists
(
errorKey
))
{
int
errorCount
=
Integer
.
parseInt
(
redisClient
.
get
(
errorKey
));
errorCount
=
errorCount
+
1
;
redisClient
.
set
(
k
ey
,
errorCount
,
Constants
.
PWD_ERROR_NUM_SECONDS
);
redisClient
.
set
(
errorK
ey
,
errorCount
,
Constants
.
PWD_ERROR_NUM_SECONDS
);
if
(
errorCount
<=
4
)
{
throw
new
PicaException
(
AccountExceptionEnum
.
PICA_PWD_MISMATCH_4
.
getCode
(),
AccountExceptionEnum
.
PICA_PWD_MISMATCH_4
.
getMessage
());
}
else
{
// 设置账号锁定24h
redisClient
.
set
(
lockKey
,
mobile
,
Constants
.
PWD_ERROR_NUM_SECONDS
);
throw
new
PicaException
(
AccountExceptionEnum
.
PICA_PWD_MISMATCH_5
.
getCode
(),
AccountExceptionEnum
.
PICA_PWD_MISMATCH_5
.
getMessage
().
replace
(
"{mobile}"
,
mobile
));
}
}
else
{
redisClient
.
set
(
k
ey
,
1
,
Constants
.
PWD_ERROR_NUM_SECONDS
);
redisClient
.
set
(
errorK
ey
,
1
,
Constants
.
PWD_ERROR_NUM_SECONDS
);
throw
new
PicaException
(
AccountExceptionEnum
.
PICA_PWD_MISMATCH_4
.
getCode
(),
AccountExceptionEnum
.
PICA_PWD_MISMATCH_4
.
getMessage
());
}
...
...
server/src/main/java/com/pica/cloud/account/account/server/service/impl/PasswordServiceImpl.java
浏览文件 @
9d008dd3
package
com
.
pica
.
cloud
.
account
.
account
.
server
.
service
.
impl
;
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.AccountExceptionEnum
;
import
com.pica.cloud.account.account.server.enums.AccountTypeEnum
;
...
...
@@ -15,6 +16,7 @@ import com.pica.cloud.account.account.server.util.AccountUtils;
import
com.pica.cloud.account.account.server.util.TokenUtils
;
import
com.pica.cloud.foundation.encryption.common.constants.EncryptConstants
;
import
com.pica.cloud.foundation.encryption.util.EncryptUtils
;
import
com.pica.cloud.foundation.redis.ICacheClient
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
...
...
@@ -46,6 +48,9 @@ public class PasswordServiceImpl implements PasswordService {
@Autowired
private
DoctorMapper
doctorInfoMapper
;
@Autowired
private
ICacheClient
cacheClient
;
@Override
@Transactional
...
...
@@ -105,7 +110,7 @@ public class PasswordServiceImpl implements PasswordService {
}
/**
* @Description 重置密码-自动登录(生成token)
* @Description 重置密码-自动登录(生成token)
,删除账号锁定缓存
* @Author Chongwen.jiang
* @Date 2020/3/3 17:44
* @ModifyDate 2020/3/3 17:44
...
...
@@ -127,11 +132,16 @@ public class PasswordServiceImpl implements PasswordService {
result
.
setUserId
(
userId
);
result
.
setMobile
(
request
.
getMobile
());
result
.
setDoctorId
(
EncryptUtils
.
encryptContent
(
userId
+
""
,
EncryptConstants
.
ENCRYPT_TYPE_ID
));
//是否完善过个人信息(云鹊医app才需要)
//
是否完善过个人信息(云鹊医app才需要)
if
(
request
.
getProductType
()
==
AccountTypeEnum
.
PRODUCT_TYPE_DOCTOR
.
getCode
())
{
Doctor
doctorEntity
=
doctorInfoMapper
.
selectByPrimaryKey
(
userId
.
intValue
());
result
.
setEntireFlag
(
doctorEntity
.
getEntireFlag
());
}
// 删除账号锁定缓存
String
lockKey
=
Constants
.
ACCOUNT_LOCK_KEY
.
replace
(
"{mobile}"
,
request
.
getMobile
());
if
(
cacheClient
.
exists
(
lockKey
))
{
cacheClient
.
del
(
lockKey
);
}
return
result
;
}
...
...
写
预览
Markdown
格式
0%
请重试
or
附加一个文件
附加文件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录