use of com.peng.config.exception.CaptchaExpireException in project blogSpringBoot by lurenha.
the class LoginController method login.
@RequestMapping(value = "/login", method = RequestMethod.POST)
public JsonResult login(@RequestParam("username") String username, @RequestParam("password") String password, @RequestParam("code") String code, @RequestParam("uuid") String uuid) {
String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
String captcha = (String) redisUtil.get(verifyKey);
redisUtil.del(verifyKey);
if (captcha == null) {
throw new CaptchaExpireException("验证码不存在");
}
if (!code.equalsIgnoreCase(captcha)) {
throw new CaptchaExpireException("验证码不匹配");
}
Map<String, Object> map = new HashMap<>();
User user = userService.verifyLogin(username, password);
if (user != null) {
String token = TokenUtil.sign(user);
map.put("token", token);
return ResultUtil.success(map, ResultCode.SUCCESS);
} else {
return ResultUtil.faile(ResultCode.USER_LOGIN_ERROR);
}
}
Aggregations