fix: 修改登录接口实现验证码功能

Этот коммит содержится в:
weihongyang 2022-06-23 14:02:00 +08:00
родитель 6be4ac7a62
Коммит 036cc1ac25

Просмотреть файл

@ -2,9 +2,11 @@ package com.cnbm.admin.service.impl;
import com.cnbm.admin.entity.LoginUser;
import com.cnbm.admin.params.LoginParam;
import com.cnbm.admin.service.CaptchaService;
import com.cnbm.admin.utils.JwtUtil;
import com.cnbm.admin.service.LoginService;
import com.cnbm.admin.utils.ResponseResult;
import com.cnbm.common.exception.ErrorCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.authentication.AuthenticationManager;
@ -32,8 +34,16 @@ public class LoginServiceImpl implements LoginService {
@Autowired
private AuthenticationManager authenticationManager;
@Autowired
private CaptchaService captchaService;
@Override
public ResponseResult login(HttpServletRequest request, LoginParam loginParam) {
//验证码是否正确
boolean flag = captchaService.validate(loginParam.getUuid(), loginParam.getCaptcha());
if(!flag){
return new ResponseResult(ErrorCode.CAPTCHA_ERROR,"验证码错误");
}
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginParam.getUsername(),loginParam.getPassword());
Authentication authenticate = authenticationManager.authenticate(authenticationToken);
if (Objects.isNull(authenticate)) {