Commit b6741a9407031a839b8252d55f58599f7ffa3567
1 parent
02aafad3
Login
Showing
5 changed files
with
89 additions
and
31 deletions
Show diff stats
common/models/LoginForm.php
@@ -30,7 +30,15 @@ class LoginForm extends Model | @@ -30,7 +30,15 @@ class LoginForm extends Model | ||
30 | ['password', 'validatePassword'], | 30 | ['password', 'validatePassword'], |
31 | ]; | 31 | ]; |
32 | } | 32 | } |
33 | - | 33 | + |
34 | + public function attributeLabels() | ||
35 | + { | ||
36 | + return [ | ||
37 | + 'username' => 'Логин', | ||
38 | + 'password' => 'Пароль', | ||
39 | + ]; | ||
40 | + } | ||
41 | + | ||
34 | /** | 42 | /** |
35 | * Validates the password. | 43 | * Validates the password. |
36 | * This method serves as the inline validation for password. | 44 | * This method serves as the inline validation for password. |
frontend/controllers/CabinetController.php
@@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
7 | use frontend\models\Report; | 7 | use frontend\models\Report; |
8 | use frontend\models\UserData; | 8 | use frontend\models\UserData; |
9 | use frontend\models\UserPassport; | 9 | use frontend\models\UserPassport; |
10 | + use yii\filters\AccessControl; | ||
10 | use yii\filters\VerbFilter; | 11 | use yii\filters\VerbFilter; |
11 | use yii\web\Controller; | 12 | use yii\web\Controller; |
12 | use yii\web\NotFoundHttpException; | 13 | use yii\web\NotFoundHttpException; |
@@ -32,6 +33,15 @@ | @@ -32,6 +33,15 @@ | ||
32 | 'passport' => [ 'post' ], | 33 | 'passport' => [ 'post' ], |
33 | ], | 34 | ], |
34 | ], | 35 | ], |
36 | + 'access' => [ | ||
37 | + 'class' => AccessControl::className(), | ||
38 | + 'rules' => [ | ||
39 | + [ | ||
40 | + 'allow' => true, | ||
41 | + 'roles' => ['@'], | ||
42 | + ], | ||
43 | + ], | ||
44 | + ], | ||
35 | ]; | 45 | ]; |
36 | } | 46 | } |
37 | 47 | ||
@@ -42,7 +52,6 @@ | @@ -42,7 +52,6 @@ | ||
42 | */ | 52 | */ |
43 | public function actionIndex() | 53 | public function actionIndex() |
44 | { | 54 | { |
45 | - \Yii::$app->user->login(User::findOne(1)); | ||
46 | /** | 55 | /** |
47 | * @var User $user | 56 | * @var User $user |
48 | */ | 57 | */ |
frontend/controllers/SiteController.php
@@ -74,7 +74,16 @@ | @@ -74,7 +74,16 @@ | ||
74 | */ | 74 | */ |
75 | public function actionIndex() | 75 | public function actionIndex() |
76 | { | 76 | { |
77 | - return $this->render('index'); | 77 | + $loginForm = new LoginForm(); |
78 | + if ($loginForm->load(Yii::$app->request->post()) && $loginForm->login()) { | ||
79 | + return $this->redirect([ 'cabinet/index' ]); | ||
80 | + } | ||
81 | + return $this->render( | ||
82 | + 'index', | ||
83 | + [ | ||
84 | + 'loginForm' => $loginForm, | ||
85 | + ] | ||
86 | + ); | ||
78 | } | 87 | } |
79 | 88 | ||
80 | /** | 89 | /** |
frontend/views/site/index.php
1 | <?php | 1 | <?php |
2 | - | ||
3 | -/* @var $this yii\web\View */ | ||
4 | 2 | ||
3 | + /** | ||
4 | + * @var View $this | ||
5 | + * @var LoginForm $loginForm | ||
6 | + */ | ||
7 | + | ||
8 | + use common\models\LoginForm; | ||
9 | + use yii\helpers\Html; | ||
5 | use yii\helpers\Url; | 10 | use yii\helpers\Url; |
11 | + use yii\web\View; | ||
12 | + use yii\widgets\ActiveForm; | ||
6 | 13 | ||
7 | $this->title = 'My Yii Application'; | 14 | $this->title = 'My Yii Application'; |
8 | ?> | 15 | ?> |
@@ -19,9 +26,19 @@ | @@ -19,9 +26,19 @@ | ||
19 | <li><a href="#">інтелектуальні права</a></li> | 26 | <li><a href="#">інтелектуальні права</a></li> |
20 | </ul> | 27 | </ul> |
21 | <div class="login-wrapp"> | 28 | <div class="login-wrapp"> |
22 | - <!--если залогинен добавить класс для ссылки ".login_user"--> | ||
23 | - <a class="btn_login" href="#">вхід</a> | ||
24 | - <!--<a class="btn_login login_user" href="#">mail.mail.mail@gmail.com</a>--> | 29 | + <?php |
30 | + if(\Yii::$app->user->isGuest) { | ||
31 | + echo Html::a('вхід', '#', [ | ||
32 | + 'class' => 'btn_login', | ||
33 | + ]); | ||
34 | + } else { | ||
35 | + echo Html::a(\Yii::$app->user->identity->username, [ | ||
36 | + 'cabinet/index', | ||
37 | + ], [ | ||
38 | + 'class' => 'btn_login login_user', | ||
39 | + ]); | ||
40 | + } | ||
41 | + ?> | ||
25 | </div> | 42 | </div> |
26 | </div> | 43 | </div> |
27 | </div> | 44 | </div> |
@@ -95,33 +112,45 @@ | @@ -95,33 +112,45 @@ | ||
95 | <div id="overlay"></div> | 112 | <div id="overlay"></div> |
96 | <div id="login_form" class="forms_"> | 113 | <div id="login_form" class="forms_"> |
97 | <span id="modal_close"></span> | 114 | <span id="modal_close"></span> |
98 | - <form action="<?php echo Url::to(['/cabinet/index']); ?>"> | ||
99 | - <div class="style bg_form"> | ||
100 | - <div class="" style="width: 420px; margin: 0 auto"> | ||
101 | - <div class="title_reg-form">Будь ласка,<br /> введіть Вашу інформацію нижче</div> | ||
102 | - <div class="style" style="margin-top: 13px;"> | ||
103 | - <div class="style" style="padding: 0 51px"> | ||
104 | - <label for="input-1">Логін</label> | ||
105 | - <input id="input-1" type="text"> | ||
106 | - </div> | ||
107 | - <div class="style" style="padding: 0 51px"> | ||
108 | - <label for="input-2">Пароль</label> | ||
109 | - <input id="input-2" type="password"> | ||
110 | - </div> | ||
111 | - </div> | ||
112 | - | ||
113 | - <div class="style" style="text-align: center; margin-top: 17px;"> | ||
114 | - <a class="btn-recovery" href="#">Забули пароль?</a> | ||
115 | - </div> | ||
116 | - | ||
117 | - <div class="style btn-form-login" style="margin-top: 29px;"> | ||
118 | - <button type="submit">вхід</button> | ||
119 | - </div> | 115 | + <?php |
116 | + $form = ActiveForm::begin([ | ||
117 | + 'id' => 'login-form', | ||
118 | + ]); | ||
119 | + ?> | ||
120 | + <div class="style bg_form"> | ||
121 | + <div class="" style="width: 420px; margin: 0 auto"> | ||
122 | + <div class="title_reg-form">Будь ласка,<br /> введіть Вашу інформацію нижче</div> | ||
123 | + <div class="style" style="margin-top: 13px;"> | ||
124 | + <?php | ||
125 | + echo $form->field($loginForm, 'username', [ | ||
126 | + 'options' => [ | ||
127 | + 'style' => 'padding: 0 51px', | ||
128 | + 'class' => 'style', | ||
129 | + ] | ||
130 | + ])->textInput(); | ||
131 | + echo $form->field($loginForm, 'password', [ | ||
132 | + 'options' => [ | ||
133 | + 'style' => 'padding: 0 51px', | ||
134 | + 'class' => 'style', | ||
135 | + ] | ||
136 | + ])->passwordInput(); | ||
137 | + ?> | ||
138 | + </div> | ||
120 | 139 | ||
140 | + <div class="style" style="text-align: center; margin-top: 17px;"> | ||
141 | + <a class="btn-recovery" href="#">Забули пароль?</a> | ||
142 | + </div> | ||
143 | + | ||
144 | + <div class="style btn-form-login" style="margin-top: 29px;"> | ||
145 | + <button type="submit">вхід</button> | ||
121 | </div> | 146 | </div> |
122 | 147 | ||
123 | </div> | 148 | </div> |
124 | - </form> | 149 | + |
150 | + </div> | ||
151 | + <?php | ||
152 | + $form::end(); | ||
153 | + ?> | ||
125 | <div class="style" style="background: #fff"> | 154 | <div class="style" style="background: #fff"> |
126 | <div class="style" style="padding: 0 98px;"> | 155 | <div class="style" style="padding: 0 98px;"> |
127 | <div class="title-begin">Почати</div> | 156 | <div class="title-begin">Почати</div> |
frontend/web/js/script.js
@@ -76,6 +76,9 @@ $(document).ready(function(){ | @@ -76,6 +76,9 @@ $(document).ready(function(){ | ||
76 | 76 | ||
77 | function formsHome() { | 77 | function formsHome() { |
78 | $('.btn_login, .btn_login_2').click(function (e) { | 78 | $('.btn_login, .btn_login_2').click(function (e) { |
79 | + if($(this).hasClass('login_user')) { | ||
80 | + return true; | ||
81 | + } | ||
79 | e.preventDefault() | 82 | e.preventDefault() |
80 | var pos = ($(window).scrollTop())+20 | 83 | var pos = ($(window).scrollTop())+20 |
81 | $('#overlay').fadeIn(400, | 84 | $('#overlay').fadeIn(400, |