fix: 修改登录接口实现验证码功能
Tento commit je obsažen v:
rodič
6be4ac7a62
revize
036cc1ac25
@ -2,9 +2,11 @@ package com.cnbm.admin.service.impl;
|
|||||||
|
|
||||||
import com.cnbm.admin.entity.LoginUser;
|
import com.cnbm.admin.entity.LoginUser;
|
||||||
import com.cnbm.admin.params.LoginParam;
|
import com.cnbm.admin.params.LoginParam;
|
||||||
|
import com.cnbm.admin.service.CaptchaService;
|
||||||
import com.cnbm.admin.utils.JwtUtil;
|
import com.cnbm.admin.utils.JwtUtil;
|
||||||
import com.cnbm.admin.service.LoginService;
|
import com.cnbm.admin.service.LoginService;
|
||||||
import com.cnbm.admin.utils.ResponseResult;
|
import com.cnbm.admin.utils.ResponseResult;
|
||||||
|
import com.cnbm.common.exception.ErrorCode;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
@ -32,8 +34,16 @@ public class LoginServiceImpl implements LoginService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private AuthenticationManager authenticationManager;
|
private AuthenticationManager authenticationManager;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CaptchaService captchaService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseResult login(HttpServletRequest request, LoginParam loginParam) {
|
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());
|
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginParam.getUsername(),loginParam.getPassword());
|
||||||
Authentication authenticate = authenticationManager.authenticate(authenticationToken);
|
Authentication authenticate = authenticationManager.authenticate(authenticationToken);
|
||||||
if (Objects.isNull(authenticate)) {
|
if (Objects.isNull(authenticate)) {
|
||||||
|
Načítá se…
Odkázat v novém úkolu
Zablokovat Uživatele