Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
customer-service
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
QG
customer-service
Commits
0674ecaf
Commit
0674ecaf
authored
Mar 06, 2020
by
xiaozhe.chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
尝试登陆功能
parent
31c7b6c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
12 deletions
+50
-12
AuthBean.java
...main/java/cn/quantgroup/customer/model/user/AuthBean.java
+39
-0
UserRest.java
src/main/java/cn/quantgroup/customer/rest/UserRest.java
+11
-12
No files found.
src/main/java/cn/quantgroup/customer/model/user/AuthBean.java
0 → 100644
View file @
0674ecaf
package
cn
.
quantgroup
.
customer
.
model
.
user
;
import
cn.quantgroup.customer.entity.User
;
public
class
AuthBean
{
private
String
token
;
private
User
user
;
public
AuthBean
(
String
token
,
User
user1
)
{
this
.
token
=
token
;
user
=
new
User
();
user
.
setName
(
user1
.
getName
());
user
.
setRole
(
user1
.
getRole
());
user
.
setUsername
(
user1
.
getUsername
());
user
.
setId
(
user1
.
getId
());
}
public
AuthBean
()
{
}
public
String
getToken
()
{
return
token
;
}
public
void
setToken
(
String
token
)
{
this
.
token
=
token
;
}
public
User
getUser
()
{
return
user
;
}
public
void
setUser
(
User
user
)
{
this
.
user
=
user
;
}
}
src/main/java/cn/quantgroup/customer/rest/UserRest.java
View file @
0674ecaf
package
cn
.
quantgroup
.
customer
.
rest
;
import
cn.quantgroup.customer.entity.User
;
import
cn.quantgroup.customer.enums.ErrorCodeEnum
;
import
cn.quantgroup.customer.model.user.AuthBean
;
import
cn.quantgroup.customer.rest.enums.phone.ModifyPhoneApplyStatus
;
import
cn.quantgroup.customer.rest.enums.phone.ModifyPhoneAuditStatus
;
import
cn.quantgroup.customer.rest.enums.phone.ModifyPhoneProcessingStatus
;
...
...
@@ -24,6 +26,7 @@ import org.springframework.web.bind.annotation.*;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpSession
;
import
javax.validation.Valid
;
import
java.security.Principal
;
import
java.time.LocalDate
;
import
static
cn
.
quantgroup
.
customer
.
constant
.
Constant
.*;
...
...
@@ -43,19 +46,15 @@ public class UserRest {
}
@PostMapping
(
value
=
"/login"
)
public
JsonResult
login
(
@Valid
@ModelAttribute
LoginParam
loginParam
,
HttpServletRequest
request
)
{
UsernamePasswordAuthenticationToken
authRequest
=
new
UsernamePasswordAuthenticationToken
(
loginParam
.
getUsername
(),
loginParam
.
getPassword
());
Authentication
authentication
=
authenticationManager
.
authenticate
(
authRequest
);
SecurityContextHolder
.
getContext
().
setAuthentication
(
authentication
);
HttpSession
session
=
request
.
getSession
();
session
.
setAttribute
(
SPRING_SECURITY_CONTEXT
,
SecurityContextHolder
.
getContext
());
if
(
authentication
!=
null
&&
authentication
.
isAuthenticated
())
{
AuthenticationUserDetail
principal
=
(
AuthenticationUserDetail
)
authentication
.
getPrincipal
();
AuthUserVo
authUserVo
=
AuthUserVo
.
parse
(
principal
);
return
JsonResult
.
buildSuccessResult
(
LOGIN_SUCCESS
,
authUserVo
);
public
JsonResult
login
(
Principal
principal
,
HttpServletRequest
request
)
{
if
(
principal
==
null
)
{
throw
new
RuntimeException
(
"账户名或密码不正确"
);
}
User
user
=
(
User
)
((
UsernamePasswordAuthenticationToken
)
principal
).
getPrincipal
();
if
(!
user
.
isEnable
())
{
throw
new
RuntimeException
(
"账号已被禁用"
);
}
return
JsonResult
.
buildErrorStateResult
(
LOGIN_FAIL
,
null
);
return
new
JsonResult
(
new
AuthBean
(
request
.
getSession
().
getId
(),
user
)
);
}
/**
...
...
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