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 @@
  • інтелектуальні права
  • - - вхід - + user->isGuest) { + echo Html::a('вхід', '#', [ + 'class' => 'btn_login', + ]); + } else { + echo Html::a(\Yii::$app->user->identity->username, [ + 'cabinet/index', + ], [ + 'class' => 'btn_login login_user', + ]); + } + ?>
    @@ -95,33 +112,45 @@
    -
    -
    -
    -
    Будь ласка,
    введіть Вашу інформацію нижче
    -
    -
    - - -
    -
    - - -
    -
    - - - - + 'login-form', + ]); + ?> +
    +
    +
    Будь ласка,
    введіть Вашу інформацію нижче
    +
    + field($loginForm, 'username', [ + 'options' => [ + 'style' => 'padding: 0 51px', + 'class' => 'style', + ] + ])->textInput(); + echo $form->field($loginForm, 'password', [ + 'options' => [ + 'style' => 'padding: 0 51px', + 'class' => 'style', + ] + ])->passwordInput(); + ?> +
    + + +
    - + +
    +
    Почати
    diff --git a/frontend/web/js/script.js b/frontend/web/js/script.js index 86aa106..e3d64bd 100755 --- a/frontend/web/js/script.js +++ b/frontend/web/js/script.js @@ -76,6 +76,9 @@ $(document).ready(function(){ function formsHome() { $('.btn_login, .btn_login_2').click(function (e) { + if($(this).hasClass('login_user')) { + return true; + } e.preventDefault() var pos = ($(window).scrollTop())+20 $('#overlay').fadeIn(400, -- libgit2 0.21.4