OEModule\PASAPI\controllers\V1Controller::beforeAction PHP Method

beforeAction() public method

public beforeAction ( CAction $action ) : boolean
$action CAction
return boolean
    public function beforeAction($action)
    {
        foreach (\Yii::app()->request->preferredAcceptTypes as $type) {
            if ($type['baseType'] == 'xml' || $type['subType'] == 'xml' || $type['subType'] == '*') {
                $this->output_format = 'xml';
                break;
            } else {
                $this->output_format = $type['baseType'];
            }
        }
        if (!in_array($this->output_format, static::$supported_formats)) {
            $this->sendResponse(406, 'PASAPI only supports ' . implode(',', static::$supported_formats));
        }
        if (!isset($_SERVER['PHP_AUTH_USER'])) {
            $this->sendResponse(401);
        }
        $identity = new UserIdentity($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
        if (!$identity->authenticate()) {
            $this->sendResponse(401);
        }
        \Yii::app()->user->login($identity);
        if (!\Yii::app()->user->checkAccess('OprnApi')) {
            $this->sendResponse(403);
        }
        return parent::beforeAction($action);
    }