Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
head_group
xyqb-user2
Commits
39b1973c
Commit
39b1973c
authored
Nov 27, 2017
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
消除验证码错误记次冗余方法(测试环境即存在,未测出来)应是5次失效,实际是3次失效,现统一为3次失效
parent
92205ca3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
45 deletions
+4
-45
Constants.java
src/main/java/cn/quantgroup/xyqb/Constants.java
+1
-1
UserController.java
...ntgroup/xyqb/controller/internal/user/UserController.java
+3
-44
No files found.
src/main/java/cn/quantgroup/xyqb/Constants.java
View file @
39b1973c
...
@@ -36,7 +36,7 @@ public interface Constants {
...
@@ -36,7 +36,7 @@ public interface Constants {
String
REDIS_VERIFICATION_COUNT
=
"verification_code_count:"
;
String
REDIS_VERIFICATION_COUNT
=
"verification_code_count:"
;
Long
Image_Need_Count
=
3L
;
Long
Image_Need_Count
=
3L
;
Long
IMAG
E_FINITE_COUNT
=
3L
;
Long
VERIFICATION_COD
E_FINITE_COUNT
=
3L
;
String
X_AUTH_TOKEN
=
"x-auth-token"
;
String
X_AUTH_TOKEN
=
"x-auth-token"
;
String
ONE_TIME_TOKEN
=
"oneTimeToken"
;
String
ONE_TIME_TOKEN
=
"oneTimeToken"
;
...
...
src/main/java/cn/quantgroup/xyqb/controller/internal/user/UserController.java
View file @
39b1973c
...
@@ -296,53 +296,10 @@ public class UserController implements IBaseController {
...
@@ -296,53 +296,10 @@ public class UserController implements IBaseController {
result
.
put
(
"fail"
,
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
));
result
.
put
(
"fail"
,
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
));
return
result
;
return
result
;
}
}
// 校验短信密码
validateFastLoginVerificationCode
(
result
,
phoneNo
,
verificationCode
);
result
.
put
(
"success"
,
JsonResult
.
buildSuccessResult
(
verificationCode
,
phoneNo
));
result
.
put
(
"success"
,
JsonResult
.
buildSuccessResult
(
verificationCode
,
phoneNo
));
return
result
;
return
result
;
}
}
/**
* 短信密码校验
* @param result - Map
* @param phoneNo - 登录手机号
* @param verificationCode - 短信密码
*/
private
void
validateFastLoginVerificationCode
(
Map
<
String
,
JsonResult
>
result
,
String
phoneNo
,
String
verificationCode
)
{
if
(
smsService
.
validateFastLoginVerificationCode
(
phoneNo
,
verificationCode
))
{
return
;
}
// 短信密码错误时,给该账号添加计数器
countErrorForPhoneNo
(
result
,
phoneNo
,
verificationCode
);
}
/**
* 短信密码错误时,给该账号添加计数器
* @param result Map
* @param phoneNo 登录手机号
* @param verificationCode 短信密码
*/
private
void
countErrorForPhoneNo
(
Map
<
String
,
JsonResult
>
result
,
String
phoneNo
,
String
verificationCode
)
{
String
passwordErrorCountKey
=
Constants
.
REDIS_PASSWORD_ERROR_COUNT
+
phoneNo
;
if
(!
stringRedisTemplate
.
hasKey
(
passwordErrorCountKey
))
{
stringRedisTemplate
.
opsForValue
().
set
(
passwordErrorCountKey
,
String
.
valueOf
(
0
),
Constants
.
ONE_DAY
,
TimeUnit
.
SECONDS
);
}
LOGGER
.
info
(
"用户快速登录,验证码校验失败,phoneNo:{} , verificationCode:{}"
,
phoneNo
,
verificationCode
);
// 密码错误计数
Long
errorCount
=
stringRedisTemplate
.
opsForValue
().
increment
(
passwordErrorCountKey
,
1L
);
if
(
errorCount
>=
Constants
.
Image_Need_Count
){
// 短信密码错误次数超过上限,执行销毁
String
verificationCodeKey
=
Constants
.
REDIS_PREFIX_VERIFICATION_CODE
+
phoneNo
;
stringRedisTemplate
.
delete
(
verificationCodeKey
);
// 短信密码错误计数器归零
stringRedisTemplate
.
opsForValue
().
set
(
passwordErrorCountKey
,
String
.
valueOf
(
0
));
stringRedisTemplate
.
expire
(
passwordErrorCountKey
,
Constants
.
ONE_DAY
,
TimeUnit
.
SECONDS
);
result
.
put
(
"fail"
,
JsonResult
.
buildErrorStateResult
(
"错误次数过多,请重新获取短信验证码"
,
null
));
}
else
{
result
.
put
(
"fail"
,
JsonResult
.
buildErrorStateResult
(
"验证码不正确"
,
null
));
}
}
/**
/**
* 用户快速注册
* 用户快速注册
*
*
...
@@ -752,6 +709,8 @@ public class UserController implements IBaseController {
...
@@ -752,6 +709,8 @@ public class UserController implements IBaseController {
if
(
needRetSendCode
(
phoneNo
)){
if
(
needRetSendCode
(
phoneNo
)){
String
key
=
Constants
.
REDIS_PREFIX_VERIFICATION_CODE
+
phoneNo
;
String
key
=
Constants
.
REDIS_PREFIX_VERIFICATION_CODE
+
phoneNo
;
stringRedisTemplate
.
delete
(
key
);
stringRedisTemplate
.
delete
(
key
);
String
verificationCountKey
=
Constants
.
REDIS_VERIFICATION_COUNT
+
phoneNo
;
stringRedisTemplate
.
opsForHash
().
delete
(
verificationCountKey
,
Constants
.
REDIS_VERIFICATION_COUNT
);
throw
new
VerificationCodeErrorException
(
"验证码失效,请重新获取"
);
throw
new
VerificationCodeErrorException
(
"验证码失效,请重新获取"
);
}
}
}
}
...
@@ -764,7 +723,7 @@ public class UserController implements IBaseController {
...
@@ -764,7 +723,7 @@ public class UserController implements IBaseController {
private
boolean
needRetSendCode
(
String
phoneNo
)
{
private
boolean
needRetSendCode
(
String
phoneNo
)
{
String
verificationCountKey
=
Constants
.
REDIS_VERIFICATION_COUNT
+
phoneNo
;
String
verificationCountKey
=
Constants
.
REDIS_VERIFICATION_COUNT
+
phoneNo
;
Long
getVerificationCount
=
stringRedisTemplate
.
opsForHash
().
increment
(
verificationCountKey
,
Constants
.
REDIS_VERIFICATION_COUNT
,
1
);
Long
getVerificationCount
=
stringRedisTemplate
.
opsForHash
().
increment
(
verificationCountKey
,
Constants
.
REDIS_VERIFICATION_COUNT
,
1
);
return
(
getVerificationCount
>=
5
);
return
(
getVerificationCount
>=
Constants
.
VERIFICATION_CODE_FINITE_COUNT
);
}
}
}
}
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