| | |
| | | package com.gkhy.exam.framework.web.service; |
| | | |
| | | import cn.hutool.core.codec.Base64; |
| | | import com.gkhy.exam.common.constant.CacheConstant; |
| | | import com.gkhy.exam.common.constant.Constant; |
| | | import com.gkhy.exam.common.constant.UserConstant; |
| | | import com.gkhy.exam.common.domain.entity.SysUser; |
| | |
| | | import com.gkhy.exam.common.enums.LoginUserTagEnum; |
| | | import com.gkhy.exam.common.exception.ApiException; |
| | | import com.gkhy.exam.common.utils.IpUtils; |
| | | import com.gkhy.exam.common.utils.RedisUtils; |
| | | import com.gkhy.exam.framework.manager.AsyncManager; |
| | | import com.gkhy.exam.framework.manager.factory.AsyncFactory; |
| | | import com.gkhy.exam.framework.security.context.AuthenticationContextHolder; |
| | |
| | | @Autowired |
| | | private HttpServletRequest request; |
| | | |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | | |
| | | |
| | | |
| | |
| | | String password=loginBody.getPassword(); |
| | | password= Base64.decodeStr(password); |
| | | //验证码校验 |
| | | //validateCaptcha(username,loginBody.code,loginBody.uuid); |
| | | validateCaptcha(username,loginBody.getCode(),loginBody.getUuid()); |
| | | loginPreCheck(username, password); |
| | | Authentication authentication=null; |
| | | try{ |
| | |
| | | // } |
| | | } |
| | | |
| | | /** |
| | | * 校验验证码 |
| | | * |
| | | * @param username 用户名 |
| | | * @param code 验证码 |
| | | * @param uuid 唯一标识 |
| | | * @return 结果 |
| | | */ |
| | | public void validateCaptcha(String username, String code, String uuid) |
| | | { |
| | | if(StringUtils.isBlank(code)||StringUtils.isBlank(uuid)){ |
| | | throw new ApiException("验证码或验证码标识为空"); |
| | | } |
| | | String verifyKey = CacheConstant.CAPTCHA_CODE_KEY +uuid; |
| | | String captcha = (String) redisUtils.get(verifyKey); |
| | | redisUtils.del(verifyKey); |
| | | if (StringUtils.isBlank(captcha)) |
| | | { |
| | | throw new ApiException("验证码已失效"); |
| | | } |
| | | if (!code.equalsIgnoreCase(captcha)) |
| | | { |
| | | throw new ApiException("验证码不正确"); |
| | | } |
| | | } |
| | | |
| | | public void logout(){ |
| | | tokenService.delTokenCache(request); |