|
@@ -1,6 +1,8 @@
|
|
|
package com.fdkk.sxz.system.controller;
|
|
|
|
|
|
import cn.hutool.captcha.GifCaptcha;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -10,6 +12,7 @@ import com.fdkk.sxz.base.BaseController;
|
|
|
import com.fdkk.sxz.base.Result;
|
|
|
import com.fdkk.sxz.constant.Constant;
|
|
|
import com.fdkk.sxz.constant.ResponseConstant;
|
|
|
+import com.fdkk.sxz.entity.LoginCheckEntity;
|
|
|
import com.fdkk.sxz.entity.system.Resource;
|
|
|
import com.fdkk.sxz.entity.system.Role;
|
|
|
import com.fdkk.sxz.entity.system.User;
|
|
@@ -20,6 +23,7 @@ import com.fdkk.sxz.system.service.IResourceService;
|
|
|
import com.fdkk.sxz.system.service.IUserRoleService;
|
|
|
import com.fdkk.sxz.system.service.IUserService;
|
|
|
import com.fdkk.sxz.util.RedisUtil;
|
|
|
+import com.fdkk.sxz.webApi.service.ILoginCheckService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -58,6 +62,8 @@ public class SysLoginController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
|
private IUserService userService;
|
|
|
+ @Autowired
|
|
|
+ private ILoginCheckService loginCheckService;
|
|
|
|
|
|
@Autowired
|
|
|
private IUserRoleService userRoleService;
|
|
@@ -97,6 +103,37 @@ public class SysLoginController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/applogin")
|
|
|
+ @NoAuthentication
|
|
|
+ @ApiOperation(value = "执行登录先验证是否在时间范围内", notes = "返回token")
|
|
|
+ public Result<String> applogin(@RequestBody LoginUser loginUser, HttpServletRequest request) throws Exception {
|
|
|
+ String userAccount = loginUser.getUserAccount();
|
|
|
+ String userPassword = loginUser.getUserPassword();
|
|
|
+ if (StringUtils.isEmpty(userAccount) || StringUtils.isEmpty(userPassword)) {
|
|
|
+ return error(ResponseConstant.PARAM_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ LoginCheckEntity checkEntity = loginCheckService.findByUserAccount(userAccount);
|
|
|
+ if (ObjectUtil.isNotNull(checkEntity)) {
|
|
|
+ if (!DateUtil.isIn(checkEntity.getStartExpirationTime(),
|
|
|
+ checkEntity.getEndExpirationTime()
|
|
|
+ , DateUtil.parse(DateUtil.now()))) {
|
|
|
+ return error(ResponseConstant.ACCOUNT_EXPIRED);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 查询用户是否存在
|
|
|
+ QueryWrapper<User> ew = new QueryWrapper<>();
|
|
|
+ ew.eq("user_account", userAccount).or().eq("user_mobile", userAccount).or().eq("user_email", userAccount);
|
|
|
+ User user = userService.getOne(ew);
|
|
|
+ if (StringUtils.isEmpty(user) || !BCrypt.checkpw(user.getUserAccount() + userPassword, user.getUserPassword())) {
|
|
|
+ return error(ResponseConstant.INVALID_USERNAME_PASSWORD);
|
|
|
+ }
|
|
|
+ String token = jwtComponent.sign(user.getUserAccount(), user.getUserPassword(), Constant.ExpTimeType.WEB);
|
|
|
+ long expTime = expireTime.get(Constant.ExpTimeType.WEB);
|
|
|
+ redisUtil.setEx("userLoginToken:" + token, JSON.toJSONString(user), expTime, TimeUnit.MILLISECONDS);
|
|
|
+ return successPut(token);
|
|
|
+ }
|
|
|
+
|
|
|
@PostMapping("/login")
|
|
|
@NoAuthentication
|
|
|
@ApiOperation(value = "执行登录", notes = "返回token")
|