Skip to content

Commit

Permalink
fixed: #33
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizzercn committed Aug 26, 2016
1 parent 8b1a78a commit ae11829
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/main/java/cn/wizzer/common/processor/NutShiroProcessor.java
Expand Up @@ -6,6 +6,7 @@
import org.nutz.integration.shiro.NutShiro;
import org.nutz.integration.shiro.NutShiroInterceptor;
import org.nutz.integration.shiro.NutShiroMethodInterceptor;
import org.nutz.lang.Strings;
import org.nutz.mvc.ActionContext;
import org.nutz.mvc.ActionInfo;
import org.nutz.mvc.NutConfig;
Expand Down Expand Up @@ -68,7 +69,7 @@ protected void whenException(ActionContext ac, Exception e) throws Throwable {
}

protected void whenUnauthenticated(ActionContext ac, UnauthenticatedException e) throws Exception {
if (NutShiro.isAjax(ac.getRequest())) {
if (NutShiro.isAjax(ac.getRequest()) || getContentType(ac).contains("multipart/form-data")) {
ac.getResponse().addHeader("loginStatus", "accessDenied");
NutShiro.rendAjaxResp(ac.getRequest(), ac.getResponse(), Result.error("登录失效"));
} else {
Expand All @@ -77,7 +78,7 @@ protected void whenUnauthenticated(ActionContext ac, UnauthenticatedException e)
}

protected void whenUnauthorized(ActionContext ac, UnauthorizedException e) throws Exception {
if (NutShiro.isAjax(ac.getRequest())) {
if (NutShiro.isAjax(ac.getRequest()) || getContentType(ac).contains("multipart/form-data")) {
ac.getResponse().addHeader("loginStatus", "unauthorized");
NutShiro.rendAjaxResp(ac.getRequest(), ac.getResponse(), Result.error("没有权限"));
} else {
Expand All @@ -86,11 +87,15 @@ protected void whenUnauthorized(ActionContext ac, UnauthorizedException e) throw
}

protected void whenOtherException(ActionContext ac, Exception e) throws Exception {
if (NutShiro.isAjax(ac.getRequest())) {
if (NutShiro.isAjax(ac.getRequest()) || getContentType(ac).contains("multipart/form-data")) {
ac.getResponse().addHeader("loginStatus", "accessDenied");
NutShiro.rendAjaxResp(ac.getRequest(), ac.getResponse(), Result.error("登录失效"));
} else {
new ServerRedirectView(loginUri).render(ac.getRequest(), ac.getResponse(), null);
}
}

private String getContentType(ActionContext ac) {
return Strings.sNull(ac.getRequest().getHeader("Content-Type")).trim().toLowerCase();
}
}
5 changes: 4 additions & 1 deletion src/main/webapp/assets/js/main.js
Expand Up @@ -6,7 +6,10 @@ $.ajaxSetup({
complete: function (XMLHttpRequest, textStatus) {
var sessionstatus = XMLHttpRequest.getResponseHeader('loginStatus'); //通过XMLHttpRequest取得响应头,sessionstatus,
if (sessionstatus == 'accessDenied') {
top.window.location.href = base+ '/private/login';
Toast.error("\u767b\u5f55\u5931\u6548\uff0c\u8bf7\u5237\u65b0\u9875\u9762\u91cd\u65b0\u767b\u5f55");
}
if (sessionstatus == 'unauthorized') {
Toast.error("\u6ca1\u6709\u6743\u9650");
}
}
});
Expand Down

0 comments on commit ae11829

Please sign in to comment.