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