use of com.qiwenshare.file.domain.user.UserBean in project qiwen-file by qiwenshare.
the class UserController method checkUserLoginInfo.
@Operation(summary = "检查用户登录信息", description = "验证token的有效性", tags = { "user" })
@GetMapping("/checkuserlogininfo")
@ResponseBody
public RestResult<UserLoginVo> checkUserLoginInfo() {
UserLoginVo userLoginVo = new UserLoginVo();
JwtUser sessionUserBean = SessionUtil.getSession();
if (sessionUserBean != null && !"anonymousUser".equals(sessionUserBean.getUsername())) {
LambdaQueryWrapper<UserLoginInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(UserLoginInfo::getUserId, sessionUserBean.getUserId());
lambdaQueryWrapper.likeRight(UserLoginInfo::getUserloginDate, DateUtil.getCurrentTime().substring(0, 10));
userLoginInfoService.remove(lambdaQueryWrapper);
UserLoginInfo userLoginInfo = new UserLoginInfo();
userLoginInfo.setUserId(sessionUserBean.getUserId());
userLoginInfo.setUserloginDate(DateUtil.getCurrentTime());
userLoginInfoService.save(userLoginInfo);
UserBean user = userService.getById(sessionUserBean.getUserId());
BeanUtil.copyProperties(user, userLoginVo);
return RestResult.success().data(userLoginVo);
} else {
return RestResult.fail().message("用户暂未登录");
}
}
use of com.qiwenshare.file.domain.user.UserBean in project qiwen-file by qiwenshare.
the class UserService method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
UserBean user = userMapper.selectById(Long.valueOf(s));
if (user == null) {
throw new UsernameNotFoundException(String.format("用户不存在"));
}
List<Role> roleList = selectRoleListByUserId(user.getUserId());
List<SimpleGrantedAuthority> authorities = new ArrayList<>();
for (Role role : roleList) {
SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority("ROLE_" + role.getRoleName());
authorities.add(simpleGrantedAuthority);
}
JwtUser jwtUser = new JwtUser(user.getUserId(), user.getUsername(), user.getPassword(), user.getAvailable(), authorities);
return jwtUser;
}
use of com.qiwenshare.file.domain.user.UserBean in project qiwen-file by qiwenshare.
the class UserController method addUser.
@Operation(summary = "用户注册", description = "注册账号", tags = { "user" })
@PostMapping(value = "/register")
@MyLog(operation = "用户注册", module = CURRENT_MODULE)
@ResponseBody
public RestResult<String> addUser(@Valid @RequestBody RegisterDTO registerDTO) {
RestResult<String> restResult = null;
UserBean userBean = new UserBean();
BeanUtil.copyProperties(registerDTO, userBean);
restResult = userService.registerUser(userBean);
return restResult;
}
use of com.qiwenshare.file.domain.user.UserBean in project qiwen-file by qiwenshare.
the class UserController method userLogin.
@Operation(summary = "用户登录", description = "用户登录认证后才能进入系统", tags = { "user" })
@GetMapping("/login")
@MyLog(operation = "用户登录", module = CURRENT_MODULE)
@ResponseBody
public RestResult<UserLoginVo> userLogin(@Parameter(description = "登录手机号") String telephone, @Parameter(description = "登录密码") String password) {
RestResult<UserLoginVo> restResult = new RestResult<UserLoginVo>();
String salt = userService.getSaltByTelephone(telephone);
String hashPassword = new SimpleHash("MD5", password, salt, 1024).toHex();
UserBean result = userService.selectUserByTelephoneAndPassword(telephone, hashPassword);
if (result == null) {
return RestResult.fail().message("手机号或密码错误!");
}
Map<String, Object> param = new HashMap<>();
param.put("userId", result.getUserId());
String token = "";
try {
token = jwtComp.createJWT(JSON.toJSONString(param));
} catch (Exception e) {
log.info("登录失败:{}", e);
return RestResult.fail().message("创建token失败!");
}
UserBean sessionUserBean = userService.findUserInfoByTelephone(telephone);
if (sessionUserBean.getAvailable() != null && sessionUserBean.getAvailable() == 0) {
return RestResult.fail().message("用户已被禁用");
}
UserLoginVo userLoginVo = new UserLoginVo();
BeanUtil.copyProperties(sessionUserBean, userLoginVo);
userLoginVo.setToken("Bearer " + token);
restResult.setData(userLoginVo);
restResult.setSuccess(true);
restResult.setCode(200001);
return restResult;
}
use of com.qiwenshare.file.domain.user.UserBean in project qiwen-file by qiwenshare.
the class UserService method getUserIdByToken.
@Override
public Long getUserIdByToken(String token) {
Claims c = null;
if (StringUtils.isEmpty(token)) {
return null;
}
token = token.replace("Bearer ", "");
token = token.replace("Bearer%20", "");
try {
c = jwtComp.parseJWT(token);
} catch (Exception e) {
log.error("解码异常:" + e);
return null;
}
if (c == null) {
log.info("解码为空");
return null;
}
String subject = c.getSubject();
log.debug("解析结果:" + subject);
UserBean tokenUserBean = JSON.parseObject(subject, UserBean.class);
UserBean user = userMapper.selectById(tokenUserBean.getUserId());
if (user != null) {
return user.getUserId();
}
return null;
}
Aggregations