|
@@ -5,6 +5,7 @@ import com.gis.common.base.service.LogService;
|
|
import com.gis.common.constant.ConfigConstant;
|
|
import com.gis.common.constant.ConfigConstant;
|
|
import com.gis.common.util.JwtUtil;
|
|
import com.gis.common.util.JwtUtil;
|
|
import com.gis.common.util.PasswordUtils;
|
|
import com.gis.common.util.PasswordUtils;
|
|
|
|
+import com.gis.common.util.RedisUtil;
|
|
import com.gis.common.util.Result;
|
|
import com.gis.common.util.Result;
|
|
import com.gis.admin.entity.po.SysUserEntity;
|
|
import com.gis.admin.entity.po.SysUserEntity;
|
|
import com.gis.admin.service.SysResourceService;
|
|
import com.gis.admin.service.SysResourceService;
|
|
@@ -27,8 +28,7 @@ import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.Set;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -37,7 +37,7 @@ import java.util.concurrent.TimeUnit;
|
|
@Api(tags = "sys-登录")
|
|
@Api(tags = "sys-登录")
|
|
@RestController
|
|
@RestController
|
|
@Log4j2
|
|
@Log4j2
|
|
-public class IndexController {
|
|
|
|
|
|
+public class LoginController {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private LogService logService;
|
|
private LogService logService;
|
|
@@ -51,8 +51,8 @@ public class IndexController {
|
|
@Autowired
|
|
@Autowired
|
|
SysResourceService sysResourceService;
|
|
SysResourceService sysResourceService;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
+// @Autowired
|
|
|
|
+// private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
ConfigConstant configConstant;
|
|
ConfigConstant configConstant;
|
|
@@ -60,6 +60,9 @@ public class IndexController {
|
|
@Resource
|
|
@Resource
|
|
protected HttpServletRequest request;
|
|
protected HttpServletRequest request;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ RedisUtil redisUtil;
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
// 目前是24h
|
|
// 目前是24h
|
|
@@ -69,6 +72,14 @@ public class IndexController {
|
|
@PostMapping(value = "admin/login")
|
|
@PostMapping(value = "admin/login")
|
|
public Result login(@Valid @RequestBody LoginDto param) {
|
|
public Result login(@Valid @RequestBody LoginDto param) {
|
|
|
|
|
|
|
|
+ String from = param.getFrom();
|
|
|
|
+ String[] checkFrom = {"cms","web"};
|
|
|
|
+ List<String> fromList = Arrays.asList(checkFrom);
|
|
|
|
+ if (!fromList.contains(from)) {
|
|
|
|
+ log.error("from: {}", from);
|
|
|
|
+ return Result.failure("非法用户");
|
|
|
|
+ }
|
|
|
|
+
|
|
// 1.获取用户
|
|
// 1.获取用户
|
|
SysUserEntity entity = userService.findByUserName(param.getUserName());
|
|
SysUserEntity entity = userService.findByUserName(param.getUserName());
|
|
if (entity == null){
|
|
if (entity == null){
|
|
@@ -76,15 +87,14 @@ public class IndexController {
|
|
return Result.failure("用户不存在");
|
|
return Result.failure("用户不存在");
|
|
}
|
|
}
|
|
|
|
|
|
-// String from = param.getFrom();
|
|
|
|
-// String role = entity.getRole();
|
|
|
|
-// log.info("role: {}", role);
|
|
|
|
-
|
|
|
|
-// if ("cms".equals(from) && "sys_visitor".equals(role)) {
|
|
|
|
-// log.error("游客不能登录管理后台");
|
|
|
|
-// return Result.failure("非法用户");
|
|
|
|
-// }
|
|
|
|
|
|
+ Long userId = entity.getId();
|
|
|
|
+ Object role = getRole(userId);
|
|
|
|
+ log.info("role: {}", role);
|
|
|
|
|
|
|
|
+ if ("cms".equals(from) && ((Set) role).contains("sys_visitor")) {
|
|
|
|
+ log.error("游客不能登录管理后台");
|
|
|
|
+ return Result.failure("非法用户");
|
|
|
|
+ }
|
|
|
|
|
|
// 验证密码,解密出来是明文密码,在跟输入密码比较
|
|
// 验证密码,解密出来是明文密码,在跟输入密码比较
|
|
boolean decryptName = PasswordUtils.decrypt(entity.getPassword(), param.getPassword(), PasswordUtils.getStaticSalt());
|
|
boolean decryptName = PasswordUtils.decrypt(entity.getPassword(), param.getPassword(), PasswordUtils.getStaticSalt());
|
|
@@ -95,18 +105,16 @@ public class IndexController {
|
|
|
|
|
|
// 检查账号是否启用
|
|
// 检查账号是否启用
|
|
if (entity.getIsDisable() != 0) {
|
|
if (entity.getIsDisable() != 0) {
|
|
- log.error("账号已停用: {}", entity.getUserName());
|
|
|
|
- return Result.failure("账号已停用");
|
|
|
|
|
|
+ log.error("此账号已停用: {}", entity.getUserName());
|
|
|
|
+ return Result.failure("此账号已停用");
|
|
}
|
|
}
|
|
|
|
|
|
// 创建新token
|
|
// 创建新token
|
|
- Long userId = entity.getId();
|
|
|
|
HashMap<String, Object> tokenMap = new HashMap<>();
|
|
HashMap<String, Object> tokenMap = new HashMap<>();
|
|
tokenMap.put("userName", entity.getUserName());
|
|
tokenMap.put("userName", entity.getUserName());
|
|
tokenMap.put("id", userId);
|
|
tokenMap.put("id", userId);
|
|
- Object role = getRole(userId);
|
|
|
|
tokenMap.put("role", role);
|
|
tokenMap.put("role", role);
|
|
- // 创建新token
|
|
|
|
|
|
+
|
|
String token = JwtUtil.createJWT(TOKEN_EXPIRE, tokenMap);
|
|
String token = JwtUtil.createJWT(TOKEN_EXPIRE, tokenMap);
|
|
|
|
|
|
|
|
|
|
@@ -121,8 +129,10 @@ public class IndexController {
|
|
saveLog(userId);
|
|
saveLog(userId);
|
|
|
|
|
|
|
|
|
|
- // 更新到 redis, 有效期24h, 旧token无效, 做单用户登录
|
|
|
|
- redisTemplate.opsForValue().set(configConstant.redisPrefix + token, token, Long.parseLong("23"), TimeUnit.HOURS);
|
|
|
|
|
|
+ // 更新到 redis, 有效期24h, 旧token无效, 做单用户登录 86400s-> 24H
|
|
|
|
+// redisTemplate.opsForValue().set(configConstant.redisPrefix + token, token, Long.parseLong("23"), TimeUnit.HOURS);
|
|
|
|
+
|
|
|
|
+ redisUtil.set(configConstant.redisPrefix + token, token, 86400);
|
|
|
|
|
|
|
|
|
|
return Result.success(result);
|
|
return Result.success(result);
|
|
@@ -136,7 +146,8 @@ public class IndexController {
|
|
if (StringUtils.isBlank(token)) {
|
|
if (StringUtils.isBlank(token)) {
|
|
log.info("token is null");
|
|
log.info("token is null");
|
|
}
|
|
}
|
|
- redisTemplate.delete(configConstant.redisPrefix + token);
|
|
|
|
|
|
+// redisTemplate.delete(configConstant.redisPrefix + token);
|
|
|
|
+ redisUtil.del(configConstant.redisPrefix + token);
|
|
return Result.success();
|
|
return Result.success();
|
|
}
|
|
}
|
|
|
|
|