Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
api
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
首航-临时账号
api
Commits
239c0628
Commit
239c0628
authored
Sep 24, 2019
by
java-李谡
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加redis方法
parent
524509ec
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
8 deletions
+16
-8
UserController.java
src/com/ejweb/modules/user/api/UserController.java
+16
-8
No files found.
src/com/ejweb/modules/user/api/UserController.java
View file @
239c0628
...
...
@@ -146,21 +146,23 @@ public class UserController {
LoginBean
loginBean
=
requestBean
.
getObjectBean
(
LoginBean
.
class
);
String
message
=
userService
.
validate
(
loginBean
);
String
userIp
=
StringUtils
.
isEmpty
(
loginBean
.
getClientip
())
?
Util
.
getOnlineIP
(
request
)
:
loginBean
.
getClientip
();
LOG
.
debug
(
"[UserController login IP]"
+
userIp
);
System
.
out
.
println
(
"[UserController login IP]"
+
userIp
);
if
(
message
==
null
)
{
LoginIpInfo
loginIpInfo
=
userService
.
findByIp
(
userIp
);
String
redisUsername
=
redisUtils
.
get
(
loginBean
.
getLoginName
(),
indexDb
);
if
(
loginIpInfo
!=
null
)
{
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4102
);
System
.
out
.
println
(
"IP地址已被锁定"
);
responseBean
.
setMessage
(
"IP地址已被锁定"
);
long
endTime
=
System
.
nanoTime
();
long
duration
=
endTime
-
startTime
;
LOG
.
debug
(
"[UserController login][STATUS_CODE_4102]总共用时:"
+
Util
.
getDurationTime
(
duration
));
System
.
out
.
println
(
"[UserController login][STATUS_CODE_4102]总共用时:"
+
Util
.
getDurationTime
(
duration
));
return
responseBean
;
}
String
blackUsername
=
redisUtils
.
get
(
"black_username:"
+
loginBean
.
getLoginName
(),
indexDb
);
boolean
sealup
=
false
;
if
(
null
!=
redisUsername
&&
Integer
.
parseInt
(
redisUsername
)
>=
5
&&
StringUtils
.
isEmpty
(
blackUsername
))
{
System
.
out
.
println
(
"加入黑名单"
);
redisUtils
.
set
(
"black_username:"
+
loginBean
.
getLoginName
(),
1
,
indexDb
);
redisUtils
.
expire
(
"black_username:"
+
loginBean
.
getLoginName
(),
userSealUpSeconds
,
indexDb
);
sealup
=
true
;
...
...
@@ -169,6 +171,7 @@ public class UserController {
}
if
(
sealup
)
{
System
.
out
.
println
(
"该帐号已禁止登录"
);
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4101
);
responseBean
.
setMessage
(
"该帐号已禁止登录"
);
checkIpLimit
(
userIp
);
...
...
@@ -190,7 +193,7 @@ public class UserController {
responseBean
.
setMessage
(
"账户或密码错误"
);
long
endTime
=
System
.
nanoTime
();
long
duration
=
endTime
-
startTime
;
LOG
.
debug
(
"[UserController login][STATUS_CODE_4102]总共用时:"
+
Util
.
getDurationTime
(
duration
));
LOG
.
info
(
"[UserController login][STATUS_CODE_4102]总共用时:"
+
Util
.
getDurationTime
(
duration
));
return
responseBean
;
// 用户被查封
}
else
if
(
GConstants
.
NO
.
equals
(
userEntity
.
getLoginFlag
()))
{
...
...
@@ -200,7 +203,7 @@ public class UserController {
checkIpLimit
(
userIp
);
long
endTime
=
System
.
nanoTime
();
long
duration
=
endTime
-
startTime
;
LOG
.
debug
(
"[UserController login][STATUS_CODE_4101]总共用时:"
+
Util
.
getDurationTime
(
duration
));
LOG
.
info
(
"[UserController login][STATUS_CODE_4101]总共用时:"
+
Util
.
getDurationTime
(
duration
));
return
responseBean
;
//不是内部联系人 通讯录联系人不允许登陆
}
else
if
(!
"2"
.
equals
(
userEntity
.
getUserType
())
&&
!
"4"
.
equals
(
userEntity
.
getUserType
())
&&
!
"6"
.
equals
(
userEntity
.
getUserType
()))
{
...
...
@@ -210,7 +213,7 @@ public class UserController {
checkIpLimit
(
userIp
);
long
endTime
=
System
.
nanoTime
();
long
duration
=
endTime
-
startTime
;
LOG
.
debug
(
"[UserController login][STATUS_CODE_4101]总共用时:"
+
Util
.
getDurationTime
(
duration
));
LOG
.
info
(
"[UserController login][STATUS_CODE_4101]总共用时:"
+
Util
.
getDurationTime
(
duration
));
return
responseBean
;
}
boolean
passwordError
=
false
;
...
...
@@ -226,18 +229,21 @@ public class UserController {
}
if
(
passwordError
)
{
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4103
);
System
.
out
.
println
(
"账户或密码错误"
);
responseBean
.
setMessage
(
"账户或密码错误"
);
// 用户信息redis初始时间 增加value值
if
(
StringUtils
.
isEmpty
(
redisUsername
))
{
System
.
out
.
println
(
"账户错误初始化"
);
redisUtils
.
set
(
loginBean
.
getLoginName
(),
1
,
indexDb
);
redisUtils
.
expire
(
loginBean
.
getLoginName
(),
userOverdueSeconds
,
indexDb
);
}
else
{
System
.
out
.
println
(
"账户错误加1"
);
redisUtils
.
incrNotResetExpireTime
(
loginBean
.
getLoginName
(),
indexDb
);
}
checkIpLimit
(
userIp
);
long
endTime
=
System
.
nanoTime
();
long
duration
=
endTime
-
startTime
;
LOG
.
debug
(
"[UserController login][STATUS_CODE_4103]总共用时:"
+
Util
.
getDurationTime
(
duration
));
LOG
.
info
(
"[UserController login][STATUS_CODE_4103]总共用时:"
+
Util
.
getDurationTime
(
duration
));
return
responseBean
;
}
else
{
// 校验码登录
...
...
@@ -252,7 +258,7 @@ public class UserController {
checkIpLimit
(
userIp
);
long
endTime
=
System
.
nanoTime
();
long
duration
=
endTime
-
startTime
;
LOG
.
debug
(
"[UserController login][STATUS_CODE_4104]总共用时:"
+
Util
.
getDurationTime
(
duration
));
LOG
.
info
(
"[UserController login][STATUS_CODE_4104]总共用时:"
+
Util
.
getDurationTime
(
duration
));
return
responseBean
;
// 校验码已经失效
}
else
if
(
entity
.
getExpireTime
().
getTime
()
>
System
.
currentTimeMillis
())
{
...
...
@@ -263,7 +269,7 @@ public class UserController {
checkIpLimit
(
userIp
);
long
endTime
=
System
.
nanoTime
();
long
duration
=
endTime
-
startTime
;
LOG
.
debug
(
"[UserController login][STATUS_CODE_4105]总共用时:"
+
Util
.
getDurationTime
(
duration
));
LOG
.
info
(
"[UserController login][STATUS_CODE_4105]总共用时:"
+
Util
.
getDurationTime
(
duration
));
return
responseBean
;
}
// 修改验证码使用状态
...
...
@@ -1046,10 +1052,12 @@ public class UserController {
private
void
checkIpLimit
(
String
userIp
)
{
//如果redis没有key
if
(
redisUtils
.
get
(
userIp
,
indexDb
)
==
null
)
{
System
.
out
.
println
(
"ip错误初始化"
);
redisUtils
.
set
(
userIp
,
1
,
indexDb
);
//设置过期时间
redisUtils
.
expire
(
userIp
,
ipWithinSeconds
,
indexDb
);
}
else
{
System
.
out
.
println
(
"ip错误自增"
);
//如果存在key
redisUtils
.
incrNotResetExpireTime
(
userIp
,
indexDb
);
if
(
Integer
.
valueOf
(
redisUtils
.
get
(
userIp
,
indexDb
))
>=
ipLimitTimes
)
{
...
...
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