/** * Logs in the user if his profile is activated, * if not, displays standard error message. * * @return string|\yii\web\Response */ public function actionLogin() { if (!Yii::$app->user->isGuest) { return $this->goHome(); } // get setting value for 'Login With Email' $lwe = Yii::$app->params['LoginWithEmail']; // if "login with email" is true we instantiate LoginForm in "lwe" scenario $lwe ? $model = new LoginForm(['scenario' => 'LoginWithEmail']) : ($model = new LoginForm()); // everything went fine, log in the user if ($model->load(Yii::$app->request->post()) && $model->login()) { AccessControl::checkRoleAssignment(); return $this->goBack(); } else { return $this->render('login', ['model' => $model]); } }
/** * Logs in the user if his profile is activated, * if not, displays appropriate message. * * @return string|\yii\web\Response */ public function actionLogin() { if (!Yii::$app->user->isGuest) { return $this->goHome(); } // get setting value for 'Login With Email' $lwe = Yii::$app->params['LoginWithEmail']; // if 'LoginWithEmail' value is 'true' we instantiate LoginForm in 'LoginWithEmail' scenario $model = $lwe ? new LoginForm(['scenario' => 'LoginWithEmail']) : new LoginForm(); // now we can try to log in the user if ($model->load(Yii::$app->request->post()) && $model->login()) { AccessControl::checkRoleAssignment(); return $this->goBack(); } else { if ($model->notActivated()) { // if his profile is not activated, he will have to activate it first AppHelper::showErrorMessage(Yii::t('frontend-profile', 'You have to activate your profile first. Please check your email.')); return $this->refresh(); } else { return $this->render('login', ['model' => $model]); } } }
public function behaviors() { return ['access' => ['class' => AccessControl::className(), 'rules' => [['allow' => true, 'roles' => [AccessControl::ROLE_ADMIN]]]]]; }
/** * Returns a list of behaviors that this component should behave as. * Here we use RBAC in combination with AccessControl filter. * * @return array */ public function behaviors() { return ['access' => ['class' => AccessControl::className(), 'rules' => [['allow' => true, 'roles' => [AccessControl::ROLE_ADMIN]], ['controllers' => ['backend/index'], 'actions' => ['login', 'error'], 'allow' => true], ['controllers' => ['backend/index'], 'actions' => ['logout'], 'allow' => true, 'roles' => ['@']], ['controllers' => ['backend/index'], 'allow' => true, 'roles' => [AccessControl::ROLE_ADMIN]], ['controllers' => ['backend/user'], 'allow' => true, 'roles' => [AccessControl::ROLE_ADMIN]], []]], 'verbs' => ['class' => VerbFilter::className(), 'actions' => ['delete' => ['POST'], 'logout' => ['POST']]]]; // return }
public function behaviors() { return ArrayHelper::merge(parent::behaviors(), ['access' => ['class' => AccessControl::className(), 'rules' => [['allow' => true, 'roles' => [AccessControl::ROLE_ADMIN]]]]]); }
public function behaviors() { return ['access' => ['class' => AccessControl::className(), 'rules' => [['actions' => ['login', 'error'], 'allow' => true, 'roles' => ['?']], ['allow' => true, 'roles' => [AccessControl::ROLE_ADMIN]]]]]; }
/** * Returns a list of behaviors that this component should behave as. * Here we use RBAC in combination with AccessControl filter. * * @return array */ public function behaviors() { return ['access' => ['class' => AccessControl::className(), 'rules' => [['controllers' => ['site/index'], 'allow' => true], ['allow' => true, 'roles' => [AccessControl::ROLE_ADMIN]], ['controllers' => ['site/article'], 'actions' => ['create', 'update', 'admin', 'delete'], 'allow' => true, 'roles' => [AccessControl::ROLE_EDITOR]], ['controllers' => ['site/article'], 'actions' => ['index', 'view'], 'allow' => true]]], 'verbs' => ['class' => VerbFilter::className(), 'actions' => ['delete' => ['POST'], 'logout' => ['POST']]]]; // return }
<?php // Docs links: // 1) https://github.com/yiisoft/yii2/blob/master/docs/guide/concept-configurations.md // 2) https://github.com/yiisoft/yii2/blob/master/docs/guide/structure-controllers.md#default-controller- use yii\helpers\ArrayHelper; use common\components\log\AppLogger; use common\rbac\AccessControl; $params = ArrayHelper::merge(require __DIR__ . '/../../common/config/params.php', require __DIR__ . '/../../common/config/params-local.php', require __DIR__ . '/params.php', require __DIR__ . '/params-local.php'); $config = ['id' => 'app-backend', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'controllerNamespace' => 'backend\\modules\\backend\\controllers', 'controller' => '@backend/modules/backend/IndexController', 'defaultRoute' => 'backend/index/index', 'layout' => '@backend/layouts/main.php', 'modules' => ['backend' => backend\modules\backend\Module::className(), 'i18n' => ['class' => uran1980\yii\modules\i18n\Module::className(), 'controllerMap' => ['default' => uran1980\yii\modules\i18n\controllers\DefaultController::className()], 'as access' => ['class' => AccessControl::className(), 'rules' => [['controllers' => ['i18n/default'], 'actions' => ['index', 'save', 'update', 'rescan', 'clear-cache', 'delete', 'restore'], 'allow' => true, 'roles' => [AccessControl::ROLE_TRANSLATOR]]]]]], 'components' => ['urlManager' => $params['app.urlManager.localeUrls'], 'urlManagerFrontend' => $params['app.urlManagerFrontend'], 'view' => $params['app.view'], 'user' => ['class' => yii\web\User::className(), 'identityClass' => common\models\identity\UserIdentity::className(), 'enableAutoLogin' => true, 'loginUrl' => '/backend/login'], 'log' => ['traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => ['file' => ['class' => yii\log\FileTarget::className(), 'levels' => ['error', 'warning']], 'dbLogger' => ['class' => common\components\log\AppLoggerDbTarget::className(), 'levels' => ['info', 'error', 'warning'], 'logVars' => ['_GET', '_POST'], 'categories' => [AppLogger::CATEGORY_APPLICATION, AppLogger::CATEGORY_TEST, AppLogger::CATEGORY_BACKEND], 'logTable' => 'log']]], 'errorHandler' => ['class' => yii\web\ErrorHandler::className(), 'errorAction' => 'backend/index/error']], 'params' => $params]; return $config;