refactor: 优化后台判断是否登陆的逻辑
This commit is contained in:
parent
49df25ba27
commit
4a503ca322
|
@ -24,11 +24,11 @@ import org.apache.shiro.SecurityUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.session.data.redis.RedisIndexedSessionRepository;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -46,11 +46,14 @@ public class LoginController {
|
||||||
private String serviceId;
|
private String serviceId;
|
||||||
@Value("${server.port}")
|
@Value("${server.port}")
|
||||||
private Integer port;
|
private Integer port;
|
||||||
|
@Resource
|
||||||
|
private RedisIndexedSessionRepository redisIndexedSessionRepository;
|
||||||
|
|
||||||
|
|
||||||
@GetMapping(value = "/is-login")
|
@GetMapping(value = "/is-login")
|
||||||
public ResultHolder isLogin(HttpSession session) throws Exception {
|
public ResultHolder isLogin(@RequestHeader(name = SessionConstants.HEADER_TOKEN, required = false) String sessionId) throws Exception {
|
||||||
RsaKey rsaKey = RsaUtil.getRsaKey();
|
RsaKey rsaKey = RsaUtil.getRsaKey();
|
||||||
Object user = session.getAttribute("user");
|
Object user = redisIndexedSessionRepository.getSessionRedisOperations().opsForHash().get("spring:session:sessions:" + sessionId, "sessionAttr:user");
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
UserDTO userDTO = baseUserService.getUserDTO((String) MethodUtils.invokeMethod(user, "getId"));
|
UserDTO userDTO = baseUserService.getUserDTO((String) MethodUtils.invokeMethod(user, "getId"));
|
||||||
if (StringUtils.isBlank(userDTO.getLanguage())) {
|
if (StringUtils.isBlank(userDTO.getLanguage())) {
|
||||||
|
|
Loading…
Reference in New Issue