每次刷新页面的时候重新put session user
This commit is contained in:
parent
0065f15f60
commit
302d4ea5a3
|
@ -1,6 +1,8 @@
|
|||
package io.metersphere.controller;
|
||||
|
||||
import io.metersphere.base.domain.UserRole;
|
||||
import io.metersphere.commons.user.SessionUser;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.controller.request.LoginRequest;
|
||||
import io.metersphere.dto.UserDTO;
|
||||
import io.metersphere.i18n.Translator;
|
||||
|
@ -10,7 +12,6 @@ import org.apache.shiro.SecurityUtils;
|
|||
import org.apache.shiro.authc.*;
|
||||
import org.apache.shiro.authz.UnauthorizedException;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -29,7 +30,12 @@ public class LoginController {
|
|||
@GetMapping(value = "/isLogin")
|
||||
public ResultHolder isLogin() {
|
||||
if (SecurityUtils.getSubject().isAuthenticated()) {
|
||||
return ResultHolder.success(LocaleContextHolder.getLocale());
|
||||
// 每次刷新页面时重新 put session user
|
||||
SessionUser user = SessionUtils.getUser();
|
||||
UserDTO userDTO = userService.getUserDTO(user.getId());
|
||||
SessionUser sessionUser = SessionUser.fromUser(userDTO);
|
||||
SessionUtils.putUser(sessionUser);
|
||||
return ResultHolder.success(sessionUser);
|
||||
}
|
||||
return ResultHolder.error("");
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
import MsUser from "./components/common/head/HeaderUser";
|
||||
import MsHeaderOrgWs from "./components/common/head/HeaderOrgWs";
|
||||
import MsLanguageSwitch from "./components/common/head/LanguageSwitch";
|
||||
import {saveLocalStorage} from "../common/js/utils";
|
||||
|
||||
export default {
|
||||
name: 'app',
|
||||
|
@ -35,8 +36,10 @@
|
|||
},
|
||||
beforeCreate() {
|
||||
this.$get("/isLogin").then(response => {
|
||||
if (response.data.success) {
|
||||
this.$setLang(response.data.data);
|
||||
let res = response.data;
|
||||
if (res.success) {
|
||||
this.$setLang(res.data.language);
|
||||
saveLocalStorage(res);
|
||||
this.auth = true;
|
||||
} else {
|
||||
window.location.href = "/login"
|
||||
|
|
Loading…
Reference in New Issue