예제 #1
0
 /**
  **在请求交由action处理之前,判断用户属性,如果当前用户没有登录,或者登录用户没有管理员权限,那么抛出403异常,即只有管理员才能进入该管理模块.
  * @param \yii\base\Action $action
  * @return bool
  * @throws HttpException
  */
 public function beforeAction($action)
 {
     if (!User::getCurrent() || !Admin::getCurrent()) {
         throw new HttpException(403, 'You are not an admin');
     }
     return parent::beforeAction($action);
 }
예제 #2
0
 public function requireAdmin()
 {
     if (!$this->hasErrors()) {
         $admin = Admin::getCurrent();
         if (!$admin || $admin->is_blocked) {
             $this->addError('username', 'This account is not an admin or has been blocked as admin.');
         }
     }
 }
예제 #3
0
 /**
  **显示主页.
  * @return string content of home page
  */
 public function actionIndex()
 {
     $admin = Admin::getCurrent();
     return $this->render('index', ['admin' => $admin]);
 }