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
6753e606
Commit
6753e606
authored
Sep 23, 2019
by
zt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改
parent
f7650884
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
5 deletions
+83
-5
redis.properties
resources/redis.properties
+4
-2
PropertiesUtils.java
src/com/ejweb/core/util/PropertiesUtils.java
+31
-0
RedisUtils.java
src/com/ejweb/core/util/RedisUtils.java
+17
-0
UserController.java
src/com/ejweb/modules/user/api/UserController.java
+31
-3
No files found.
resources/redis.properties
View file @
6753e606
...
@@ -7,4 +7,6 @@ redis.maxIdle=20
...
@@ -7,4 +7,6 @@ redis.maxIdle=20
redis.maxWaitMillis
=
10000
redis.maxWaitMillis
=
10000
redis.testOnBorrow
=
true
redis.testOnBorrow
=
true
redis.testOnReturn
=
true
redis.testOnReturn
=
true
redis.dbIndex
=
3
redis.dbIndex
=
3
\ No newline at end of file
ipWithinSeconds
=
3600
ipLimitTimes
=
25
\ No newline at end of file
src/com/ejweb/core/util/PropertiesUtils.java
0 → 100644
View file @
6753e606
package
com
.
ejweb
.
core
.
util
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.util.Properties
;
/**
* @author zangtao
*/
public
class
PropertiesUtils
{
private
static
Properties
properties
;
/**
* 获取配置文件中配置信息
*/
static
{
}
public
static
Properties
getProperties
(){
if
(
properties
==
null
){
properties
=
new
Properties
();
try
{
properties
.
load
(
new
InputStreamReader
(
PropertiesUtils
.
class
.
getClassLoader
().
getResourceAsStream
(
"redis.properties"
),
"UTF-8"
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
properties
;
}
}
src/com/ejweb/core/util/RedisUtils.java
View file @
6753e606
...
@@ -18,6 +18,23 @@ public class RedisUtils {
...
@@ -18,6 +18,23 @@ public class RedisUtils {
private
JedisPool
jedisPool
;
private
JedisPool
jedisPool
;
/**
/**
* 删除key
*
* @param key
* @param indexDb
* @return
*/
public
long
del
(
String
key
,
int
indexDb
)
{
Jedis
jedis
=
jedisPool
.
getResource
();
jedis
.
select
(
indexDb
);
long
s
=
jedis
.
del
(
key
);
if
(
null
!=
jedis
&&
null
!=
jedisPool
)
{
returnResource
(
jedisPool
,
jedis
);
}
return
s
;
}
/**
* 通过key获取储存在redis中的value
* 通过key获取储存在redis中的value
* 并释放连接
* 并释放连接
*
*
...
...
src/com/ejweb/modules/user/api/UserController.java
View file @
6753e606
...
@@ -9,6 +9,8 @@ import com.ejweb.core.conf.GConstants;
...
@@ -9,6 +9,8 @@ import com.ejweb.core.conf.GConstants;
import
com.ejweb.core.fetcher.FetchEntity
;
import
com.ejweb.core.fetcher.FetchEntity
;
import
com.ejweb.core.fetcher.HCFetcher
;
import
com.ejweb.core.fetcher.HCFetcher
;
import
com.ejweb.core.util.IdWorker
;
import
com.ejweb.core.util.IdWorker
;
import
com.ejweb.core.util.PropertiesUtils
;
import
com.ejweb.core.util.RedisUtils
;
import
com.ejweb.core.util.Util
;
import
com.ejweb.core.util.Util
;
import
com.ejweb.modules.im.service.HuaweiInterfaseService
;
import
com.ejweb.modules.im.service.HuaweiInterfaseService
;
import
com.ejweb.modules.mobile.verify.entity.MobileVerifyEntity
;
import
com.ejweb.modules.mobile.verify.entity.MobileVerifyEntity
;
...
@@ -55,6 +57,11 @@ public class UserController {
...
@@ -55,6 +57,11 @@ public class UserController {
@Autowired
@Autowired
private
HuaweiInterfaseService
huaweiInterfaseService
;
private
HuaweiInterfaseService
huaweiInterfaseService
;
@Autowired
private
RedisUtils
redisUtils
;
/**
/**
* 根据用户CODE查询用户信息
* 根据用户CODE查询用户信息
*
*
...
@@ -126,19 +133,40 @@ public class UserController {
...
@@ -126,19 +133,40 @@ public class UserController {
*/
*/
@ResponseBody
@ResponseBody
@RequestMapping
(
"/login"
)
@RequestMapping
(
"/login"
)
public
ResponseBean
login
(
HttpServletRequest
request
,
RequestBean
requestBean
)
{
public
ResponseBean
login
(
HttpServletRequest
request
,
RequestBean
requestBean
,
String
userIp
)
{
//获取redis的库
int
indexDb
=
Integer
.
valueOf
(
PropertiesUtils
.
getProperties
().
get
(
"redis.dbIndex"
).
toString
());
//ip受限时间与次数
int
ipWithinSeconds
=
Integer
.
valueOf
(
PropertiesUtils
.
getProperties
().
get
(
"ipWithinSeconds"
).
toString
());
int
ipLimitTimes
=
Integer
.
valueOf
(
PropertiesUtils
.
getProperties
().
get
(
"ipLimitTimes"
).
toString
());
long
startTime
=
System
.
nanoTime
();
long
startTime
=
System
.
nanoTime
();
ResponseBean
responseBean
=
new
ResponseBean
();
ResponseBean
responseBean
=
new
ResponseBean
();
String
message
=
userService
.
validate
(
requestBean
);
String
message
=
userService
.
validate
(
requestBean
);
LoginBean
loginBean
=
requestBean
.
getObjectBean
(
LoginBean
.
class
);
LoginBean
loginBean
=
requestBean
.
getObjectBean
(
LoginBean
.
class
);
message
=
userService
.
validate
(
loginBean
);
message
=
userService
.
validate
(
loginBean
);
if
(
message
==
null
)
{
if
(
message
==
null
)
{
//todo 在查用户名数据库之前先查一下数据库 ip限制,如果有ip限制,则直接返回
if
(
true
){
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4102
);
responseBean
.
setMessage
(
"IP受限!"
);
}
LoginUserEntity
userEntity
=
userService
.
findUserByLoginName
(
loginBean
);
LoginUserEntity
userEntity
=
userService
.
findUserByLoginName
(
loginBean
);
if
(
userEntity
==
null
){
// 查询不到用户信息
// 查询不到用户信息
if
(
userEntity
==
null
){
if
(
redisUtils
.
get
(
userIp
,
indexDb
)
==
null
){
redisUtils
.
set
(
userIp
,
1
,
indexDb
);
}
else
{
redisUtils
.
incr
(
userIp
,
indexDb
);
if
(
Integer
.
valueOf
(
redisUtils
.
get
(
userIp
,
indexDb
))
>=
ipLimitTimes
){
//todo 存入数据库清除key
redisUtils
.
del
(
userIp
,
indexDb
);
}
}
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4102
);
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4102
);
responseBean
.
setMessage
(
"用户名不存在"
);
responseBean
.
setMessage
(
"用户名不存在"
);
long
endTime
=
System
.
nanoTime
();
long
endTime
=
System
.
nanoTime
();
long
duration
=
endTime
-
startTime
;
long
duration
=
endTime
-
startTime
;
LOG
.
debug
(
"[UserController login][STATUS_CODE_4102]总共用时:"
+
Util
.
getDurationTime
(
duration
));
LOG
.
debug
(
"[UserController login][STATUS_CODE_4102]总共用时:"
+
Util
.
getDurationTime
(
duration
));
...
...
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