You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
23
hyhproject/home/behavior/InitConfig.php
Executable file
23
hyhproject/home/behavior/InitConfig.php
Executable file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace wstmart\home\behavior;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 初始化基础数据
|
||||
*/
|
||||
class InitConfig
|
||||
{
|
||||
public function run(&$params){
|
||||
WSTConf('protectedUrl',model('HomeMenus')->getMenusUrl());
|
||||
// 检测手机端访问
|
||||
$request = request();
|
||||
$currModel = $request->module();
|
||||
|
||||
hook('initConfigHook',['getParams'=>input()]);
|
||||
|
||||
if($request->isMobile() && $currModel=='home'){
|
||||
$url = url('mobile/index/index');
|
||||
header("location:$url");
|
||||
die;
|
||||
}
|
||||
}
|
||||
}
|
49
hyhproject/home/behavior/ListenProtectedUrl.php
Executable file
49
hyhproject/home/behavior/ListenProtectedUrl.php
Executable file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace wstmart\home\behavior;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 检测用户有没有登录和访问权限
|
||||
*/
|
||||
class ListenProtectedUrl
|
||||
{
|
||||
public function run(&$params){
|
||||
$request = request();
|
||||
$urls = WSTConf('protectedUrl');
|
||||
$visit = strtolower($request->module()."/".$request->controller()."/".$request->action());
|
||||
|
||||
//受保护资源进来检测身份
|
||||
if(isset($urls[$visit])){
|
||||
$menuType = (int)$urls[$visit];
|
||||
$userType = -1;
|
||||
if((int)session('WST_USER.userId')>0)$userType = 0;
|
||||
//if((int)session('WST_USER.shopId')>0)$userType = 1;
|
||||
if((int)session('WST_USER.userType')>0)$userType = 1;
|
||||
//未登录不允许访问受保护的资源
|
||||
if($userType==-1){
|
||||
if($request->isAjax()){
|
||||
echo json_encode(['status'=>-999,'msg'=>'对不起,您还没有登录,请先登录']);
|
||||
}else{
|
||||
header("Location:".url('home/users/login'));
|
||||
}
|
||||
exit();
|
||||
}
|
||||
//已登录但不是商家 则不允许访问受保护的商家资源
|
||||
if($userType==0 && $menuType==1){
|
||||
if($request->isAjax()){
|
||||
echo json_encode(['status'=>-999,'msg'=>'对不起,您不是商家,请先申请为商家再访问']);
|
||||
}else{
|
||||
header("Location:".url('home/shops/login'));
|
||||
}
|
||||
exit();
|
||||
}
|
||||
//商家角色权限
|
||||
if(((int)session('WST_USER.roleId')>0) && $userType==1 && $menuType==1){
|
||||
$shopMenuUrls = model('HomeMenus')->getShopMenusUrl();
|
||||
if(!in_array($visit,$shopMenuUrls)){
|
||||
header("Location:".url('home/error/index'));
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user