验证码校验功能
This commit is contained in:
parent
fdb6a9e329
commit
f66057f442
|
|
@ -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;
|
||||||
|
|
@ -25,14 +28,16 @@ import java.util.Map;
|
||||||
* @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());
|
||||||
|
String uuid = form.getUuid();
|
||||||
|
String captcha = redisService.getCacheObject(CacheConstants.CAPTCHA_CODE_KEY + uuid).toString();
|
||||||
|
if (form.getCode() != null && form.getCode().equals(captcha)) {
|
||||||
// 获取登录token
|
// 获取登录token
|
||||||
return R.ok(tokenService.createToken(userInfo));
|
return R.ok(tokenService.createToken(userInfo));
|
||||||
|
} else {
|
||||||
|
return R.fail("验证码已过期,请刷新验证码");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("sendCode")
|
@PostMapping("sendCode")
|
||||||
|
|
|
||||||
|
|
@ -29,4 +29,6 @@ public class LoginBody {
|
||||||
*/
|
*/
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
|
|
||||||
|
private String uuid;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue