PluginAdminBaseController.php
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +---------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace cmf\controller;
class PluginAdminBaseController extends PluginBaseController
{
// 初始化
protected function initialize()
{
$adminId = cmf_get_current_admin_id();
if (!empty($adminId)) {
if (!$this->checkAccess($adminId)) {
$this->error("您没有访问权限!");
}
} else {
if ($this->request->isAjax()) {
$this->error("您还没有登录!", url("admin/Public/login"));
} else {
header("Location:" . url("admin/Public/login"));
exit();
}
}
}
/**
* 检查后台用户访问权限
* @param int $userId 后台用户id
* @return boolean 检查通过返回true
*/
private function checkAccess($userId)
{
// 如果用户id是1,则无需判断
if ($userId == 1) {
return true;
}
$pluginName = $this->request->param('_plugin');
$controller = $this->request->param('_controller');
$controller = cmf_parse_name($controller, 1);
$action = $this->request->param('_action');
return cmf_auth_check($userId, "plugin/{$pluginName}/$controller/$action");
}
}