Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
986b146c
Commit
986b146c
authored
Nov 30, 2019
by
dqjdda
Browse files
用户加入昵称与性别字段,个人中心优化,可修改基本资料
parent
4c90303e
Changes
17
Hide whitespace changes
Inline
Side-by-side
eladmin-system/src/main/java/me/zhengjie/modules/security/config/SecurityProperties.java
View file @
986b146c
...
@@ -24,12 +24,9 @@ public class SecurityProperties {
...
@@ -24,12 +24,9 @@ public class SecurityProperties {
/** 必须使用最少88位的Base64对该令牌进行编码 */
/** 必须使用最少88位的Base64对该令牌进行编码 */
private
String
base64Secret
;
private
String
base64Secret
;
/** 令牌过期时间 此处单位/秒 */
/** 令牌过期时间 此处单位/
毫
秒 */
private
Long
tokenValidityInSeconds
;
private
Long
tokenValidityInSeconds
;
/** 记住我模式下的令牌过期时间 此处单位/毫秒 */
private
Long
tokenValidityInSecondsForRememberMe
;
/** 在线用户 key,根据 key 查询 redis 中在线用户的数据 */
/** 在线用户 key,根据 key 查询 redis 中在线用户的数据 */
private
String
onlineKey
;
private
String
onlineKey
;
...
...
eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthController.java
View file @
986b146c
...
@@ -80,9 +80,8 @@ public class AuthController {
...
@@ -80,9 +80,8 @@ public class AuthController {
Authentication
authentication
=
authenticationManagerBuilder
.
getObject
().
authenticate
(
authenticationToken
);
Authentication
authentication
=
authenticationManagerBuilder
.
getObject
().
authenticate
(
authenticationToken
);
SecurityContextHolder
.
getContext
().
setAuthentication
(
authentication
);
SecurityContextHolder
.
getContext
().
setAuthentication
(
authentication
);
boolean
rememberMe
=
(
authUser
.
getRememberMe
()
==
null
)
?
false
:
authUser
.
getRememberMe
();
// 生成令牌
// 生成令牌
String
token
=
tokenProvider
.
createToken
(
authentication
,
rememberMe
);
String
token
=
tokenProvider
.
createToken
(
authentication
);
final
JwtUser
jwtUser
=
(
JwtUser
)
authentication
.
getPrincipal
();
final
JwtUser
jwtUser
=
(
JwtUser
)
authentication
.
getPrincipal
();
// 保存在线信息
// 保存在线信息
onlineUserService
.
save
(
jwtUser
,
token
,
request
);
onlineUserService
.
save
(
jwtUser
,
token
,
request
);
...
...
eladmin-system/src/main/java/me/zhengjie/modules/security/security/TokenProvider.java
View file @
986b146c
...
@@ -41,18 +41,13 @@ public class TokenProvider implements InitializingBean {
...
@@ -41,18 +41,13 @@ public class TokenProvider implements InitializingBean {
this
.
key
=
Keys
.
hmacShaKeyFor
(
keyBytes
);
this
.
key
=
Keys
.
hmacShaKeyFor
(
keyBytes
);
}
}
public
String
createToken
(
Authentication
authentication
,
boolean
rememberMe
)
{
public
String
createToken
(
Authentication
authentication
)
{
String
authorities
=
authentication
.
getAuthorities
().
stream
()
String
authorities
=
authentication
.
getAuthorities
().
stream
()
.
map
(
GrantedAuthority:
:
getAuthority
)
.
map
(
GrantedAuthority:
:
getAuthority
)
.
collect
(
Collectors
.
joining
(
","
));
.
collect
(
Collectors
.
joining
(
","
));
long
now
=
(
new
Date
()).
getTime
();
long
now
=
(
new
Date
()).
getTime
();
Date
validity
;
Date
validity
=
new
Date
(
now
+
properties
.
getTokenValidityInSeconds
());
if
(
rememberMe
)
{
validity
=
new
Date
(
now
+
properties
.
getTokenValidityInSecondsForRememberMe
());
}
else
{
validity
=
new
Date
(
now
+
properties
.
getTokenValidityInSeconds
());
}
return
Jwts
.
builder
()
return
Jwts
.
builder
()
.
setSubject
(
authentication
.
getName
())
.
setSubject
(
authentication
.
getName
())
...
...
eladmin-system/src/main/java/me/zhengjie/modules/security/security/vo/AuthUser.java
View file @
986b146c
...
@@ -19,8 +19,6 @@ public class AuthUser {
...
@@ -19,8 +19,6 @@ public class AuthUser {
@NotBlank
@NotBlank
private
String
password
;
private
String
password
;
private
Boolean
rememberMe
;
private
String
code
;
private
String
code
;
private
String
uuid
=
""
;
private
String
uuid
=
""
;
...
...
eladmin-system/src/main/java/me/zhengjie/modules/security/security/vo/JwtUser.java
View file @
986b146c
...
@@ -18,11 +18,14 @@ import java.util.stream.Collectors;
...
@@ -18,11 +18,14 @@ import java.util.stream.Collectors;
@AllArgsConstructor
@AllArgsConstructor
public
class
JwtUser
implements
UserDetails
{
public
class
JwtUser
implements
UserDetails
{
@JsonIgnore
private
final
Long
id
;
private
final
Long
id
;
private
final
String
username
;
private
final
String
username
;
private
final
String
nickName
;
private
final
String
sex
;
@JsonIgnore
@JsonIgnore
private
final
String
password
;
private
final
String
password
;
...
...
eladmin-system/src/main/java/me/zhengjie/modules/security/security/vo/OnlineUser.java
View file @
986b146c
...
@@ -16,6 +16,8 @@ public class OnlineUser {
...
@@ -16,6 +16,8 @@ public class OnlineUser {
private
String
userName
;
private
String
userName
;
private
String
nickName
;
private
String
job
;
private
String
job
;
private
String
browser
;
private
String
browser
;
...
...
eladmin-system/src/main/java/me/zhengjie/modules/security/service/OnlineUserService.java
View file @
986b146c
...
@@ -39,7 +39,7 @@ public class OnlineUserService {
...
@@ -39,7 +39,7 @@ public class OnlineUserService {
String
address
=
StringUtils
.
getCityInfo
(
ip
);
String
address
=
StringUtils
.
getCityInfo
(
ip
);
OnlineUser
onlineUser
=
null
;
OnlineUser
onlineUser
=
null
;
try
{
try
{
onlineUser
=
new
OnlineUser
(
jwtUser
.
getUsername
(),
job
,
browser
,
ip
,
address
,
EncryptUtils
.
desEncrypt
(
token
),
new
Date
());
onlineUser
=
new
OnlineUser
(
jwtUser
.
getUsername
(),
jwtUser
.
getNickName
(),
job
,
browser
,
ip
,
address
,
EncryptUtils
.
desEncrypt
(
token
),
new
Date
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
...
eladmin-system/src/main/java/me/zhengjie/modules/security/service/UserDetailsServiceImpl.java
View file @
986b146c
...
@@ -46,6 +46,8 @@ public class UserDetailsServiceImpl implements UserDetailsService {
...
@@ -46,6 +46,8 @@ public class UserDetailsServiceImpl implements UserDetailsService {
return
new
JwtUser
(
return
new
JwtUser
(
user
.
getId
(),
user
.
getId
(),
user
.
getUsername
(),
user
.
getUsername
(),
user
.
getNickName
(),
user
.
getSex
(),
user
.
getPassword
(),
user
.
getPassword
(),
user
.
getAvatar
(),
user
.
getAvatar
(),
user
.
getEmail
(),
user
.
getEmail
(),
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/domain/User.java
View file @
986b146c
...
@@ -32,6 +32,13 @@ public class User implements Serializable {
...
@@ -32,6 +32,13 @@ public class User implements Serializable {
@Column
(
unique
=
true
)
@Column
(
unique
=
true
)
private
String
username
;
private
String
username
;
/** 用户昵称 */
@NotBlank
private
String
nickName
;
/** 性别 */
private
String
sex
;
@OneToOne
@OneToOne
@JoinColumn
(
name
=
"avatar_id"
)
@JoinColumn
(
name
=
"avatar_id"
)
private
UserAvatar
userAvatar
;
private
UserAvatar
userAvatar
;
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/UserController.java
View file @
986b146c
...
@@ -119,6 +119,18 @@ public class UserController {
...
@@ -119,6 +119,18 @@ public class UserController {
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
}
}
@Log
(
"修改用户:个人中心"
)
@ApiOperation
(
"修改用户:个人中心"
)
@PutMapping
(
value
=
"center"
)
public
ResponseEntity
center
(
@Validated
(
User
.
Update
.
class
)
@RequestBody
User
resources
){
UserDto
userDto
=
userService
.
findByName
(
SecurityUtils
.
getUsername
());
if
(!
resources
.
getId
().
equals
(
userDto
.
getId
())){
throw
new
BadRequestException
(
"不能修改他人资料"
);
}
userService
.
updateCenter
(
resources
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
}
@Log
(
"删除用户"
)
@Log
(
"删除用户"
)
@ApiOperation
(
"删除用户"
)
@ApiOperation
(
"删除用户"
)
@DeleteMapping
(
value
=
"/{id}"
)
@DeleteMapping
(
value
=
"/{id}"
)
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/UserService.java
View file @
986b146c
...
@@ -90,4 +90,10 @@ public interface UserService {
...
@@ -90,4 +90,10 @@ public interface UserService {
* @throws IOException /
* @throws IOException /
*/
*/
void
download
(
List
<
UserDto
>
queryAll
,
HttpServletResponse
response
)
throws
IOException
;
void
download
(
List
<
UserDto
>
queryAll
,
HttpServletResponse
response
)
throws
IOException
;
/**
* 用户自助修改资料
* @param resources /
*/
void
updateCenter
(
User
resources
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserDto.java
View file @
986b146c
...
@@ -20,6 +20,10 @@ public class UserDto implements Serializable {
...
@@ -20,6 +20,10 @@ public class UserDto implements Serializable {
private
String
username
;
private
String
username
;
private
String
nickName
;
private
String
sex
;
private
String
avatar
;
private
String
avatar
;
private
String
email
;
private
String
email
;
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserQueryCriteria.java
View file @
986b146c
...
@@ -20,7 +20,7 @@ public class UserQueryCriteria implements Serializable {
...
@@ -20,7 +20,7 @@ public class UserQueryCriteria implements Serializable {
@Query
(
propName
=
"id"
,
type
=
Query
.
Type
.
IN
,
joinName
=
"dept"
)
@Query
(
propName
=
"id"
,
type
=
Query
.
Type
.
IN
,
joinName
=
"dept"
)
private
Set
<
Long
>
deptIds
;
private
Set
<
Long
>
deptIds
;
@Query
(
blurry
=
"email,username"
)
@Query
(
blurry
=
"email,username
,nickName
"
)
private
String
blurry
;
private
String
blurry
;
@Query
@Query
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
View file @
986b146c
...
@@ -127,6 +127,19 @@ public class UserServiceImpl implements UserService {
...
@@ -127,6 +127,19 @@ public class UserServiceImpl implements UserService {
user
.
setDept
(
resources
.
getDept
());
user
.
setDept
(
resources
.
getDept
());
user
.
setJob
(
resources
.
getJob
());
user
.
setJob
(
resources
.
getJob
());
user
.
setPhone
(
resources
.
getPhone
());
user
.
setPhone
(
resources
.
getPhone
());
user
.
setNickName
(
resources
.
getNickName
());
user
.
setSex
(
resources
.
getSex
());
userRepository
.
save
(
user
);
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateCenter
(
User
resources
)
{
User
user
=
userRepository
.
findById
(
resources
.
getId
()).
orElseGet
(
User:
:
new
);
user
.
setNickName
(
resources
.
getNickName
());
user
.
setPhone
(
resources
.
getPhone
());
user
.
setSex
(
resources
.
getSex
());
userRepository
.
save
(
user
);
userRepository
.
save
(
user
);
}
}
...
...
eladmin-system/src/main/resources/config/application-dev.yml
View file @
986b146c
...
@@ -44,14 +44,12 @@ spring:
...
@@ -44,14 +44,12 @@ spring:
#jwt
#jwt
jwt
:
jwt
:
header
:
Authorization
header
:
Authorization
# 令牌前缀
,主要最后留个空格
# 令牌前缀
token-start-with
:
Bearer
token-start-with
:
Bearer
# 必须使用最少88位的Base64对该令牌进行编码
# 必须使用最少88位的Base64对该令牌进行编码
base64-secret
:
ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
base64-secret
:
ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
# 令牌过期时间 此处单位/秒 ,默认4小时
# 令牌过期时间 此处单位/
毫
秒 ,默认4小时
,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
token-validity-in-seconds
:
14400000
token-validity-in-seconds
:
14400000
# 记住我模式下的令牌过期时间 此处单位/毫秒 ,默认1天
token-validity-in-seconds-for-remember-me
:
86400000
# 在线用户key
# 在线用户key
online-key
:
online-token
online-key
:
online-token
# 验证码
# 验证码
...
...
eladmin-system/src/main/resources/config/application-prod.yml
View file @
986b146c
...
@@ -46,14 +46,12 @@ spring:
...
@@ -46,14 +46,12 @@ spring:
#jwt
#jwt
jwt
:
jwt
:
header
:
Authorization
header
:
Authorization
# 令牌前缀
,主要最后留个空格
# 令牌前缀
token-start-with
:
Bearer
token-start-with
:
Bearer
# 必须使用最少88位的Base64对该令牌进行编码
# 必须使用最少88位的Base64对该令牌进行编码
base64-secret
:
ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
base64-secret
:
ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
# 令牌过期时间 此处单位/秒 ,默认4小时
# 令牌过期时间 此处单位/毫秒 ,默认2小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
token-validity-in-seconds
:
14400000
token-validity-in-seconds
:
7200000
# 记住我模式下的令牌过期时间 此处单位/毫秒 ,默认1天
token-validity-in-seconds-for-remember-me
:
86400000
# 在线用户key
# 在线用户key
online-key
:
online-token
online-key
:
online-token
# 验证码
# 验证码
...
...
sql/eladmin.sql
View file @
986b146c
...
@@ -257,7 +257,6 @@ INSERT INTO `menu` VALUES (3, b'0', '角色管理', 'system/role/index', 1, 3, '
...
@@ -257,7 +257,6 @@ INSERT INTO `menu` VALUES (3, b'0', '角色管理', 'system/role/index', 1, 3, '
INSERT
INTO
`menu`
VALUES
(
5
,
b
'0'
,
'菜单管理'
,
'system/menu/index'
,
1
,
5
,
'menu'
,
'menu'
,
b
'0'
,
b
'0'
,
'Menu'
,
'2018-12-18 15:17:28'
,
'menu:list'
,
1
);
INSERT
INTO
`menu`
VALUES
(
5
,
b
'0'
,
'菜单管理'
,
'system/menu/index'
,
1
,
5
,
'menu'
,
'menu'
,
b
'0'
,
b
'0'
,
'Menu'
,
'2018-12-18 15:17:28'
,
'menu:list'
,
1
);
INSERT
INTO
`menu`
VALUES
(
6
,
b
'0'
,
'系统监控'
,
NULL
,
0
,
10
,
'monitor'
,
'monitor'
,
b
'0'
,
b
'0'
,
NULL
,
'2018-12-18 15:17:48'
,
NULL
,
0
);
INSERT
INTO
`menu`
VALUES
(
6
,
b
'0'
,
'系统监控'
,
NULL
,
0
,
10
,
'monitor'
,
'monitor'
,
b
'0'
,
b
'0'
,
NULL
,
'2018-12-18 15:17:48'
,
NULL
,
0
);
INSERT
INTO
`menu`
VALUES
(
7
,
b
'0'
,
'操作日志'
,
'monitor/log/index'
,
6
,
11
,
'log'
,
'logs'
,
b
'0'
,
b
'0'
,
'Log'
,
'2018-12-18 15:18:26'
,
NULL
,
1
);
INSERT
INTO
`menu`
VALUES
(
7
,
b
'0'
,
'操作日志'
,
'monitor/log/index'
,
6
,
11
,
'log'
,
'logs'
,
b
'0'
,
b
'0'
,
'Log'
,
'2018-12-18 15:18:26'
,
NULL
,
1
);
INSERT
INTO
`menu`
VALUES
(
8
,
b
'0'
,
'系统缓存'
,
'monitor/redis/index'
,
6
,
15
,
'redis'
,
'redis'
,
b
'0'
,
b
'0'
,
'Redis'
,
'2018-12-18 15:19:01'
,
'redis:list'
,
1
);
INSERT
INTO
`menu`
VALUES
(
9
,
b
'0'
,
'SQL监控'
,
'monitor/sql/index'
,
6
,
18
,
'sqlMonitor'
,
'druid'
,
b
'0'
,
b
'0'
,
'Sql'
,
'2018-12-18 15:19:34'
,
NULL
,
1
);
INSERT
INTO
`menu`
VALUES
(
9
,
b
'0'
,
'SQL监控'
,
'monitor/sql/index'
,
6
,
18
,
'sqlMonitor'
,
'druid'
,
b
'0'
,
b
'0'
,
'Sql'
,
'2018-12-18 15:19:34'
,
NULL
,
1
);
INSERT
INTO
`menu`
VALUES
(
10
,
b
'0'
,
'组件管理'
,
NULL
,
0
,
50
,
'zujian'
,
'components'
,
b
'0'
,
b
'0'
,
NULL
,
'2018-12-19 13:38:16'
,
NULL
,
0
);
INSERT
INTO
`menu`
VALUES
(
10
,
b
'0'
,
'组件管理'
,
NULL
,
0
,
50
,
'zujian'
,
'components'
,
b
'0'
,
b
'0'
,
NULL
,
'2018-12-19 13:38:16'
,
NULL
,
0
);
INSERT
INTO
`menu`
VALUES
(
11
,
b
'0'
,
'图标库'
,
'components/icons/index'
,
10
,
51
,
'icon'
,
'icon'
,
b
'0'
,
b
'0'
,
'Icons'
,
'2018-12-19 13:38:49'
,
NULL
,
1
);
INSERT
INTO
`menu`
VALUES
(
11
,
b
'0'
,
'图标库'
,
'components/icons/index'
,
10
,
51
,
'icon'
,
'icon'
,
b
'0'
,
b
'0'
,
'Icons'
,
'2018-12-19 13:38:49'
,
NULL
,
1
);
...
@@ -603,7 +602,6 @@ INSERT INTO `roles_menus` VALUES (3, 1);
...
@@ -603,7 +602,6 @@ INSERT INTO `roles_menus` VALUES (3, 1);
INSERT
INTO
`roles_menus`
VALUES
(
5
,
1
);
INSERT
INTO
`roles_menus`
VALUES
(
5
,
1
);
INSERT
INTO
`roles_menus`
VALUES
(
6
,
1
);
INSERT
INTO
`roles_menus`
VALUES
(
6
,
1
);
INSERT
INTO
`roles_menus`
VALUES
(
7
,
1
);
INSERT
INTO
`roles_menus`
VALUES
(
7
,
1
);
INSERT
INTO
`roles_menus`
VALUES
(
8
,
1
);
INSERT
INTO
`roles_menus`
VALUES
(
9
,
1
);
INSERT
INTO
`roles_menus`
VALUES
(
9
,
1
);
INSERT
INTO
`roles_menus`
VALUES
(
10
,
1
);
INSERT
INTO
`roles_menus`
VALUES
(
10
,
1
);
INSERT
INTO
`roles_menus`
VALUES
(
11
,
1
);
INSERT
INTO
`roles_menus`
VALUES
(
11
,
1
);
...
@@ -670,7 +668,6 @@ INSERT INTO `roles_menus` VALUES (2, 2);
...
@@ -670,7 +668,6 @@ INSERT INTO `roles_menus` VALUES (2, 2);
INSERT
INTO
`roles_menus`
VALUES
(
3
,
2
);
INSERT
INTO
`roles_menus`
VALUES
(
3
,
2
);
INSERT
INTO
`roles_menus`
VALUES
(
5
,
2
);
INSERT
INTO
`roles_menus`
VALUES
(
5
,
2
);
INSERT
INTO
`roles_menus`
VALUES
(
6
,
2
);
INSERT
INTO
`roles_menus`
VALUES
(
6
,
2
);
INSERT
INTO
`roles_menus`
VALUES
(
8
,
2
);
INSERT
INTO
`roles_menus`
VALUES
(
9
,
2
);
INSERT
INTO
`roles_menus`
VALUES
(
9
,
2
);
INSERT
INTO
`roles_menus`
VALUES
(
10
,
2
);
INSERT
INTO
`roles_menus`
VALUES
(
10
,
2
);
INSERT
INTO
`roles_menus`
VALUES
(
11
,
2
);
INSERT
INTO
`roles_menus`
VALUES
(
11
,
2
);
...
...
Write
Preview
Supports
Markdown
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