colly_wyx
2018-05-03 1237ba717c8e1902662747b94f7d302a6310cb8c
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
//af_Loader::import('/core/BaseController');
/**
 * 后台通用控制器 加了rbac
 * Class AdminCommonController
 */
class System_Controller_Admin extends System_Controller_Base{
 
    public $layout = APP_ROOT.'/modules/Admin/views/layout/adminLayout.phtml';
    public $defaultMsgTemplate = 'common/showmsg.phtml';
    public $config = array();
    public $session = array();
    /**
     * @var boolean 是否开启用户验证 authenticate
     */
    public $doAuth = true;
    /**
     * @var bool 是否检查权限
     */
    public $checkAuthorization = true;
 
    /**
     * @var string 当前请求的权限节点
     */
    public $currentRequest = '';
 
    public function init(){
        $this->session = Yaf_Session::getInstance();
        if(!$this->session->has('user')){
          $this->redirect('/user_login.html');
        }
        //初始化redis
        $this->redis = System_Service_Locator::getInstance()->get('redis');
        if(!$this->redis->exists('modules') ){
          $this->redis->set('modules', $this->getModules());
        }
         //更新角色权限
        if(!$this->redis->exists('role_auth')){
          Util::updateRoleAuth();
        }
        $role_auth = $this->redis->get('role_auth');
        $module_service = new Service_Module();
       // $current_module = $module_service->getModuleInfo(array('module' => strtolower($this->_request->module), 'controller' => strtolower($this->_request->controller), 'action' => strtolower($this->_request->action)));
       // if($current_module){
       //   if(!in_array($current_module['_id'], $role_auth[$this->session['user']['role_id']])){
       //     $this->redirect('/error/show/type/no_auth');
       //   }
      //  }
       // else{
       //    $this->redirect('/error/show/type/not_found');
       // }
        parent::init();
       // $currentRequest = '/' . strtolower( implode('/', [
       ///         $this->_request->module,
       //         $this->_request->controller,
       //         $this->_request->action,
       //     ]) );
       // $this->getView()->currentRequest = $currentRequest;
      //  if($this->checkAuthorization && $this->userInfo){
       //     $rbacManage = \Core\ServiceLocator::getInstance()->get('rbacManage');
      //      if( ! $rbacManage->isAdmin( $this->userInfo['name'] ) ) {
       //         $authInfo = $rbacManage->checkAuthorization($this->userInfo['id'], $currentRequest);
       //         if ($authInfo == false) {
        //            throw new \Exception('没有节点访问权限');
         //       }
       //     }
        //}
    }
 
    public function setLayout($layout = ''){
        $this->layout = $layout;
    }
 
    /**
     * 返回正确提示
     * @param  string  $content [description]
     * @param  boolean $is_json [description]
     * @return [type]           [description]
     */
    public function showSuccess($content = '', $is_json = false){
      return $this->showMessage($content, 200, $is_json);
    }
 
    /**
     * 返回错误信息
     * @param  string  $content [description]
     * @param  integer $code    [description]
     * @param  boolean $is_json [description]
     * @return [type]           [description]
     */
    public function showError($content = '', $code = 400, $is_json = false){
      return $this->showMessage($content, $code, $is_json);
    }
 
    /**
     * 返回信息
     * @param  string  $content [description]
     * @param  integer $code    [description]
     * @param  boolean $is_json [description]
     * @return [type]           [description]
     */
    public function showMessage($content = '', $code = 200, $is_json = false){
      $return_msg = array('code' => $code, 'content' => $content);
      if($is_json){
        $return_msg = json_encode($return_msg);
      }
      return $return_msg;
    }
 
    /**
     * 发送数据
     * @param  array   $arr     [description]
     * @param  boolean $is_json [description]
     * @return [type]           [description]
     */
    public function send($arr = array(), $is_json = true){
      $return_data = $arr;
      if($is_json){
        $return_data = json_encode($arr);
      }
      return $return_data;
    }
 
    /**
     * 向DataTable发送数据
     * @param  [type] $data [description]
     * @return [type]       [description]
     */
    public function sendToDataTable($data){
      return json_encode($data, JSON_UNESCAPED_UNICODE);
    }
 
    /**
     * 获取栏目列表
     * @return [type] [description]
     */
    public function getModules(){
        $this->module_service = new Service_Module();
        return $this->module_service->getModuleList(array(), array(), array('level' => 1));
    }
 
}