Commit 02e6217b authored by ma's avatar ma

修改登录接口

parent fe56a993
......@@ -15,12 +15,14 @@ import iot.sixiang.license.log.MyLog;
import iot.sixiang.license.mapper.UserMapper;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.vo.LoginReqVo;
import iot.sixiang.license.model.vo.LoginVo;
import iot.sixiang.license.util.CommonUtil;
import iot.sixiang.license.util.EmailUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.DigestUtils;
import org.springframework.util.StreamUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
......@@ -56,14 +58,12 @@ public class LoginController {
* 模拟用户登录
*/
@ApiOperation(value = "登录接口", notes = "登录接口")
@GetMapping("login")
@MyLog(title = "登录", optParam = "#{userName},#{password},#{code}", businessType = BusinessType.OTHER)
@ApiImplicitParams({
@ApiImplicitParam(name = "userName", value = "用户名", required = true),
@ApiImplicitParam(name = "password", value = "密码", required = true),
@ApiImplicitParam(name = "code", value = "验证码", required = true)
})
public ResResult<LoginVo> login(@RequestParam("userName") String userName, @RequestParam("password") String password, @RequestParam("code") String code) {
@PostMapping("login")
@MyLog(title = "登录", businessType = BusinessType.OTHER)
public ResResult<LoginVo> login(@RequestBody LoginReqVo loginReqVo) {
String userName = loginReqVo.getUserName();
String password = loginReqVo.getPassword();
String code = loginReqVo.getCode();
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password) || StringUtils.isEmpty(code)) {
return ResResult.validate_failed().setMsgValue("参数不能为空");
}
......@@ -80,17 +80,18 @@ public class LoginController {
return ResResult.failed().setMsgValue("用户名或密码错误次数达到三次,请三分钟后再重试");
} else {
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);
LoginVo loginVo = new LoginVo();
loginVo.setAuthorization(token);
loginVo.setUpdateTime(user.getUpdateTime());
UserUtils.setToken(dbUser.getUserId(), token);
UserUtils.setTokenExp(dbUser.getUserId(), JwtUtil.getTokenExp());
UserUtils.removeErrCnt(userName);
UserUtils.removeCountFreezeDate(userName);
UserUtils.removeEmailCode(account);
UserUtils.removeEmailCodeExpTime(account);
//UserUtils.removeErrCnt(userName);
//UserUtils.removeCountFreezeDate(userName);
//UserUtils.removeEmailCode(account);
//UserUtils.removeEmailCodeExpTime(account);
log.info("登录成功!生成token!");
return ResResult.success().goRecord(loginVo);
} 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