鉴权
This commit is contained in:
@@ -4,7 +4,10 @@ import cn.van.business.model.user.LoginRequest;
|
||||
import cn.van.business.model.user.LoginResponse;
|
||||
import cn.van.business.service.CaptchaService;
|
||||
import cn.van.business.util.JwtUtils;
|
||||
import cn.van.business.util.WXUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -19,6 +22,9 @@ import java.util.concurrent.TimeUnit;
|
||||
@RequestMapping("/api/auth")
|
||||
public class AuthController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AuthController.class);
|
||||
|
||||
|
||||
private final CaptchaService captchaService;
|
||||
private final JwtUtils jwtUtils;
|
||||
private final AuthenticationManager authenticationManager;
|
||||
@@ -35,6 +41,11 @@ public class AuthController {
|
||||
|
||||
@PostMapping("/login")
|
||||
public ResponseEntity<LoginResponse> login(@RequestBody LoginRequest request) {
|
||||
logger.info("用户登录");
|
||||
logger.info("用户名:{}", request.getUsername());
|
||||
logger.info("密码:{}", request.getPassword());
|
||||
logger.info("验证码:{}", request.getCaptcha());
|
||||
logger.info("生成的验证码:{}", request.getGeneratedCaptcha());
|
||||
// 1. 基础校验
|
||||
if (StringUtils.isBlank(request.getUsername()) || StringUtils.isBlank(request.getPassword())) {
|
||||
throw new RuntimeException("用户名或密码不能为空");
|
||||
@@ -56,6 +67,7 @@ public class AuthController {
|
||||
new UsernamePasswordAuthenticationToken(request.getUsername(), request.getPassword()));
|
||||
|
||||
// 4. 生成 JWT Token
|
||||
logger.info("用户认证成功");
|
||||
String token = jwtUtils.generateToken(request.getUsername());
|
||||
String refreshToken = generateRefreshToken(request.getUsername());
|
||||
|
||||
@@ -90,6 +102,7 @@ public class AuthController {
|
||||
|
||||
@GetMapping("/captcha")
|
||||
public ResponseEntity<String> getCaptcha() throws Exception {
|
||||
logger.info("获取验证码");
|
||||
String captchaImage = captchaService.generateCaptchaImage();
|
||||
return ResponseEntity.ok(captchaImage);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user