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
cbf8478b
Commit
cbf8478b
authored
Sep 24, 2019
by
java-李谡
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev-zt' into develop
parents
b7881d9b
8b98afac
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
203 additions
and
14 deletions
+203
-14
UserDao.xml
resources/mapper/modules/user/UserDao.xml
+9
-0
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
+34
-0
UserController.java
src/com/ejweb/modules/user/api/UserController.java
+65
-12
LoginIpInfo.java
src/com/ejweb/modules/user/bean/LoginIpInfo.java
+42
-0
UserDao.java
src/com/ejweb/modules/user/dao/UserDao.java
+4
-0
UserService.java
src/com/ejweb/modules/user/service/UserService.java
+14
-0
No files found.
resources/mapper/modules/user/UserDao.xml
View file @
cbf8478b
...
@@ -904,4 +904,12 @@
...
@@ -904,4 +904,12 @@
</if>
</if>
ORDER BY r.login_date DESC
ORDER BY r.login_date DESC
</select>
</select>
<select
id=
"findByIp"
resultType=
"com.ejweb.modules.user.bean.LoginIpInfo"
>
select black_ip from sys_login_blacklist where black_ip = #{userIp}
</select>
<insert
id=
"insertInfoByIp"
parameterType=
"string"
>
insert into sys_login_blacklist(black_ip,create_time) values (#{userIp},DATE_FORMAT(now(),'%Y-%m-%d %k:%i:%s'))
</insert>
</mapper>
</mapper>
\ No newline at end of file
resources/redis.properties
View file @
cbf8478b
...
@@ -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 @
cbf8478b
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 @
cbf8478b
...
@@ -18,6 +18,40 @@ public class RedisUtils {
...
@@ -18,6 +18,40 @@ public class RedisUtils {
private
JedisPool
jedisPool
;
private
JedisPool
jedisPool
;
/**
/**
* 判断key是否存在
*
* @param key
* @param indexDb
* @return boolean
**/
public
boolean
exists
(
String
key
,
int
indexDb
)
{
Jedis
jedis
=
jedisPool
.
getResource
();
jedis
.
select
(
indexDb
);
boolean
exist
=
jedis
.
exists
(
key
);
if
(
null
!=
jedis
&&
null
!=
jedisPool
)
{
returnResource
(
jedisPool
,
jedis
);
}
return
exist
;
}
/**
* 删除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 @
cbf8478b
...
@@ -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,28 +133,41 @@ public class UserController {
...
@@ -126,28 +133,41 @@ 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
());
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
)
{
LoginIpInfo
loginIpInfo
=
userService
.
findByIp
(
userIp
);
if
(
loginIpInfo
!=
null
){
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4102
);
responseBean
.
setMessage
(
"IP受限!请联系管理员"
);
long
endTime
=
System
.
nanoTime
();
long
duration
=
endTime
-
startTime
;
LOG
.
debug
(
"[UserController login][STATUS_CODE_4102]总共用时:"
+
Util
.
getDurationTime
(
duration
));
return
responseBean
;
}
LoginUserEntity
userEntity
=
userService
.
findUserByLoginName
(
loginBean
);
LoginUserEntity
userEntity
=
userService
.
findUserByLoginName
(
loginBean
);
if
(
userEntity
==
null
){
// 查询不到用户信息
// 查询不到用户信息
if
(
userEntity
==
null
){
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4102
);
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4102
);
responseBean
.
setMessage
(
"用户名不存在"
);
responseBean
.
setMessage
(
"用户名不存在"
);
//判断ip限制
checkIpLimit
(
redisUtils
,
userIp
,
indexDb
,
responseBean
);
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
));
return
responseBean
;
return
responseBean
;
}
else
if
(
GConstants
.
NO
.
equals
(
userEntity
.
getLoginFlag
()))
{
// 用户被查封
}
else
if
(
GConstants
.
NO
.
equals
(
userEntity
.
getLoginFlag
()))
{
// 用户被查封
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4101
);
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4101
);
responseBean
.
setMessage
(
"该帐号已禁止登录"
);
responseBean
.
setMessage
(
"该帐号已禁止登录"
);
//判断ip限制
checkIpLimit
(
redisUtils
,
userIp
,
indexDb
,
responseBean
);
long
endTime
=
System
.
nanoTime
();
long
endTime
=
System
.
nanoTime
();
long
duration
=
endTime
-
startTime
;
long
duration
=
endTime
-
startTime
;
LOG
.
debug
(
"[UserController login][STATUS_CODE_4101]总共用时:"
+
Util
.
getDurationTime
(
duration
));
LOG
.
debug
(
"[UserController login][STATUS_CODE_4101]总共用时:"
+
Util
.
getDurationTime
(
duration
));
...
@@ -155,7 +175,8 @@ public class UserController {
...
@@ -155,7 +175,8 @@ public class UserController {
}
else
if
(!
"2"
.
equals
(
userEntity
.
getUserType
())
&&
!
"4"
.
equals
(
userEntity
.
getUserType
())
&&
!
"6"
.
equals
(
userEntity
.
getUserType
()))
{
//不是内部联系人 通讯录联系人不允许登陆
}
else
if
(!
"2"
.
equals
(
userEntity
.
getUserType
())
&&
!
"4"
.
equals
(
userEntity
.
getUserType
())
&&
!
"6"
.
equals
(
userEntity
.
getUserType
()))
{
//不是内部联系人 通讯录联系人不允许登陆
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4101
);
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4101
);
responseBean
.
setMessage
(
"当前用户类型不允许登陆,请联系系统管理员"
);
responseBean
.
setMessage
(
"当前用户类型不允许登陆,请联系系统管理员"
);
//判断ip限制
checkIpLimit
(
redisUtils
,
userIp
,
indexDb
,
responseBean
);
long
endTime
=
System
.
nanoTime
();
long
endTime
=
System
.
nanoTime
();
long
duration
=
endTime
-
startTime
;
long
duration
=
endTime
-
startTime
;
LOG
.
debug
(
"[UserController login][STATUS_CODE_4101]总共用时:"
+
Util
.
getDurationTime
(
duration
));
LOG
.
debug
(
"[UserController login][STATUS_CODE_4101]总共用时:"
+
Util
.
getDurationTime
(
duration
));
...
@@ -176,19 +197,23 @@ public class UserController {
...
@@ -176,19 +197,23 @@ public class UserController {
if
(
passwordError
){
if
(
passwordError
){
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4103
);
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4103
);
responseBean
.
setMessage
(
"用户名密码不匹配!"
);
responseBean
.
setMessage
(
"用户名密码不匹配!"
);
//判断ip限制
checkIpLimit
(
redisUtils
,
userIp
,
indexDb
,
responseBean
);
long
endTime
=
System
.
nanoTime
();
long
endTime
=
System
.
nanoTime
();
long
duration
=
endTime
-
startTime
;
long
duration
=
endTime
-
startTime
;
LOG
.
debug
(
"[UserController login][STATUS_CODE_4103]总共用时:"
+
Util
.
getDurationTime
(
duration
));
LOG
.
debug
(
"[UserController login][STATUS_CODE_4103]总共用时:"
+
Util
.
getDurationTime
(
duration
));
return
responseBean
;
return
responseBean
;
}
else
{
}
else
{
if
(
StringUtils
.
isNotBlank
(
loginBean
.
getVerifyCode
())){
// 校验码登录
// 校验码登录
if
(
StringUtils
.
isNotBlank
(
loginBean
.
getVerifyCode
())){
MobileVerifyEntity
entity
=
mobileVerifyService
.
getVerifyCode
(
loginBean
.
getLoginName
(),
loginBean
.
getVerifyCode
());
MobileVerifyEntity
entity
=
mobileVerifyService
.
getVerifyCode
(
loginBean
.
getLoginName
(),
loginBean
.
getVerifyCode
());
if
(
entity
==
null
){
// 校验码不存在
// 校验码不存在
if
(
entity
==
null
){
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4104
);
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4104
);
responseBean
.
setMessage
(
"校验码错误"
);
responseBean
.
setMessage
(
"校验码错误"
);
//判断ip限制
checkIpLimit
(
redisUtils
,
userIp
,
indexDb
,
responseBean
);
long
endTime
=
System
.
nanoTime
();
long
endTime
=
System
.
nanoTime
();
long
duration
=
endTime
-
startTime
;
long
duration
=
endTime
-
startTime
;
LOG
.
debug
(
"[UserController login][STATUS_CODE_4104]总共用时:"
+
Util
.
getDurationTime
(
duration
));
LOG
.
debug
(
"[UserController login][STATUS_CODE_4104]总共用时:"
+
Util
.
getDurationTime
(
duration
));
...
@@ -197,7 +222,8 @@ public class UserController {
...
@@ -197,7 +222,8 @@ public class UserController {
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4105
);
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4105
);
responseBean
.
setMessage
(
"校验码已失效"
);
responseBean
.
setMessage
(
"校验码已失效"
);
//判断ip限制
checkIpLimit
(
redisUtils
,
userIp
,
indexDb
,
responseBean
);
long
endTime
=
System
.
nanoTime
();
long
endTime
=
System
.
nanoTime
();
long
duration
=
endTime
-
startTime
;
long
duration
=
endTime
-
startTime
;
LOG
.
debug
(
"[UserController login][STATUS_CODE_4105]总共用时:"
+
Util
.
getDurationTime
(
duration
));
LOG
.
debug
(
"[UserController login][STATUS_CODE_4105]总共用时:"
+
Util
.
getDurationTime
(
duration
));
...
@@ -327,6 +353,8 @@ public class UserController {
...
@@ -327,6 +353,8 @@ public class UserController {
responseBean
.
setMessage
(
message
);
responseBean
.
setMessage
(
message
);
return
responseBean
;
return
responseBean
;
}
}
public
boolean
sendVerifyCode
(
String
telephone
,
String
verifyCode
)
{
public
boolean
sendVerifyCode
(
String
telephone
,
String
verifyCode
)
{
try
{
try
{
HCFetcher
fetcher
=
HCFetcher
.
getInstance
();
HCFetcher
fetcher
=
HCFetcher
.
getInstance
();
...
@@ -995,4 +1023,29 @@ public class UserController {
...
@@ -995,4 +1023,29 @@ public class UserController {
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4001
);
responseBean
.
setStatus
(
ErrorCode
.
STATUS_CODE_4001
);
return
responseBean
;
return
responseBean
;
}
}
private
void
checkIpLimit
(
RedisUtils
redisUtils
,
String
userIp
,
int
indexDb
,
ResponseBean
responseBean
)
{
//ip受限时间与次数
int
ipWithinSeconds
=
Integer
.
valueOf
(
PropertiesUtils
.
getProperties
().
get
(
"ipWithinSeconds"
).
toString
());
int
ipLimitTimes
=
Integer
.
valueOf
(
PropertiesUtils
.
getProperties
().
get
(
"ipLimitTimes"
).
toString
());
//如果redis没有key
if
(!
redisUtils
.
exists
(
userIp
,
indexDb
)){
redisUtils
.
set
(
userIp
,
1
,
indexDb
);
//设置过期时间
redisUtils
.
expire
(
userIp
,
ipWithinSeconds
,
indexDb
);
}
else
{
//如果存在key
redisUtils
.
incrNotResetExpireTime
(
userIp
,
indexDb
);
if
(
Integer
.
valueOf
(
redisUtils
.
get
(
userIp
,
indexDb
))
>=
ipLimitTimes
){
redisUtils
.
del
(
userIp
,
indexDb
);
userService
.
insertInfoByIp
(
userIp
);
responseBean
.
setMessage
(
"IP受限!请联系管理员"
);
}
}
}
}
}
src/com/ejweb/modules/user/bean/LoginIpInfo.java
0 → 100644
View file @
cbf8478b
package
com
.
ejweb
.
modules
.
user
.
bean
;
import
java.util.Date
;
/**
* 登录Ip信息
*
* @author zangtao
* @create 2019 - 09 -24 10:06
*/
public
class
LoginIpInfo
{
private
Integer
id
;
private
String
blackIp
;
private
Date
createTime
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
String
getBlackIp
()
{
return
blackIp
;
}
public
void
setBlackIp
(
String
blackIp
)
{
this
.
blackIp
=
blackIp
;
}
public
Date
getCreateTime
()
{
return
createTime
;
}
public
void
setCreateTime
(
Date
createTime
)
{
this
.
createTime
=
createTime
;
}
}
src/com/ejweb/modules/user/dao/UserDao.java
View file @
cbf8478b
...
@@ -101,4 +101,8 @@ public interface UserDao extends CurdDao<UserEntity> {
...
@@ -101,4 +101,8 @@ public interface UserDao extends CurdDao<UserEntity> {
public
void
updateOuterUser
(
OuterUserBean
bean
);
public
void
updateOuterUser
(
OuterUserBean
bean
);
List
<
UserLoginLogEntity
>
findUserLoginLogList
(
UserLoginLogEntity
userLoginLogEntity
);
List
<
UserLoginLogEntity
>
findUserLoginLogList
(
UserLoginLogEntity
userLoginLogEntity
);
LoginIpInfo
findByIp
(
@Param
(
"userIp"
)
String
userIp
);
void
insertInfoByIp
(
@Param
(
"userIp"
)
String
userIp
);
}
}
src/com/ejweb/modules/user/service/UserService.java
View file @
cbf8478b
...
@@ -658,4 +658,18 @@ public class UserService extends CurdService<UserDao, UserEntity> {
...
@@ -658,4 +658,18 @@ public class UserService extends CurdService<UserDao, UserEntity> {
public
List
<
UserLoginLogEntity
>
findUserLoginLogList
(
UserLoginLogEntity
userLoginLogEntity
)
{
public
List
<
UserLoginLogEntity
>
findUserLoginLogList
(
UserLoginLogEntity
userLoginLogEntity
)
{
return
dao
.
findUserLoginLogList
(
userLoginLogEntity
);
return
dao
.
findUserLoginLogList
(
userLoginLogEntity
);
}
}
/**
* 查找IP
*
* @param userIp
* @return
*/
public
LoginIpInfo
findByIp
(
String
userIp
)
{
return
dao
.
findByIp
(
userIp
);
}
public
void
insertInfoByIp
(
String
userIp
)
{
dao
.
insertInfoByIp
(
userIp
);
}
}
}
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