refactor: 后台重启过后,前端操作页面弹框提示重新登录
This commit is contained in:
parent
9470cec489
commit
0b21fc8e6a
|
@ -2,4 +2,6 @@ package io.metersphere.commons.constants;
|
|||
|
||||
public class SessionConstants {
|
||||
public static final String ATTR_USER = "user";
|
||||
public static final String AUTHENTICATION_STATUS = "Authentication-Status";
|
||||
public static final String AUTHENTICATION_INVALID = "invalid";
|
||||
}
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package io.metersphere.controller;
|
||||
|
||||
import io.metersphere.commons.constants.SessionConstants;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@Controller
|
||||
@RequestMapping
|
||||
public class IndexController {
|
||||
|
@ -15,8 +18,9 @@ public class IndexController {
|
|||
}
|
||||
|
||||
@GetMapping(value = "/login")
|
||||
public String login() {
|
||||
public String login(HttpServletResponse response) {
|
||||
if (SessionUtils.getUser() == null) {
|
||||
response.setHeader(SessionConstants.AUTHENTICATION_STATUS, SessionConstants.AUTHENTICATION_INVALID);
|
||||
return "login.html";
|
||||
} else {
|
||||
return "redirect:/";
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.metersphere.security;
|
||||
|
||||
import io.metersphere.commons.constants.SessionConstants;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
|
@ -31,7 +32,7 @@ public class ApiKeyFilter extends AnonymousFilter {
|
|||
}
|
||||
|
||||
if (!SecurityUtils.getSubject().isAuthenticated()) {
|
||||
((HttpServletResponse) response).setHeader("Authentication-Status", "invalid");
|
||||
((HttpServletResponse) response).setHeader(SessionConstants.AUTHENTICATION_STATUS, SessionConstants.AUTHENTICATION_INVALID);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (ApiKeyHandler.isApiKeyCall(WebUtils.toHttp(request))) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.metersphere.security;
|
||||
|
||||
import io.metersphere.commons.constants.SessionConstants;
|
||||
import io.metersphere.commons.user.SessionUser;
|
||||
import io.metersphere.commons.utils.CodingUtil;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
|
@ -25,7 +26,7 @@ public class CsrfFilter extends AnonymousFilter {
|
|||
HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
|
||||
|
||||
if (!SecurityUtils.getSubject().isAuthenticated()) {
|
||||
((HttpServletResponse) response).setHeader("Authentication-Status", "invalid");
|
||||
((HttpServletResponse) response).setHeader(SessionConstants.AUTHENTICATION_STATUS, SessionConstants.AUTHENTICATION_INVALID);
|
||||
return true;
|
||||
}
|
||||
// api 过来的请求
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {Message, MessageBox} from 'element-ui';
|
||||
import axios from "axios";
|
||||
import i18n from '../../i18n/i18n'
|
||||
import i18n from '../../i18n/i18n';
|
||||
import {TokenKey} from "@/common/js/constants";
|
||||
|
||||
export function registerRequestHeaders() {
|
||||
|
@ -33,7 +33,7 @@ export function login() {
|
|||
callback: () => {
|
||||
axios.get("/signout");
|
||||
localStorage.setItem('Admin-Token', "{}");
|
||||
window.location.href = "/login"
|
||||
window.location.href = "/login";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ export function get(url, success) {
|
|||
}
|
||||
}
|
||||
|
||||
export function post (url, data, success, failure) {
|
||||
export function post(url, data, success, failure) {
|
||||
let result = {loading: true};
|
||||
if (!success) {
|
||||
return axios.post(url, data);
|
||||
|
@ -139,7 +139,7 @@ export function fileUpload(url, file, files, param, success, failure) {
|
|||
if (files) {
|
||||
files.forEach(f => {
|
||||
formData.append("files", f);
|
||||
})
|
||||
});
|
||||
}
|
||||
formData.append('request', new Blob([JSON.stringify(param)], {type: "application/json"}));
|
||||
let axiosRequestConfig = getUploadConfig(url, formData);
|
||||
|
@ -156,15 +156,15 @@ export default {
|
|||
|
||||
if (!axios) {
|
||||
window.console.error('You have to install axios');
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Message) {
|
||||
window.console.error('You have to install Message of ElementUI');
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
let login = login;
|
||||
// let login = login;
|
||||
|
||||
axios.defaults.withCredentials = true;
|
||||
|
||||
|
@ -189,4 +189,4 @@ export default {
|
|||
|
||||
Vue.prototype.$fileUpload = fileUpload;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue