diff --git a/common/models/LoginForm.php b/common/models/LoginForm.php index c4869d4..aaec56f 100755 --- a/common/models/LoginForm.php +++ b/common/models/LoginForm.php @@ -30,7 +30,15 @@ class LoginForm extends Model ['password', 'validatePassword'], ]; } - + + public function attributeLabels() + { + return [ + 'username' => 'Логин', + 'password' => 'Пароль', + ]; + } + /** * Validates the password. * This method serves as the inline validation for password. diff --git a/frontend/controllers/CabinetController.php b/frontend/controllers/CabinetController.php index 60fbf45..b7ab8e2 100755 --- a/frontend/controllers/CabinetController.php +++ b/frontend/controllers/CabinetController.php @@ -7,6 +7,7 @@ use frontend\models\Report; use frontend\models\UserData; use frontend\models\UserPassport; + use yii\filters\AccessControl; use yii\filters\VerbFilter; use yii\web\Controller; use yii\web\NotFoundHttpException; @@ -32,6 +33,15 @@ 'passport' => [ 'post' ], ], ], + 'access' => [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'allow' => true, + 'roles' => ['@'], + ], + ], + ], ]; } @@ -42,7 +52,6 @@ */ public function actionIndex() { - \Yii::$app->user->login(User::findOne(1)); /** * @var User $user */ diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index bcc5e86..9231a9f 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -74,7 +74,16 @@ */ public function actionIndex() { - return $this->render('index'); + $loginForm = new LoginForm(); + if ($loginForm->load(Yii::$app->request->post()) && $loginForm->login()) { + return $this->redirect([ 'cabinet/index' ]); + } + return $this->render( + 'index', + [ + 'loginForm' => $loginForm, + ] + ); } /** diff --git a/frontend/views/site/index.php b/frontend/views/site/index.php index 9a5a553..6fcc0a6 100755 --- a/frontend/views/site/index.php +++ b/frontend/views/site/index.php @@ -1,8 +1,15 @@ title = 'My Yii Application'; ?> @@ -19,9 +26,19 @@