|
|
@@ -1,10 +1,12 @@
|
|
|
package com.zd.auth.controller;
|
|
|
|
|
|
+
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import com.zd.auth.form.LoginBody;
|
|
|
import com.zd.auth.form.RegisterBody;
|
|
|
import com.zd.auth.service.SysLoginService;
|
|
|
import com.zd.chemical.api.fegin.RemoteStockService;
|
|
|
+import com.zd.common.core.exception.ParamException;
|
|
|
import com.zd.common.core.exception.ServiceException;
|
|
|
import com.zd.common.core.redis.RedisService;
|
|
|
import com.zd.common.core.security.TokenService;
|
|
|
@@ -14,74 +16,101 @@ import com.zd.common.core.utils.StringUtils;
|
|
|
import com.zd.model.constant.*;
|
|
|
import com.zd.model.domain.AjaxResult;
|
|
|
import com.zd.model.domain.R;
|
|
|
+import com.zd.model.domain.ResultData;
|
|
|
+import com.zd.model.entity.LoginModel;
|
|
|
import com.zd.model.entity.LoginUser;
|
|
|
import com.zd.model.entity.SysUser;
|
|
|
+import com.zd.system.api.bo.SysLoginBo;
|
|
|
import com.zd.system.api.feign.RemoteUserService;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
-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 org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import static com.zd.model.constant.BaseConstants.CODE_EXPIRATION;
|
|
|
|
|
|
-/**
|
|
|
- * token 控制
|
|
|
+/***
|
|
|
+ * <p>认证接口</p>
|
|
|
*
|
|
|
- * @author zd
|
|
|
+ * @author linft
|
|
|
+ * @date 6/21/2023
|
|
|
+ * @version 3.0
|
|
|
*/
|
|
|
@RestController
|
|
|
-public class TokenController {
|
|
|
+public class AuthController {
|
|
|
|
|
|
- private final Logger logger = LoggerFactory.getLogger(TokenController.class);
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(AuthController.class);
|
|
|
|
|
|
@Autowired
|
|
|
private TokenService tokenService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private SysLoginService sysLoginService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private RemoteUserService remoteUserService;
|
|
|
- @Autowired
|
|
|
- private RedisService redisService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private RemoteStockService stockService;
|
|
|
+
|
|
|
@Resource
|
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
- @PostMapping("login")
|
|
|
- public R<?> login(@RequestBody LoginBody form) {
|
|
|
+ @Autowired
|
|
|
+ private RedisService redisService;
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("/login")
|
|
|
+ public R login(@RequestBody LoginBody form) {
|
|
|
// 用户登录
|
|
|
String authType = form.getAuthType() == null ? BaseConstants.GRANT_TYPE_PASSWORD : form.getAuthType();
|
|
|
- LoginUser userInfo;
|
|
|
- if (Objects.equals(authType, BaseConstants.GRANT_TYPE_MOBILE)) {
|
|
|
+ LoginModel loginModel = new LoginModel();
|
|
|
+ SysLoginBo loginBo = new SysLoginBo();
|
|
|
+ loginBo.setAccount(form.getUsername());
|
|
|
+ loginBo.setGrantType(authType);
|
|
|
+ if (BaseConstants.GRANT_TYPE_PASSWORD.equals(authType)) {
|
|
|
+ //校验参数
|
|
|
+ if (StringUtils.isEmpty(form.getUsername()) || StringUtils.isEmpty(form.getPassword())) {
|
|
|
+ throw new ParamException("账号信息不能为空");
|
|
|
+ } else if (form.getUsername().length() < UserConstants.USERNAME_MIN_LENGTH
|
|
|
+ || form.getUsername().length() > UserConstants.USERNAME_MAX_LENGTH
|
|
|
+ || form.getPassword().length() < UserConstants.PASSWORD_MIN_LENGTH
|
|
|
+ || form.getPassword().length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
|
|
+ throw new ParamException("账号参数有误");
|
|
|
+ } else {
|
|
|
+ loginBo.setPassword(form.getPassword());
|
|
|
+ loginBo.setLoginType(UserConstants.USER_LOGIN_PC);
|
|
|
+ R<LoginModel> r = remoteUserService.userLogin(loginBo);
|
|
|
+ if (r.getCode() == HttpStatus.SUCCESS && r.getData() != null) {
|
|
|
+ loginModel = r.getData();
|
|
|
+ } else if (r.getCode() == HttpStatus.ERROR){
|
|
|
+ return R.fail(r.getMsg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (BaseConstants.GRANT_TYPE_MOBILE.equals(authType)) {
|
|
|
+ //手机号
|
|
|
String key = BaseConstants.DEFAULT_CODE_KEY + BaseConstants.GRANT_TYPE_MOBILE + "@" + form.getUsername();
|
|
|
String code = redisTemplate.opsForValue().get(key);
|
|
|
if (form.getPassword().equals(code)) {
|
|
|
- R<LoginUser> userR = remoteUserService.getUserInfo(form.getUsername(), SecurityConstants.INNER);
|
|
|
- if (userR.getCode() == HttpStatus.SUCCESS && userR.getData() != null) {
|
|
|
- userInfo = userR.getData();
|
|
|
- } else {
|
|
|
- throw new ServiceException("服务未知异常,请稍后重试");
|
|
|
+ R<LoginModel> r = remoteUserService.phoneAccount(loginBo);
|
|
|
+ if (r.getCode() == HttpStatus.SUCCESS && r.getData() != null) {
|
|
|
+ loginModel = r.getData();
|
|
|
+ } else if (r.getCode() == HttpStatus.ERROR){
|
|
|
+ return R.fail(r.getMsg());
|
|
|
}
|
|
|
- } else {
|
|
|
- throw new ServiceException("验证码不正确", 503);
|
|
|
}
|
|
|
- } else {
|
|
|
- userInfo = sysLoginService.login(form.getUsername(), UserConstants.USER_LOGIN_PC, form.getPassword());
|
|
|
}
|
|
|
- userInfo.setLoginType(UserConstants.USER_LOGIN_PC);
|
|
|
- Map<String, Object> data = tokenService.createToken(userInfo);
|
|
|
+ loginModel.setLoginType(UserConstants.USER_LOGIN_PC);
|
|
|
+ Map<String, Object> data = tokenService.createToken(loginModel);
|
|
|
//这里判断输入的密码,是否和默认配置密码一样,如果一样,需要提示跳转设置密码
|
|
|
AjaxResult resultPassword = remoteUserService.getConfigKey("sys.user.initPassword");
|
|
|
if ((resultPassword.get("code") + "").equals("200")) {
|
|
|
@@ -94,7 +123,7 @@ public class TokenController {
|
|
|
}
|
|
|
// 区分大屏用户
|
|
|
// 查询大屏链接
|
|
|
- AjaxResult result = remoteUserService.getRouters(userInfo.getUserid());
|
|
|
+ AjaxResult result = remoteUserService.getRouters(loginModel.getUserId());
|
|
|
try {
|
|
|
List<Map<String, Object>> routers = (List<Map<String, Object>>) result.get("data");
|
|
|
Map<String, Object> dataMenu = routers.stream().filter(
|
|
|
@@ -103,30 +132,28 @@ public class TokenController {
|
|
|
String tokenKey = "login_screen:";
|
|
|
|
|
|
Integer type;
|
|
|
- if (userInfo.getSysUser().isAdmin()) {
|
|
|
+ if (loginModel.isAdmin()) {
|
|
|
type = 1;
|
|
|
} else {
|
|
|
- result = remoteUserService.selectAuthUserPower(userInfo.getUserid());
|
|
|
+ result = remoteUserService.selectAuthUserPower(loginModel.getUserId());
|
|
|
Map<String, Object> map = (Map<String, Object>) result.get("data");
|
|
|
type = Integer.parseInt(map.get("type") + "");
|
|
|
}
|
|
|
-
|
|
|
if (type == null) {
|
|
|
// 没有大屏权限
|
|
|
type = 3;
|
|
|
data.put("screen_token", "");
|
|
|
- } else if (redisService.hasKey(tokenKey + userInfo.getUserid())) {
|
|
|
- String token = redisService.getCacheObject(tokenKey + userInfo.getUserid());
|
|
|
- commLogin(userInfo, token);
|
|
|
+ } else if (redisService.hasKey(tokenKey + loginModel.getUserId())) {
|
|
|
+ String token = redisService.getCacheObject(tokenKey + loginModel.getUserId());
|
|
|
+ commLogin(loginModel, token);
|
|
|
data.put("screen_token", token);
|
|
|
} else {
|
|
|
String token = IdUtils.fastUUID();
|
|
|
- commLogin(userInfo, token);
|
|
|
- redisService.setCacheObject(tokenKey + userInfo.getUserid(), token);
|
|
|
+ commLogin(loginModel, token);
|
|
|
+ redisService.setCacheObject(tokenKey + loginModel.getUserId(), token, BaseConstants.TOKEN_EXPIRE, TimeUnit.SECONDS);
|
|
|
// 获取大屏TOKEN
|
|
|
data.put("screen_token", token);
|
|
|
}
|
|
|
-
|
|
|
data.put("screen_type", type);
|
|
|
} else {
|
|
|
// 没有大屏权限
|
|
|
@@ -143,11 +170,9 @@ public class TokenController {
|
|
|
}
|
|
|
|
|
|
//公共登录方法
|
|
|
- private void commLogin(LoginUser userInfo, String token) {
|
|
|
- LoginUser loginUser = new LoginUser();
|
|
|
- BeanUtils.copyProperties(userInfo, loginUser);
|
|
|
- loginUser.setToken(token);
|
|
|
- redisService.setCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token, loginUser);
|
|
|
+ private void commLogin(LoginModel model, String token) {
|
|
|
+ model.setToken(token);
|
|
|
+ redisService.setCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token, model, BaseConstants.TOKEN_EXPIRE, TimeUnit.SECONDS);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -155,19 +180,51 @@ public class TokenController {
|
|
|
* 小程序登录也在用
|
|
|
*/
|
|
|
@PostMapping("/one/login")
|
|
|
- public R<?> oneLogin(@RequestBody LoginBody form) {
|
|
|
+ public R oneLogin(@RequestBody LoginBody form) {
|
|
|
// 用户登录
|
|
|
- LoginUser userInfo = sysLoginService.login(form.getUsername(), UserConstants.USER_LOGIN_WX, form.getPassword());
|
|
|
- userInfo.setLoginType(UserConstants.USER_LOGIN_WX);
|
|
|
+ SysLoginBo loginBo = new SysLoginBo();
|
|
|
+ loginBo.setAccount(form.getUsername());
|
|
|
+ loginBo.setPassword(form.getPassword());
|
|
|
+ loginBo.setGrantType(BaseConstants.GRANT_TYPE_PASSWORD);
|
|
|
+ loginBo.setLoginType(UserConstants.USER_LOGIN_WX);
|
|
|
+ R<LoginModel> r = remoteUserService.userLogin(loginBo);
|
|
|
+ if (r.getCode() != HttpStatus.SUCCESS || r.getData() == null) {
|
|
|
+ return R.fail(r.getMsg());
|
|
|
+ }
|
|
|
+ LoginModel model = r.getData();
|
|
|
+ model.setLoginType(UserConstants.USER_LOGIN_WX);
|
|
|
// 获取登录token
|
|
|
- return R.ok(tokenService.createProgramToken(userInfo));
|
|
|
+ return R.ok(tokenService.createProgramToken(model));
|
|
|
+ }
|
|
|
+
|
|
|
+ /***
|
|
|
+ * 手持机账号、密码 登录
|
|
|
+ * @param form
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/pda/pwdLogin")
|
|
|
+ public R padLogin(@RequestBody LoginBody form) {
|
|
|
+ // 用户登录
|
|
|
+ SysLoginBo loginBo = new SysLoginBo();
|
|
|
+ loginBo.setAccount(form.getUsername());
|
|
|
+ loginBo.setPassword(form.getPassword());
|
|
|
+ loginBo.setGrantType(BaseConstants.GRANT_TYPE_PASSWORD);
|
|
|
+ R<LoginModel> r = remoteUserService.userLogin(loginBo);
|
|
|
+ if (r.getCode() != HttpStatus.SUCCESS || r.getData() == null) {
|
|
|
+ return R.fail(r.getMsg());
|
|
|
+ }
|
|
|
+ LoginModel model = r.getData();
|
|
|
+ model.setLoginType(UserConstants.HANDSET_LOGIN_AIO);
|
|
|
+ // 获取登录token
|
|
|
+ return R.ok(tokenService.createProgramToken(model));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 发送验证码
|
|
|
*/
|
|
|
+
|
|
|
@PostMapping("/send/code")
|
|
|
- public R<?> send(@RequestBody LoginBody form) {
|
|
|
+ public R send(@RequestBody LoginBody form) {
|
|
|
String username = form.getUsername();
|
|
|
R<LoginUser> userR = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
|
|
if (userR.getCode() != HttpStatus.SUCCESS || userR.getData() == null) {
|
|
|
@@ -194,40 +251,30 @@ public class TokenController {
|
|
|
return stockService.sendSydSms(code, 2, null, form.getUsername());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 学习一体机 用户端登录
|
|
|
* 接口修改为分两步操作,1 刷卡获取人员信息和token , 2 人脸验证之后再调用一次实现真实登录
|
|
|
* type : 1 和 2
|
|
|
*/
|
|
|
+
|
|
|
@PostMapping("/learn/login")
|
|
|
- public R<?> learnLogin(HttpServletRequest request, @RequestBody Map<String, Object> params) {
|
|
|
+ public R learnLogin(HttpServletRequest request, @RequestBody Map<String, Object> params) {
|
|
|
int type = org.apache.commons.lang3.StringUtils.isNotBlank((String) params.get("type")) ? Integer.parseInt((String) params.get("type")) : 1;
|
|
|
String machineCode = params.get("machineCode") == null ? "" : (String) params.get("machineCode");
|
|
|
// 用户登录
|
|
|
String username = (String) params.get("userName");
|
|
|
int aioType = params.get("aioType") == null ? UserConstants.USER_LOGIN_AIO : Integer.parseInt(params.get("aioType") + "");
|
|
|
- logger.error("学习机登录,加密前:" + username + ",设备编码:" + machineCode);
|
|
|
+ logger.error("学习机登录,加密前:" + username + ",设备编码:" + machineCode +"设备类型:"+aioType);
|
|
|
if (UserConstants.USER_LOGIN_HXP == aioType) {
|
|
|
- // TODO 终端传参数据有问题,暂临时后端处理
|
|
|
+ //终端传参数据有问题,暂临时后端处理
|
|
|
//通过des生成对称加密卡号
|
|
|
+ logger.error("化学品补0:" + DESUtils.completeMissing(username));
|
|
|
username = DESUtils.encrypt(DESUtils.completeMissing(username));
|
|
|
-
|
|
|
-// username = username.replaceAll("%00", "")
|
|
|
-// .replaceAll("%02", "")
|
|
|
-// .replaceAll("%03", "")
|
|
|
-// .replaceAll("%0A", "")
|
|
|
-// .replaceAll("%0D", "")
|
|
|
-// .trim();
|
|
|
+ logger.error("化学品加密后:" + username);
|
|
|
} else {
|
|
|
- // 查询用户信息
|
|
|
-// if (StringUtils.isNumeric(username)) {
|
|
|
-// username = Long.toHexString(Long.parseLong(username)).toUpperCase();
|
|
|
- username =DESUtils.encrypt(username+"");
|
|
|
- logger.error("学习机登录,加密后:" + username);
|
|
|
-// } else {
|
|
|
-// logger.error("通过卡号未找到用户");
|
|
|
-// return R.fail("无效卡号或未绑定用户,请联系管理员!");
|
|
|
-// }
|
|
|
+ username =DESUtils.encrypt(username+"");
|
|
|
+ logger.error("学习机登录,加密后:" + username);
|
|
|
}
|
|
|
R<SysUser> user = remoteUserService.getUserInfoByCardNum(username, SecurityConstants.INNER);
|
|
|
if (R.FAIL == user.getCode()) {
|
|
|
@@ -236,42 +283,46 @@ public class TokenController {
|
|
|
if (StringUtils.isNull(user.getData())) {
|
|
|
return R.fail("账号信息不存在");
|
|
|
}
|
|
|
- R<LoginUser> userResult = remoteUserService.getUserInfo(user.getData().getUserName(), aioType, SecurityConstants.INNER);
|
|
|
- if (R.FAIL == userResult.getCode() || 503 == userResult.getCode()) {
|
|
|
- return R.fail(userResult.getMsg());
|
|
|
+ SysLoginBo loginBo = new SysLoginBo();
|
|
|
+ loginBo.setAccount(user.getData().getUserName());
|
|
|
+ loginBo.setLoginType(aioType);
|
|
|
+ R<LoginModel> r = remoteUserService.userLoginByNoPassword(loginBo);
|
|
|
+ if (r.getCode() != R.SUCCESS) {
|
|
|
+ return R.fail(r.getMsg());
|
|
|
}
|
|
|
- if (userResult.getData() != null) {
|
|
|
- LoginUser userInfo = userResult.getData();
|
|
|
+ if (r.getData() != null) {
|
|
|
+ LoginModel userInfo = r.getData();
|
|
|
userInfo.setLoginType(aioType);
|
|
|
userInfo.setMachineCode(machineCode);
|
|
|
- if (userInfo.getSysUser() == null) {
|
|
|
- return R.fail("账号信息不存在");
|
|
|
- }
|
|
|
Map<String, Object> map = null;
|
|
|
if (type == 1) {
|
|
|
// 获取登录token
|
|
|
map = tokenService.createToken(userInfo);
|
|
|
} else if (type == 2) {
|
|
|
// 资源删除
|
|
|
- LoginUser loginUser = tokenService.getLoginUser(request);
|
|
|
+ LoginModel loginUser = tokenService.getLoginUser(request);
|
|
|
if (StringUtils.isNotNull(loginUser)) {
|
|
|
// 删除用户缓存记录
|
|
|
tokenService.delLoginUser(loginUser.getToken());
|
|
|
}
|
|
|
map = tokenService.createToken(userInfo);
|
|
|
if (UserConstants.USER_LOGIN_HXP == aioType) {
|
|
|
- map.put("positionName", userInfo.getSysUser().getPositionName());
|
|
|
+ map.put("positionName", userInfo.getPositionName());
|
|
|
map.put("cabinetLock", userInfo.isCabinetLock());
|
|
|
map.put("airBottle", userInfo.isAirBottle());
|
|
|
} else if (UserConstants.USER_LOGIN_AIO == aioType) {
|
|
|
- if (redisService.hasKey(CacheConstants.LEARN_USER_KEY + userInfo.getSysUser().getUserId())) {
|
|
|
- LoginUser userCache = redisService.getCacheObject(CacheConstants.LEARN_USER_KEY + userInfo.getSysUser().getUserId());
|
|
|
- if (!machineCode.equals(userCache.getMachineCode())) {
|
|
|
- return R.fail("签到失败,不能重复签到!");
|
|
|
+ if (redisService.hasKey(CacheConstants.LEARN_USER_KEY + userInfo.getUserId())) {
|
|
|
+ LoginModel userCache = redisService.getCacheObject(CacheConstants.LEARN_USER_KEY + userInfo.getUserId());
|
|
|
+ if(StringUtils.isNull(params.get("isLogin")) || "0".equals(params.get("isLogin"))){
|
|
|
+ if (machineCode.equals(userCache.getMachineCode())) {
|
|
|
+ return R.fail(4466,"您已在设备登录,是否重新登录!");
|
|
|
+ }else{
|
|
|
+ return R.fail("签到失败,不能重复签到!");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
// 记录学习一体机用户登录状态
|
|
|
- redisService.setCacheObject(CacheConstants.LEARN_USER_KEY + userInfo.getSysUser().getUserId(), userInfo, BaseConstants.TOKEN_EXPIRE * 60, TimeUnit.SECONDS);
|
|
|
+ redisService.setCacheObject(CacheConstants.LEARN_USER_KEY + userInfo.getUserId(), userInfo, BaseConstants.TOKEN_EXPIRE * 60, TimeUnit.SECONDS);
|
|
|
}
|
|
|
}
|
|
|
return R.ok(map);
|
|
|
@@ -280,40 +331,77 @@ public class TokenController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 手持机 用户端登录
|
|
|
+ * 接口操作,1刷卡验证之后调用实现真实登录
|
|
|
+ */
|
|
|
+
|
|
|
+ @PostMapping("/handset/login")
|
|
|
+ public R handsetLogin(@RequestBody Map<String, Object> params) {
|
|
|
+ // 用户登录
|
|
|
+ String username = (String) params.get("userName");
|
|
|
+ logger.error("手持机登录,加密前:" + username);
|
|
|
+ //通过des生成对称加密卡号
|
|
|
+ username = DESUtils.encrypt(username);
|
|
|
+ logger.error("手持机登录,加密后:" + username);
|
|
|
+
|
|
|
+ int aioType = UserConstants.HANDSET_LOGIN_AIO;
|
|
|
+
|
|
|
+ R<SysUser> user = remoteUserService.getUserInfoByCardNum(username, SecurityConstants.INNER);
|
|
|
+ if (R.FAIL == user.getCode()) {
|
|
|
+ throw new ServiceException(user.getMsg());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNull(user.getData())) {
|
|
|
+ return R.fail("账号信息不存在");
|
|
|
+ }
|
|
|
+ SysLoginBo loginBo = new SysLoginBo();
|
|
|
+ loginBo.setAccount(user.getData().getUserName());
|
|
|
+ loginBo.setLoginType(aioType);
|
|
|
+ R<LoginModel> r = remoteUserService.userLoginByNoPassword(loginBo);
|
|
|
+ if (r.getCode() != R.SUCCESS) {
|
|
|
+ return R.fail(r.getMsg());
|
|
|
+ }
|
|
|
+ if (r.getData() != null) {
|
|
|
+ LoginModel userInfo = r.getData();
|
|
|
+ userInfo.setLoginType(aioType);
|
|
|
+ // 获取登录token
|
|
|
+ Map<String, Object> map = tokenService.createToken(userInfo);
|
|
|
+ return R.ok(map);
|
|
|
+ } else {
|
|
|
+ return R.fail("账号信息不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 学习一体机 用户退出登录
|
|
|
*/
|
|
|
@PostMapping("/learn/loginOut")
|
|
|
- public R<?> learnLoginOut(HttpServletRequest request) {
|
|
|
- LoginUser loginUser = tokenService.getLoginUser(request);
|
|
|
+ public R learnLoginOut(HttpServletRequest request) {
|
|
|
+ LoginModel loginUser = tokenService.getLoginUser(request);
|
|
|
if (StringUtils.isNotNull(loginUser)) {
|
|
|
- SysUser user = loginUser.getSysUser();
|
|
|
// 删除用户缓存记录
|
|
|
tokenService.delLoginUser(loginUser.getToken());
|
|
|
- // 记录用户退出日志
|
|
|
- sysLoginService.logout(user);
|
|
|
// 删除一体机登录状态
|
|
|
- redisService.deleteObject(CacheConstants.LEARN_USER_KEY + loginUser.getUserid());
|
|
|
+ redisService.deleteObject(CacheConstants.LEARN_USER_KEY + loginUser.getUserId());
|
|
|
}
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
@DeleteMapping("logout")
|
|
|
- public R<?> logout(HttpServletRequest request) {
|
|
|
- LoginUser loginUser = tokenService.getLoginUser(request);
|
|
|
+ public R logout(HttpServletRequest request) {
|
|
|
+ LoginModel loginUser = tokenService.getLoginUser(request);
|
|
|
if (StringUtils.isNotNull(loginUser)) {
|
|
|
- SysUser user = loginUser.getSysUser();
|
|
|
// 删除用户缓存记录
|
|
|
tokenService.delLoginUser(loginUser.getToken());
|
|
|
- // 记录用户退出日志
|
|
|
- sysLoginService.logout(user);
|
|
|
}
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
@PostMapping("refresh")
|
|
|
- public R<?> refresh(HttpServletRequest request) {
|
|
|
- LoginUser loginUser = tokenService.getLoginUser(request);
|
|
|
+ public R refresh(HttpServletRequest request) {
|
|
|
+ LoginModel loginUser = tokenService.getLoginUser(request);
|
|
|
if (StringUtils.isNotNull(loginUser)) {
|
|
|
// 刷新令牌有效期
|
|
|
tokenService.refreshToken(loginUser);
|
|
|
@@ -323,9 +411,22 @@ public class TokenController {
|
|
|
}
|
|
|
|
|
|
@PostMapping("register")
|
|
|
- public R<?> register(@RequestBody RegisterBody registerBody) {
|
|
|
+ public R register(@RequestBody RegisterBody registerBody) {
|
|
|
// 用户注册
|
|
|
sysLoginService.register(registerBody.getUsername(), registerBody.getPassword());
|
|
|
return R.ok();
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation(value = "手持机人脸登录")
|
|
|
+ @PostMapping("/facePda")
|
|
|
+ public R face(@RequestParam("file") MultipartFile file) {
|
|
|
+ //调用人脸对比获取用户信息
|
|
|
+ ResultData<LoginModel> result = remoteUserService.pdaCompare(file);
|
|
|
+ if (result.getCode().equals(HttpStatus.SUCCESS)) {
|
|
|
+ LoginModel model = result.getData();
|
|
|
+ Map<String, Object> data = tokenService.createToken(model);
|
|
|
+ return R.ok(data);
|
|
|
+ }
|
|
|
+ return R.fail(result.getMsg());
|
|
|
+ }
|
|
|
}
|