Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
chnmuseum-party
Project
Project
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
liqin
chnmuseum-party
Commits
3759748e
Commit
3759748e
authored
Apr 07, 2021
by
liqin
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixed
parent
38993a44
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
37 deletions
+53
-37
ShiroConfig.java
...n/java/cn/wisenergy/chnmuseum/party/conf/ShiroConfig.java
+1
-0
LoginController.java
...nergy/chnmuseum/party/web/controller/LoginController.java
+52
-37
No files found.
src/main/java/cn/wisenergy/chnmuseum/party/conf/ShiroConfig.java
View file @
3759748e
...
...
@@ -89,6 +89,7 @@ public class ShiroConfig {
filterChainDefinitionMap
.
put
(
"/verifyCode"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/ajaxLogin1"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/verifyCode1"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/loginByQrCode"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/404"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/500"
,
"anon"
);
...
...
src/main/java/cn/wisenergy/chnmuseum/party/web/controller/LoginController.java
View file @
3759748e
package
cn
.
wisenergy
.
chnmuseum
.
party
.
web
.
controller
;
import
cn.hutool.extra.qrcode.QrCodeUtil
;
import
cn.hutool.extra.qrcode.QrConfig
;
import
cn.wisenergy.chnmuseum.party.auth.SHA256PasswordEncryptionService
;
import
cn.wisenergy.chnmuseum.party.auth.util.JwtTokenUtil
;
import
cn.wisenergy.chnmuseum.party.common.checkcode.SpecCaptcha
;
import
cn.wisenergy.chnmuseum.party.common.enums.AuditOperationEnum
;
import
cn.wisenergy.chnmuseum.party.common.enums.AuditStatusEnum
;
import
cn.wisenergy.chnmuseum.party.common.log.MethodLog
;
import
cn.wisenergy.chnmuseum.party.common.log.OperModule
;
import
cn.wisenergy.chnmuseum.party.common.log.OperType
;
import
cn.wisenergy.chnmuseum.party.model.Audit
;
import
cn.wisenergy.chnmuseum.party.model.Menu
;
import
cn.wisenergy.chnmuseum.party.model.Role
;
import
cn.wisenergy.chnmuseum.party.model.TUser
;
import
cn.wisenergy.chnmuseum.party.model.Menu
;
import
cn.wisenergy.chnmuseum.party.service.RoleService
;
import
cn.wisenergy.chnmuseum.party.service.impl.TUserServiceImpl
;
import
cn.wisenergy.chnmuseum.party.service.impl.MenuServiceImpl
;
import
cn.wisenergy.chnmuseum.party.service.impl.TUserServiceImpl
;
import
cn.wisenergy.chnmuseum.party.web.controller.base.BaseController
;
import
com.alibaba.fastjson.JSONObject
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.shiro.SecurityUtils
;
import
org.apache.shiro.authc.DisabledAccountException
;
import
org.apache.shiro.authc.IncorrectCredentialsException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.data.redis.core.ValueOperations
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
...
...
@@ -36,6 +32,7 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
java.time.LocalDate
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -127,34 +124,34 @@ public class LoginController extends BaseController {
if
(
StringUtils
.
isNoneBlank
(
username
))
{
try
{
//访问一次,计数一次
ValueOperations
<
String
,
String
>
opsForValue
=
stringRedisTemplate
.
opsForValue
();
if
(
"LOCK"
.
equals
(
opsForValue
.
get
(
SHIRO_IS_LOCK
+
username
)))
{
resultMap
.
put
(
"resultCode"
,
"500"
);
resultMap
.
put
(
"message"
,
"由于密码输入错误次数大于5次,12小时内帐号已禁止登录!请您联系相关管理人员。"
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
resultMap
);
}
user
=
userService
.
selectByUsername
(
username
);
if
(
user
==
null
)
{
resultMap
.
put
(
"resultCode"
,
"500"
);
resultMap
.
put
(
"message"
,
"用户名不正确!"
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
resultMap
);
}
//访问一次,计数一次
ValueOperations
<
String
,
String
>
opsForValue
=
stringRedisTemplate
.
opsForValue
();
if
(
"LOCK"
.
equals
(
opsForValue
.
get
(
SHIRO_IS_LOCK
+
username
)))
{
resultMap
.
put
(
"resultCode"
,
"500"
);
resultMap
.
put
(
"message"
,
"由于密码输入错误次数大于5次,12小时内帐号已禁止登录!请您联系相关管理人员。"
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
resultMap
);
}
if
(
AuditOperationEnum
.
DISABLE
.
name
().
equals
(
user
.
getStatus
()))
{
resultMap
.
put
(
"resultCode"
,
"500"
);
resultMap
.
put
(
"message"
,
"此帐号已禁用,请联系管理员!"
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
resultMap
);
}
user
=
userService
.
selectByUsername
(
username
);
if
(
user
==
null
)
{
resultMap
.
put
(
"resultCode"
,
"500"
);
resultMap
.
put
(
"message"
,
"用户名不正确!"
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
resultMap
);
}
if
(
user
.
getPermanent
()!=
null
&&!
user
.
getPermanent
())
{
if
(
user
.
getEffectiveDate
().
isAfter
(
LocalDate
.
now
())||
user
.
getExiredDate
().
isBefore
(
LocalDate
.
now
()))
{
if
(
AuditOperationEnum
.
DISABLE
.
name
().
equals
(
user
.
getStatus
()))
{
resultMap
.
put
(
"resultCode"
,
"500"
);
resultMap
.
put
(
"message"
,
"此帐号已
失效
,请联系管理员!"
);
resultMap
.
put
(
"message"
,
"此帐号已
禁用
,请联系管理员!"
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
resultMap
);
}
}
if
(
user
.
getPermanent
()
!=
null
&&
!
user
.
getPermanent
())
{
if
(
user
.
getEffectiveDate
().
isAfter
(
LocalDate
.
now
())
||
user
.
getExiredDate
().
isBefore
(
LocalDate
.
now
()))
{
resultMap
.
put
(
"resultCode"
,
"500"
);
resultMap
.
put
(
"message"
,
"此帐号已失效,请联系管理员!"
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
resultMap
);
}
}
byte
[]
salt
=
user
.
getPasswordSalt
();
String
s1
=
new
String
(
SHA256PasswordEncryptionService
.
createPasswordHash
(
password
,
salt
));
...
...
@@ -163,7 +160,7 @@ public class LoginController extends BaseController {
//计数大于5时,设置用户被锁定12小时
//测试设置5000次
int
i
=
5000
;
int
i
=
5000
;
String
s
=
opsForValue
.
get
(
SHIRO_LOGIN_COUNT
+
username
);
if
(
StringUtils
.
isNotBlank
(
s
))
{
if
(
Integer
.
parseInt
(
s
)
>=
i
)
{
...
...
@@ -172,14 +169,14 @@ public class LoginController extends BaseController {
}
}
resultMap
.
put
(
"resultCode"
,
"500"
);
resultMap
.
put
(
"message"
,
"密码不正确,您还有"
+(
i
-
Integer
.
valueOf
(
s
))+
"次机会!"
);
resultMap
.
put
(
"message"
,
"密码不正确,您还有"
+
(
i
-
Integer
.
valueOf
(
s
))
+
"次机会!"
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
resultMap
);
}
List
<
Role
>
roles
=
roleService
.
selectRoleByUserId
(
user
.
getId
());
List
<
String
>
list1
=
new
ArrayList
<>();
//获取当前用户角色拥有菜单
List
<
Menu
>
userMenuPerms
=
new
ArrayList
<>();
if
(
roles
!=
null
&&
roles
.
get
(
0
)!=
null
)
{
if
(
roles
!=
null
&&
roles
.
get
(
0
)
!=
null
)
{
roles
.
stream
().
forEach
(
r
->
list1
.
add
(
r
.
getId
()));
user
.
setRoleList
(
list1
);
userMenuPerms
=
this
.
menuService
.
getUserMenuPerms
(
list1
);
...
...
@@ -190,7 +187,7 @@ public class LoginController extends BaseController {
if
(
user
.
getOrgName
()
!=
null
)
{
operationContent
+=
",机构"
+
user
.
getOrgName
();
}
this
.
sysLogController
.
insertSysLog
(
operationContent
,
user
);
this
.
sysLogController
.
insertSysLog
(
operationContent
,
user
);
String
token
=
JwtTokenUtil
.
sign
(
username
,
user
.
getId
());
// 将token信息存入Redis
...
...
@@ -288,4 +285,22 @@ public class LoginController extends BaseController {
return
null
;
}
@ApiOperation
(
value
=
"H5/PAD登录二维码"
,
notes
=
"H5/PAD登录二维码"
,
httpMethod
=
"GET"
)
@GetMapping
(
value
=
"loginByQrCode"
)
public
ResponseEntity
<
byte
[]>
loginByQrCode
(
@RequestParam
(
value
=
"width"
,
required
=
false
,
defaultValue
=
"120"
)
int
width
,
@RequestParam
(
value
=
"height"
,
required
=
false
,
defaultValue
=
"120"
)
int
height
,
HttpServletRequest
request
)
{
String
regFullUrl
=
request
.
getScheme
()
+
"://"
+
request
.
getServerName
()
+
":"
+
request
.
getServerPort
()
+
"/h5"
;
QrConfig
config
=
new
QrConfig
(
width
,
height
);
config
.
setCharset
(
StandardCharsets
.
UTF_8
);
config
.
setMargin
(
0
);
config
.
setWidth
(
width
);
config
.
setHeight
(
height
);
final
byte
[]
bytes
=
QrCodeUtil
.
generatePng
(
regFullUrl
,
config
);
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
IMAGE_PNG
);
headers
.
setContentLength
(
bytes
.
length
);
return
new
ResponseEntity
<>(
bytes
,
headers
,
HttpStatus
.
OK
);
}
}
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