/**
  * @inheritDoc
  */
 public function beforeAction($action)
 {
     if (self::getAdminModule()->allowLoginViaToken == false) {
         throw new NotFoundHttpException();
     }
     return parent::beforeAction($action);
 }
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         /** validate user token here */
         return true;
     }
     return false;
 }
Пример #3
0
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         $headers = Yii::$app->request->headers;
         $this->client = Client::findOne(['app_id' => $headers['app-id']]);
         return true;
     }
 }
 public function beforeAction($action)
 {
     if (!\Yii::$app->request->getIsAjax()) {
         \Yii::$app->user->enableSession = false;
         \Yii::$app->session->destroy();
     }
     return parent::beforeAction($action);
 }
Пример #5
0
 public function beforeAction($action)
 {
     \Yii::$app->response->on(Response::EVENT_BEFORE_SEND, [$this, 'modifyResponse']);
     if (!parent::beforeAction($action)) {
         return false;
     }
     return true;
     // or false to not run the action
 }
Пример #6
0
 /**
  * This method is used to valide the user's authority with token.
  * This method is invoked right before an action is executed.
  *
  * The method will trigger the [[EVENT_BEFORE_ACTION]] event. The return value of the method
  * will determine whether the action should continue to run.
  *
  * If you override this method, your code should look like the following:
  *
  * ```php
  * public function beforeAction($action)
  * {
  *     if (parent::beforeAction($action)) {
  *         // your custom code here
  *         return true;  // or false if needed
  *     } else {
  *         return false;
  *     }
  * }
  * ```
  *
  * @param Action $action the action to be executed.
  * @return boolean whether the action should continue to run.
  * @author Harry Sun
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         $this->attachBehavior('ControllerBehavior', new ControllerBehavior());
         $token = $this->getAccessToken();
         return $this->checkAuth($this->module, $token);
     }
     throw new HttpException(400, "Fail to resolve the action.");
 }
Пример #7
0
 /**
  * Makes necessary preparation before the action. In this case it sets up the appropriate response format
  *
  * @param \yii\base\Action $action
  *
  * @return bool
  * @throws \yii\web\BadRequestHttpException
  */
 function beforeAction($action)
 {
     /** @noinspection PhpUndefinedFieldInspection */
     if (Yii::$app->has('api', true) && Yii::$app->api->enableProfiling) {
         Yii::beginProfile($action->uniqueId);
     }
     if (!parent::beforeAction($action) || !$this->checkContentType()) {
         return false;
     }
     return true;
 }
Пример #8
0
 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (!parent::beforeAction($action)) {
         return false;
     }
     // check for CORS preflight OPTIONS. if so, then return false so that it doesn't run
     // the controller action
     // @link https://github.com/yiisoft/yii2/pull/8626/files
     // @link https://github.com/yiisoft/yii2/issues/6254
     if (Yii::$app->request->isOptions) {
         return false;
     }
     return true;
 }