验证码校验功能

This commit is contained in:
liang.chao 2024-01-24 11:13:46 +08:00
parent fdb6a9e329
commit f66057f442
2 changed files with 18 additions and 5 deletions

View File

@ -3,8 +3,11 @@ package com.bonus.sgzb.auth.controller;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import com.bonus.sgzb.common.core.constant.CacheConstants;
import com.bonus.sgzb.common.redis.service.RedisService;
import com.bonus.sgzb.system.api.RemoteUserService; import com.bonus.sgzb.system.api.RemoteUserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisConnectionUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.bonus.sgzb.auth.form.LoginBody; import com.bonus.sgzb.auth.form.LoginBody;
import com.bonus.sgzb.auth.form.RegisterBody; import com.bonus.sgzb.auth.form.RegisterBody;
@ -21,18 +24,20 @@ import java.util.Map;
/** /**
* token 控制 * token 控制
* *
* @author ruoyi * @author ruoyi
*/ */
@RestController @RestController
public class TokenController public class TokenController {
{
@Autowired @Autowired
private TokenService tokenService; private TokenService tokenService;
@Autowired @Autowired
private SysLoginService sysLoginService; private SysLoginService sysLoginService;
@Resource
private RedisService redisService;
@Resource @Resource
private RemoteUserService remoteUserService; private RemoteUserService remoteUserService;
@ -40,8 +45,14 @@ public class TokenController
public R<?> login(@RequestBody LoginBody form) { public R<?> login(@RequestBody LoginBody form) {
// 用户登录 // 用户登录
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword()); LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
// 获取登录token String uuid = form.getUuid();
return R.ok(tokenService.createToken(userInfo)); String captcha = redisService.getCacheObject(CacheConstants.CAPTCHA_CODE_KEY + uuid).toString();
if (form.getCode() != null && form.getCode().equals(captcha)) {
// 获取登录token
return R.ok(tokenService.createToken(userInfo));
} else {
return R.fail("验证码已过期,请刷新验证码");
}
} }
@PostMapping("sendCode") @PostMapping("sendCode")

View File

@ -29,4 +29,6 @@ public class LoginBody {
*/ */
private String phone; private String phone;
private String uuid;
} }