'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
],
[
'actions' => ['logout', 'index'],
'allow' => true,
'roles' => ['admin'],
],
],
],
'as access' => [
'class' => 'yii\filters\AccessControl',
'except' => ['site/login', 'site/error'],
'rules' => [
[
'allow' => true,
'roles' => ['admin'],
],
],
],
public function actionLogin()
{
if (!Yii::app()->user->isGuest)
{
$role = Yii::app()->user->role;
if ($role)
{
$this->redirect(Yii::app()->params['modules_default_pages'][$role]);
}
}
$model = new LoginForm;
// if it is ajax validation request
if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
// collect user input data
if (isset($_POST['LoginForm']))
{
$model->attributes = $_POST['LoginForm'];
if ($model->validate() && $model->login())
$this->redirect(Yii::app()->user->returnUrl);
}
$this->render('login', array('model' => $model));
}