黑马头条1
登录逻辑
@Override
public ResponseResult login(LoginDto loginDto) {
//nomal login need phone and password
if (!StringUtils.isAnyBlank(loginDto.getPhone(), loginDto.getPassword())) {
ApUser apUser = this.lambdaQuery()
.eq(ApUser::getPhone, loginDto.getPhone())
.one();
if (apUser == null) {
return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST, "用户不存在");
}
String salt = apUser.getSalt();
String password = loginDto.getPassword();
String encryptPassword = DigestUtils.md5DigestAsHex((password + salt).getBytes());
if (!encryptPassword.equals(apUser.getPassword())) {
return ResponseResult.errorResult(AppHttpCodeEnum.LOGIN_PASSWORD_ERROR);
}
//正确,返回jwt信息
HashMap<String, Object> map = new HashMap<>();
String token = AppJwtUtil.getToken(apUser.getId().longValue());
map.put("token", token);
apUser.setPassword("");
apUser.setSalt("");
map.put("user", apUser);
return ResponseResult.okResult(map);
}
HashMap<String, Object> map = new HashMap<>();
String token = AppJwtUtil.getToken(0L);
map.put("token", token);
return ResponseResult.okResult(map);
}
大约 5 分钟