/** * @inheritdoc */ public function afterAction($action, $result) { $result = parent::afterAction($action, $result); if (in_array($action->id, ['delete', 'verify', 'activate', 'disable'])) { if (!isset($_GET['ajax'])) { return $this->redirect(isset($_REQUEST['returnUrl']) ? $_REQUEST['returnUrl'] : ['index']); } } return $result; }
/** * Redirect user depending on whether is he logged in or not. * Performs additional authorization checks. * @param Action $action the action to be executed. * @return boolean whether the action should continue to be executed. */ public function beforeAction($action) { if (!parent::beforeAction($action)) { return false; } switch ($action->id) { case 'index': case 'profile': case 'profilePicture': if (Yii::$app->user->isGuest) { $this->redirect(['login']); return false; } break; case 'login': case 'recovery': if ($action->id === 'recovery' && !$this->module->recoveryEnabled) { throw new AccessDeniedHttpException(Yii::t('usr', 'Password recovery has not been enabled.')); } if (!Yii::$app->user->isGuest) { $this->goBack(); return false; } break; case 'register': if (!$this->module->registrationEnabled) { throw new AccessDeniedHttpException(Yii::t('usr', 'Registration has not been enabled.')); } if (!Yii::$app->user->isGuest) { $this->redirect(['profile']); return false; } break; case 'verify': if (!isset($_GET['activationKey'])) { throw new BadRequestHttpException(Yii::t('usr', 'Activation key is missing.')); } break; } return true; }