Zhiqim Account(前端账户管理台)是在ZhiqimManager基础上改造成用于前端注册登录的管理系统,增加组织结构和余额,开放注册组织和组织管理员,可以添加组织内的部门和角色和操作员。并增加该管理台上的一些组件,如充值支付等组件。适用于二级代理管理或该大型组织机构
森中灵 最后提交于8月前 整理为组织方式和替换新的jar
ZmrInterceptor.java5KB
/*
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
*
* https://zhiqim.org/project/zhiqim_components/zhiqim_account.htm
*
* Zhiqim Account is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
package org.zhiqim.manager;
import org.zhiqim.httpd.HttpRequest;
import org.zhiqim.httpd.context.ZmlContexts;
import org.zhiqim.httpd.context.core.Interceptor;
import org.zhiqim.kernel.util.Strings;
import org.zhiqim.kernel.util.Urls;
import org.zhiqim.kernel.util.Validates;
import org.zhiqim.manager.dao.ZmrParamDao;
import org.zhiqim.manager.presenter.ZmrPassportPresenter;
/**
* 登录检查
*
* @version v1.0.0 @author zouzhigang 2017-6-28 新建与整理
*/
public class ZmrInterceptor implements Interceptor, ZmrConstants
{
private String mainUrl;
@Override
public void intercept(HttpRequest request) throws Exception
{
if (mainUrl == null)
{//主页地址
this.mainUrl = ZmlContexts.parseZmlContent(request, ZMR_MAIN_URL_DEFAULT);
}
ZmrSessionUser sessionUser = request.getSessionUser(ZmrSessionUser.class);
if (sessionUser == null)
{//未登录,自动登录判断
chkAutoLogin(request);
return;
}
if (_PATH_SERVICE_AJAX_.equals(request.getPathInContext()))
{//AJAX访问
chkAjax(request);
}
else
{//URL访问
chkUrl(request);
}
}
/** 未登录检查自动登录和跳转 */
private void chkAutoLogin(HttpRequest request) throws Exception
{
String isRemember = request.getCookie("isRemember");
String userAccount = request.getCookie("userAccount");
String userPass = request.getCookie("userPass");
if (Validates.isNotEmpty(isRemember) && Validates.isNotEmpty(userAccount) && Validates.isNotEmpty(userPass))
{//勾选了自动登录,session结束后自动登录
request.setParameterOnCNT("isRemember", isRemember);
request.setParameterOnCNT("userAccount", userAccount);
request.setParameterOnCNT("userPass", userPass);
request.setParameterOnCNT("isAuto", "on");
ZmrPassportPresenter.login(request);
return;
}
if (request.isXMLHttpRequest())
{//ajax访问
String url = request.getRequestURI();
String to = Urls.get(url, "path");
request.setRedirect("/login.htm?to="+Urls.encodeUTF8(to));
}
else
{//URL访问
request.setRedirect("/login.htm?to="+Urls.encodeUTF8(request.getRequestURI()));
}
}
/** AJAX访问 */
private void chkAjax(HttpRequest request) throws Exception
{
if (!request.isXMLHttpRequest())
{
request.setResponseError("您闲置太久或未登录,请重新登录后再操作...");
return;
}
ZmrSessionUser sessionUser = request.getSessionUser(ZmrSessionUser.class);
String path = request.getPathInRMI();
if (Validates.isEmpty(path))
{//没有配置权限路径
return;
}
path = ZmlContexts.parseZmlContent(request, path);
if (!sessionUser.hasMenuRule(path))
{//没有权限
request.setResponseError("您没有该权限,请与管理员联系...");
return;
}
}
/** URL访问 */
private void chkUrl(HttpRequest request)
{
ZmrSessionUser sessionUser = request.getSessionUser(ZmrSessionUser.class);
String path = request.getPathInContext();
if (sessionUser.hasAllRule(path))
{//在所有菜单中的,要检查是否有权限
if (!sessionUser.hasMenuRule(path))
{//没有权限
request.setRedirectTop("/"+request.getContextAttributeString(ZMR_PATH)+"/logout.htm", "您没有该权限,请与管理员联系...");
return;
}
}
if (!ZmrParamDao.isThemeFrame())
{//非框架模式结束检查
return;
}
if (!_GET_.equalsIgnoreCase(request.getMethod()) || !ZMR_TEMPLATE_MAIN.equals(request.getView()))
{//非GET方法和没使用主模板的请求不处理
return;
}
if (!Strings.endsWith(path, ".htm") && !Strings.endsWith(path, ".zml"))
{//不是.htm/.zml结尾的不处理
return;
}
if (mainUrl.equals(path) || "/manager/welcome.htm".equals(path))
{//主页不处理
return;
}
//其他认为是内部页,设置到会话中,以便F5刷新恢复
sessionUser.setIncludeUrl(request.getRequestURI());
}
}