Search in sources :

Example 1 with CaptchaExpireException

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);
    }
}
Also used : CaptchaExpireException(com.peng.config.exception.CaptchaExpireException) User(com.peng.entity.User) HashMap(java.util.HashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

CaptchaExpireException (com.peng.config.exception.CaptchaExpireException)1 User (com.peng.entity.User)1 HashMap (java.util.HashMap)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1