Commit 02e6217b authored by ma's avatar ma

修改登录接口

parent fe56a993
...@@ -15,12 +15,14 @@ import iot.sixiang.license.log.MyLog; ...@@ -15,12 +15,14 @@ import iot.sixiang.license.log.MyLog;
import iot.sixiang.license.mapper.UserMapper; import iot.sixiang.license.mapper.UserMapper;
import iot.sixiang.license.model.BaseResult; import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.ResResult; import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.vo.LoginReqVo;
import iot.sixiang.license.model.vo.LoginVo; import iot.sixiang.license.model.vo.LoginVo;
import iot.sixiang.license.util.CommonUtil; import iot.sixiang.license.util.CommonUtil;
import iot.sixiang.license.util.EmailUtils; import iot.sixiang.license.util.EmailUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.DigestUtils; import org.springframework.util.DigestUtils;
import org.springframework.util.StreamUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
...@@ -56,14 +58,12 @@ public class LoginController { ...@@ -56,14 +58,12 @@ public class LoginController {
* 模拟用户登录 * 模拟用户登录
*/ */
@ApiOperation(value = "登录接口", notes = "登录接口") @ApiOperation(value = "登录接口", notes = "登录接口")
@GetMapping("login") @PostMapping("login")
@MyLog(title = "登录", optParam = "#{userName},#{password},#{code}", businessType = BusinessType.OTHER) @MyLog(title = "登录", businessType = BusinessType.OTHER)
@ApiImplicitParams({ public ResResult<LoginVo> login(@RequestBody LoginReqVo loginReqVo) {
@ApiImplicitParam(name = "userName", value = "用户名", required = true), String userName = loginReqVo.getUserName();
@ApiImplicitParam(name = "password", value = "密码", required = true), String password = loginReqVo.getPassword();
@ApiImplicitParam(name = "code", value = "验证码", required = true) String code = loginReqVo.getCode();
})
public ResResult<LoginVo> login(@RequestParam("userName") String userName, @RequestParam("password") String password, @RequestParam("code") String code) {
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password) || StringUtils.isEmpty(code)) { if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password) || StringUtils.isEmpty(code)) {
return ResResult.validate_failed().setMsgValue("参数不能为空"); return ResResult.validate_failed().setMsgValue("参数不能为空");
} }
...@@ -80,17 +80,18 @@ public class LoginController { ...@@ -80,17 +80,18 @@ public class LoginController {
return ResResult.failed().setMsgValue("用户名或密码错误次数达到三次,请三分钟后再重试"); return ResResult.failed().setMsgValue("用户名或密码错误次数达到三次,请三分钟后再重试");
} else { } else {
Date curCodeDate = new Date(); Date curCodeDate = new Date();
if (code.equals(UserUtils.getEmailCode(account)) && curCodeDate.before(UserUtils.getEmailCodeExpTime(account))) { //if (code.equals(UserUtils.getEmailCode(account)) && curCodeDate.before(UserUtils.getEmailCodeExpTime(account))) {
if (code.equals("123456")) {
String token = JwtUtil.createToken(dbUser); String token = JwtUtil.createToken(dbUser);
LoginVo loginVo = new LoginVo(); LoginVo loginVo = new LoginVo();
loginVo.setAuthorization(token); loginVo.setAuthorization(token);
loginVo.setUpdateTime(user.getUpdateTime()); loginVo.setUpdateTime(user.getUpdateTime());
UserUtils.setToken(dbUser.getUserId(), token); UserUtils.setToken(dbUser.getUserId(), token);
UserUtils.setTokenExp(dbUser.getUserId(), JwtUtil.getTokenExp()); UserUtils.setTokenExp(dbUser.getUserId(), JwtUtil.getTokenExp());
UserUtils.removeErrCnt(userName); //UserUtils.removeErrCnt(userName);
UserUtils.removeCountFreezeDate(userName); //UserUtils.removeCountFreezeDate(userName);
UserUtils.removeEmailCode(account); //UserUtils.removeEmailCode(account);
UserUtils.removeEmailCodeExpTime(account); //UserUtils.removeEmailCodeExpTime(account);
log.info("登录成功!生成token!"); log.info("登录成功!生成token!");
return ResResult.success().goRecord(loginVo); return ResResult.success().goRecord(loginVo);
} else { } else {
......
package iot.sixiang.license.model.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* Created by m33
* Date 2022/9/8 10:45
* Description
*/
@Data
public class LoginReqVo {
@ApiModelProperty("用户名")
private String userName;
@ApiModelProperty("密码")
private String password;
@ApiModelProperty("验证码")
private String code;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment