增加u盾登录

20240109-yw
yuanwei 8 months ago
parent 1fda17caea
commit d1ea056253

@ -14,11 +14,9 @@ import com.glxp.api.entity.sup.UserCompanyEntity;
import com.glxp.api.entity.sup.UserPersonEntity;
import com.glxp.api.entity.system.CompanyEntity;
import com.glxp.api.entity.system.SysPdaKeyEntity;
import com.glxp.api.entity.ud.UdInfoEntity;
import com.glxp.api.exception.JsonException;
import com.glxp.api.req.auth.LoginRequest;
import com.glxp.api.req.auth.PCLoginRequest;
import com.glxp.api.req.auth.UpdatePasswordRequest;
import com.glxp.api.req.auth.UpdateUserRequset;
import com.glxp.api.req.auth.*;
import com.glxp.api.res.auth.LoginResponse;
import com.glxp.api.res.auth.LoginUserInfoResponse;
import com.glxp.api.service.auth.*;
@ -26,7 +24,9 @@ import com.glxp.api.service.monitor.LogininforService;
import com.glxp.api.service.sup.UserCompanyService;
import com.glxp.api.service.sup.UserPersonService;
import com.glxp.api.service.system.CompanyService;
import com.glxp.api.service.ud.UdInfoService;
import com.glxp.api.util.*;
import com.glxp.api.util.sm2.SM2SM3;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
@ -63,6 +63,8 @@ public class UserPersonLoginController extends BaseController {
UserCompanyService userCompanyService;
@Resource
SysPermissionService sysPermissionService;
@Resource
UdInfoService udInfoService;
/**
@ -112,6 +114,62 @@ public class UserPersonLoginController extends BaseController {
}
/**
*
*
* @return
*/
@ApiOperation(value = "U盾系统用户登录",response = LoginResponse.class)
@PostMapping(value = "/loginUd")
public BaseResponse loginUd(@RequestBody @Valid LoginUdRequest loginRequest,
BindingResult bindingResult,
HttpServletRequest request) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("userName", loginRequest.getUsername());
UdInfoEntity entity = udInfoService.getOne(queryWrapper);
if (entity == null) {
throw new JsonException(ResultEnum.DATA_NOT, "用户名或密码错误");
}
boolean checkStatus = SM2SM3.YtVerfiy(entity.getUserName(),loginRequest.getRandomString(),
entity.getPublicKeyX(),entity.getPublicKeyY(),loginRequest.getCiphertext());
if(!checkStatus){
throw new JsonException(ResultEnum.DATA_NOT, "用户名或密码错误");
}
UserPersonEntity userPerson = userPersonService.findByCompanyId(entity.getCompanyId());
if (userPerson == null) {
throw new JsonException(ResultEnum.DATA_NOT, "用户名或密码错误");
}
// 更新登录状态
userPerson.setLastLoginTime(new Date());
userPerson.setLastLoginIp(IpUtils.getIpAddr(request));
userPersonService.update(userPerson);
Map<String, Object> claims = new HashMap<>();
claims.put("admin_id", userPerson.getId());
String token = JwtUtils.createToken(claims, 86400L); // 一天后过期
Map<String, Object> map = new HashMap<>();
map.put("id", userPerson.getId());
map.put("token", token);
map.put("time", DateUtil.getDateTime());
LoginResponse loginResponse = new LoginResponse();
loginResponse.setId(userPerson.getId() + "");
loginResponse.setToken(token);
loginResponse.setCompanyId(userPerson.getCompanyId());
logininforService.recordLogininfor(userPerson.getName(), Constant.LOGIN_SUCCESS, "登录成功!", request);
return ResultVOUtils.success(loginResponse);
}
@ApiIgnore
@AuthRuleAnnotation("")
@ApiOperation(value = "获取登入用户信息",response = LoginUserInfoResponse.class)

@ -0,0 +1,31 @@
package com.glxp.api.req.auth;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
/**
*
*/
@Data
@ApiModel("登录验证请求类")
public class LoginUdRequest {
@ApiModelProperty(value = "用户账号", required = true)
@NotEmpty(message = "用户名不能为空")
private String username;
/**
*
*/
private String randomString;
/**
*
*/
private String ciphertext;
}
Loading…
Cancel
Save