use of com.jxys.base.exception.ErrorServiceException in project springboot-scaffold by a241978181.
the class UserServiceImpl method signIn.
@Override
public SignInView signIn(SignInData data) {
// 找到对应name的用户
User user = userMapper.selectOne(new QueryWrapper<User>().select("*").eq("name", data.getName()));
// 判断用户是否存在
if (user != null) {
// 校验密码
if (data.getPassword().equals(EncryptConfigUtil.decyptPwd(this.encryptorPassword, user.getPassword()))) {
// 校验通过,登陆成功,返回Token
SignInView signInView = new SignInView();
// 生成AccessToken
signInView.setAccessToken(tokenService.generate(TokenSubject.ACCESS, user.getId()));
// 生成RrefreshToken,有效期为24小时
signInView.setRefreshToken(tokenService.generate(TokenSubject.REFRESH, user.getId(), 24));
// 将对象序列化为JOSN格式储存在Redis中
try {
this.redisTemplate.opsForValue().set(user.getId(), user, Constant.REDIS_OVERDUE_TIME_MINUTES, TimeUnit.MINUTES);
} catch (Exception e) {
logger.error("向redis中存入数据失败!", e);
throw new ErrorServiceException();
} finally {
// 释放连接
RedisConnectionUtils.unbindConnection(redisTemplate.getConnectionFactory());
}
// 登录对象信息
signInView.setUser(user);
return signInView;
} else {
// 自定义异常示范
throw new PasswordErrorException();
}
} else {
// 抛出用户不存在的服务异常
throw new UserNotFoundException();
}
}
Aggregations