Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
education
Project
Project
Details
Activity
Releases
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
李丛阳
education
Commits
8210a1c5
Commit
8210a1c5
authored
Dec 19, 2017
by
YangZhaoJun1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改登录方法返回值
parent
27065684
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
6 deletions
+40
-6
AuthenticationController.java
...org/rcisoft/core/controller/AuthenticationController.java
+8
-3
UserAuthDTO.java
src/main/java/org/rcisoft/core/controller/UserAuthDTO.java
+15
-0
AuthenticationService.java
.../java/org/rcisoft/core/service/AuthenticationService.java
+2
-1
AuthenticationServiceImpl.java
.../rcisoft/core/service/impl/AuthenticationServiceImpl.java
+14
-2
UserMapper.xml
src/main/resources/mapper/sys/user/mapper/UserMapper.xml
+1
-0
No files found.
src/main/java/org/rcisoft/core/controller/AuthenticationController.java
View file @
8210a1c5
package
org
.
rcisoft
.
core
.
controller
;
import
org.rcisoft.core.constant.MessageConstant
;
import
org.rcisoft.core.model.PersistModel
;
import
org.rcisoft.core.result.Result
;
import
org.rcisoft.core.service.AuthenticationService
;
import
org.rcisoft.core.util.ResultGenerator
;
...
...
@@ -34,9 +36,12 @@ public class AuthenticationController {
public
Result
login
(
@RequestParam
(
"username"
)
String
username
,
@RequestParam
(
"password"
)
String
password
,
@RequestParam
(
"userType"
)
String
userType
){
final
String
token
=
authenticationServiceImpl
.
login
(
username
,
password
,
userType
);
Result
result
=
ResultGenerator
.
genSuccessResult
(
token
);
return
result
;
final
UserAuthDTO
userAuthDTO
=
authenticationServiceImpl
.
login
(
username
,
password
,
userType
);
//Result result = ResultGenerator.genSuccessResult(token);
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
userAuthDTO
);
}
/**
...
...
src/main/java/org/rcisoft/core/controller/UserAuthDTO.java
0 → 100644
View file @
8210a1c5
package
org
.
rcisoft
.
core
.
controller
;
import
lombok.Data
;
/**
* Created by gaowenfeng on 2017/8/4.
*/
@Data
public
class
UserAuthDTO
{
private
String
userId
;
private
String
name
;
private
String
headPic
;
private
String
roleCode
;
private
String
token
;
}
src/main/java/org/rcisoft/core/service/AuthenticationService.java
View file @
8210a1c5
package
org
.
rcisoft
.
core
.
service
;
import
org.rcisoft.core.controller.UserAuthDTO
;
import
org.rcisoft.sys.user.entity.SysUser
;
/**
...
...
@@ -19,7 +20,7 @@ public interface AuthenticationService {
* @param password
* @return
*/
String
login
(
String
username
,
String
password
,
String
userType
);
UserAuthDTO
login
(
String
username
,
String
password
,
String
userType
);
/**
* 刷新
...
...
src/main/java/org/rcisoft/core/service/impl/AuthenticationServiceImpl.java
View file @
8210a1c5
package
org
.
rcisoft
.
core
.
service
.
impl
;
import
org.rcisoft.common.component.Global
;
import
org.rcisoft.core.controller.UserAuthDTO
;
import
org.rcisoft.core.exception.ServiceException
;
import
org.rcisoft.core.result.ResultExceptionEnum
;
import
org.rcisoft.core.result.ResultServiceEnums
;
...
...
@@ -67,12 +68,17 @@ public class AuthenticationServiceImpl implements AuthenticationService {
}
@Override
public
String
login
(
String
username
,
String
password
,
String
userType
)
{
public
UserAuthDTO
login
(
String
username
,
String
password
,
String
userType
)
{
UsernamePasswordAuthenticationToken
upToken
=
new
UsernamePasswordAuthenticationToken
(
username
,
password
);
/*进入到 UserDetailsService(JwtUserDetailServiceImpl) loadUserByUsername 方法*/
UserAuthDTO
userAuthDTO
=
new
UserAuthDTO
();
final
Authentication
authentication
=
authenticationManager
.
authenticate
(
upToken
);
final
UserDetails
userDetails
=
userDetailsService
.
loadUserByUsername
(
username
);
List
<
SysUser
>
sysUserList
=
sysUserMapper
.
queryUserByName
(
username
);
SysUser
sysUser
=
sysUserList
.
get
(
0
);
List
<
SysRole
>
role
=
sysRoleRepository
.
queryCodeByUsername
(
username
);
if
(
role
.
size
()!=
0
){
if
(
userType
.
equals
(
"1"
)&&!
global
.
getAdminCode
().
equals
(
role
.
get
(
0
).
getCode
())){
//1代表请求后台,只有管理员能够访问
...
...
@@ -85,7 +91,13 @@ public class AuthenticationServiceImpl implements AuthenticationService {
}
final
String
token
=
JwtUtil
.
generateToken
(
userDetails
);
SecurityContextHolder
.
getContext
().
setAuthentication
(
authentication
);
return
token
;
userAuthDTO
.
setUserId
(
sysUser
.
getBusinessId
());
userAuthDTO
.
setName
(
sysUser
.
getName
());
userAuthDTO
.
setHeadPic
(
sysUser
.
getHeadPic
());
userAuthDTO
.
setRoleCode
(
role
.
get
(
0
).
getCode
());
userAuthDTO
.
setToken
(
token
);
return
userAuthDTO
;
}
@Override
...
...
src/main/resources/mapper/sys/user/mapper/UserMapper.xml
View file @
8210a1c5
...
...
@@ -6,6 +6,7 @@
<result
column=
"login_name"
jdbcType=
"VARCHAR"
property=
"loginName"
/>
<result
column=
"name"
jdbcType=
"VARCHAR"
property=
"name"
/>
<result
column=
"password"
jdbcType=
"VARCHAR"
property=
"password"
/>
<result
column=
"head_pic"
jdbcType=
"VARCHAR"
property=
"headPic"
/>
<!--<result column="email" jdbcType="VARCHAR" property="email" />
<result column="phone" jdbcType="VARCHAR" property="phone" />-->
<!--dataEntity-->
...
...
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