短信验证重写方法修改
This commit is contained in:
parent
07d826f2d3
commit
8da0ba0275
|
|
@ -1,11 +1,9 @@
|
|||
package com.bonus.sgzb.auth.controller;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.bonus.sgzb.auth.form.LoginBody;
|
||||
import com.bonus.sgzb.auth.form.RegisterBody;
|
||||
import com.bonus.sgzb.auth.service.SysLoginService;
|
||||
|
|
@ -39,14 +37,24 @@ public class TokenController
|
|||
return R.ok(tokenService.createToken(userInfo));
|
||||
}
|
||||
|
||||
@PostMapping("loginCode")
|
||||
public R<?> loginCode(@RequestBody LoginBody form) {
|
||||
@PostMapping("sendCode")
|
||||
public R<?> sendCode(@RequestBody LoginBody form) {
|
||||
// 用户登录
|
||||
LoginUser userInfo = sysLoginService.loginCode(form.getPhone(), form.getCode());
|
||||
// 获取登录token
|
||||
return R.ok(tokenService.createToken(userInfo));
|
||||
}
|
||||
|
||||
@PostMapping("checkCode")
|
||||
public R<?> checkCode(@RequestBody LoginBody form) {
|
||||
// 校验验证码
|
||||
boolean result = sysLoginService.checkCode(form.getPhone(), form.getCode());
|
||||
if (result) {
|
||||
return R.ok(null, "验证码正确");
|
||||
}
|
||||
return R.fail("短信验证码错误");
|
||||
}
|
||||
|
||||
@DeleteMapping("logout")
|
||||
public R<?> logout(HttpServletRequest request)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import com.bonus.sgzb.common.security.utils.SecurityUtils;
|
|||
import com.bonus.sgzb.system.api.RemoteUserService;
|
||||
import com.bonus.sgzb.system.api.domain.SysUser;
|
||||
import com.bonus.sgzb.system.api.model.LoginUser;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
|
@ -151,6 +150,19 @@ public class SysLoginService
|
|||
}
|
||||
}
|
||||
|
||||
public boolean checkCode(String phone, String code) {
|
||||
String redisCode = redisService.getCacheObject("code_" + phone);
|
||||
if (StringUtils.isEmpty(redisCode)) {
|
||||
throw new ServiceException("验证码失效", 403);
|
||||
}
|
||||
if (!StringUtils.equals(redisCode.split("_")[0], code)) {
|
||||
throw new ServiceException("验证码错误", 401);
|
||||
} else {
|
||||
redisService.deleteObject("code_" + phone);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void isBlackIp(String phone) {
|
||||
String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST));
|
||||
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
|
||||
|
|
|
|||
Loading…
Reference in New Issue