用户加入昵称与性别字段,个人中心优化,可修改基本资料

pull/214/head
dqjdda 2019-11-30 21:56:23 +08:00
parent 4c90303e89
commit 986b146c88
17 changed files with 61 additions and 30 deletions

View File

@ -24,12 +24,9 @@ public class SecurityProperties {
/** 必须使用最少88位的Base64对该令牌进行编码 */
private String base64Secret;
/** 令牌过期时间 此处单位/秒 */
/** 令牌过期时间 此处单位/秒 */
private Long tokenValidityInSeconds;
/** 记住我模式下的令牌过期时间 此处单位/毫秒 */
private Long tokenValidityInSecondsForRememberMe;
/** 在线用户 key根据 key 查询 redis 中在线用户的数据 */
private String onlineKey;

View File

@ -80,9 +80,8 @@ public class AuthController {
Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken);
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();
// 保存在线信息
onlineUserService.save(jwtUser, token, request);

View File

@ -41,18 +41,13 @@ public class TokenProvider implements InitializingBean {
this.key = Keys.hmacShaKeyFor(keyBytes);
}
public String createToken(Authentication authentication, boolean rememberMe) {
public String createToken(Authentication authentication) {
String authorities = authentication.getAuthorities().stream()
.map(GrantedAuthority::getAuthority)
.collect(Collectors.joining(","));
long now = (new Date()).getTime();
Date validity;
if (rememberMe) {
validity = new Date(now + properties.getTokenValidityInSecondsForRememberMe());
} else {
validity = new Date(now + properties.getTokenValidityInSeconds());
}
Date validity = new Date(now + properties.getTokenValidityInSeconds());
return Jwts.builder()
.setSubject(authentication.getName())

View File

@ -19,8 +19,6 @@ public class AuthUser {
@NotBlank
private String password;
private Boolean rememberMe;
private String code;
private String uuid = "";

View File

@ -18,11 +18,14 @@ import java.util.stream.Collectors;
@AllArgsConstructor
public class JwtUser implements UserDetails {
@JsonIgnore
private final Long id;
private final String username;
private final String nickName;
private final String sex;
@JsonIgnore
private final String password;

View File

@ -16,6 +16,8 @@ public class OnlineUser {
private String userName;
private String nickName;
private String job;
private String browser;

View File

@ -39,7 +39,7 @@ public class OnlineUserService {
String address = StringUtils.getCityInfo(ip);
OnlineUser onlineUser = null;
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) {
e.printStackTrace();
}

View File

@ -46,6 +46,8 @@ public class UserDetailsServiceImpl implements UserDetailsService {
return new JwtUser(
user.getId(),
user.getUsername(),
user.getNickName(),
user.getSex(),
user.getPassword(),
user.getAvatar(),
user.getEmail(),

View File

@ -32,6 +32,13 @@ public class User implements Serializable {
@Column(unique = true)
private String username;
/** 用户昵称 */
@NotBlank
private String nickName;
/** 性别 */
private String sex;
@OneToOne
@JoinColumn(name = "avatar_id")
private UserAvatar userAvatar;

View File

@ -119,6 +119,18 @@ public class UserController {
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("删除用户")
@ApiOperation("删除用户")
@DeleteMapping(value = "/{id}")

View File

@ -90,4 +90,10 @@ public interface UserService {
* @throws IOException /
*/
void download(List<UserDto> queryAll, HttpServletResponse response) throws IOException;
/**
*
* @param resources /
*/
void updateCenter(User resources);
}

View File

@ -20,6 +20,10 @@ public class UserDto implements Serializable {
private String username;
private String nickName;
private String sex;
private String avatar;
private String email;

View File

@ -20,7 +20,7 @@ public class UserQueryCriteria implements Serializable {
@Query(propName = "id", type = Query.Type.IN, joinName = "dept")
private Set<Long> deptIds;
@Query(blurry = "email,username")
@Query(blurry = "email,username,nickName")
private String blurry;
@Query

View File

@ -127,6 +127,19 @@ public class UserServiceImpl implements UserService {
user.setDept(resources.getDept());
user.setJob(resources.getJob());
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);
}

View File

@ -44,14 +44,12 @@ spring:
#jwt
jwt:
header: Authorization
# 令牌前缀,主要最后留个空格
# 令牌前缀
token-start-with: Bearer
# 必须使用最少88位的Base64对该令牌进行编码
base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
# 令牌过期时间 此处单位/默认4小时
# 令牌过期时间 此处单位/默认4小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
token-validity-in-seconds: 14400000
# 记住我模式下的令牌过期时间 此处单位/毫秒 默认1天
token-validity-in-seconds-for-remember-me: 86400000
# 在线用户key
online-key: online-token
# 验证码

View File

@ -46,14 +46,12 @@ spring:
#jwt
jwt:
header: Authorization
# 令牌前缀,主要最后留个空格
# 令牌前缀
token-start-with: Bearer
# 必须使用最少88位的Base64对该令牌进行编码
base64-secret: ZmQ0ZGI5NjQ0MDQwY2I4MjMxY2Y3ZmI3MjdhN2ZmMjNhODViOTg1ZGE0NTBjMGM4NDA5NzYxMjdjOWMwYWRmZTBlZjlhNGY3ZTg4Y2U3YTE1ODVkZDU5Y2Y3OGYwZWE1NzUzNWQ2YjFjZDc0NGMxZWU2MmQ3MjY1NzJmNTE0MzI=
# 令牌过期时间 此处单位/秒 默认4小时
token-validity-in-seconds: 14400000
# 记住我模式下的令牌过期时间 此处单位/毫秒 默认1天
token-validity-in-seconds-for-remember-me: 86400000
# 令牌过期时间 此处单位/毫秒 默认2小时可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
token-validity-in-seconds: 7200000
# 在线用户key
online-key: online-token
# 验证码

View File

@ -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 (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 (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 (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);
@ -603,7 +602,6 @@ INSERT INTO `roles_menus` VALUES (3, 1);
INSERT INTO `roles_menus` VALUES (5, 1);
INSERT INTO `roles_menus` VALUES (6, 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 (10, 1);
INSERT INTO `roles_menus` VALUES (11, 1);
@ -670,7 +668,6 @@ INSERT INTO `roles_menus` VALUES (2, 2);
INSERT INTO `roles_menus` VALUES (3, 2);
INSERT INTO `roles_menus` VALUES (5, 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 (10, 2);
INSERT INTO `roles_menus` VALUES (11, 2);