Commit 0ffdb7f962856fa16d98266160947b1d42d6397b
1 parent
fd14e3ba
Merge branch 'master' of gitlab.artweb.com.ua:yarik.nechyporuk/artbox-core
# Conflicts: # behaviors/LanguageBehavior.php # components/LanguageRequest.php # components/LanguageUrlManager.php # controllers/SettingsController.php # language_instruction.txt # models/Feedback.php # models/FeedbackSearch.php # models/Language.php # models/Page.php # models/PageLang.php # models/PageSearch.php # models/User.php # widgets/LanguageForm.php # widgets/LanguagePicker.php # widgets/views/language_form_frame.php # widgets/views/view.php
Showing
13 changed files
with
133 additions
and
290 deletions
Show diff stats
backend/config/main.php
@@ -14,6 +14,7 @@ | @@ -14,6 +14,7 @@ | ||
14 | 'bootstrap' => [ 'log' ], | 14 | 'bootstrap' => [ 'log' ], |
15 | 'controllerMap' => [ | 15 | 'controllerMap' => [ |
16 | 'settings' => 'artweb\artbox\core\controllers\SettingsController', | 16 | 'settings' => 'artweb\artbox\core\controllers\SettingsController', |
17 | + 'profile' => 'artweb\artbox\core\controllers\ProfileController', | ||
17 | ], | 18 | ], |
18 | 'modules' => [ | 19 | 'modules' => [ |
19 | 'imagemanager' => [ | 20 | 'imagemanager' => [ |
@@ -58,7 +59,7 @@ | @@ -58,7 +59,7 @@ | ||
58 | 'baseUrl' => '/admin', | 59 | 'baseUrl' => '/admin', |
59 | ], | 60 | ], |
60 | 'user' => [ | 61 | 'user' => [ |
61 | - 'identityClass' => 'common\models\User', | 62 | + 'identityClass' => 'artweb\artbox\core\models\User', |
62 | 'enableAutoLogin' => true, | 63 | 'enableAutoLogin' => true, |
63 | 'identityCookie' => [ | 64 | 'identityCookie' => [ |
64 | 'name' => '_identity-backend', | 65 | 'name' => '_identity-backend', |
backend/views/layouts/main.php
@@ -5,11 +5,13 @@ | @@ -5,11 +5,13 @@ | ||
5 | * @var \yii\web\View $this | 5 | * @var \yii\web\View $this |
6 | */ | 6 | */ |
7 | 7 | ||
8 | + use artweb\artbox\core\assets\ArtboxCoreAsset; | ||
8 | use artweb\artbox\core\models\User; | 9 | use artweb\artbox\core\models\User; |
9 | use yii\helpers\Html; | 10 | use yii\helpers\Html; |
10 | use yii\web\View; | 11 | use yii\web\View; |
11 | 12 | ||
12 | - $bundle = yiister\gentelella\assets\Asset::register($this); | 13 | + yiister\gentelella\assets\Asset::register($this); |
14 | + ArtboxCoreAsset::register($this); | ||
13 | /** | 15 | /** |
14 | * @var User $user | 16 | * @var User $user |
15 | */ | 17 | */ |
backend/views/site/index.php
@@ -3,7 +3,6 @@ | @@ -3,7 +3,6 @@ | ||
3 | /* @var $this yii\web\View */ | 3 | /* @var $this yii\web\View */ |
4 | 4 | ||
5 | use artweb\artbox\gentelella\widgets\XPanel; | 5 | use artweb\artbox\gentelella\widgets\XPanel; |
6 | - use yii\bootstrap\Carousel; | ||
7 | use yii\bootstrap\Collapse; | 6 | use yii\bootstrap\Collapse; |
8 | 7 | ||
9 | $this->title = 'My Yii Application'; | 8 | $this->title = 'My Yii Application'; |
@@ -11,31 +10,49 @@ | @@ -11,31 +10,49 @@ | ||
11 | <?php | 10 | <?php |
12 | $panel = XPanel::begin( | 11 | $panel = XPanel::begin( |
13 | [ | 12 | [ |
14 | - 'title' => 'Test', | ||
15 | - 'toolbarLayout' => '{close}{collapse}', | 13 | + 'title' => 'Test', |
14 | + ] | ||
15 | + ); | ||
16 | + echo Collapse::widget( | ||
17 | + [ | ||
18 | + 'items' => [ | ||
19 | + // equivalent to the above | ||
20 | + [ | ||
21 | + 'label' => '<p>Collapsible Group Item #1</p>', | ||
22 | + 'content' => 'Anim pariatur cliche...', | ||
23 | + // open its content by default | ||
24 | + 'contentOptions' => [ 'class' => 'in' ], | ||
25 | + ], | ||
26 | + // another group item | ||
27 | + [ | ||
28 | + 'label' => 'Collapsible Group Item #1', | ||
29 | + 'content' => 'Anim pariatur cliche...', | ||
30 | + ], | ||
31 | + // if you want to swap out .panel-body with .list-group, you may use the following | ||
32 | + [ | ||
33 | + 'label' => 'Collapsible Group Item #1', | ||
34 | + 'content' => [ | ||
35 | + 'Anim pariatur cliche...', | ||
36 | + 'Anim pariatur cliche...', | ||
37 | + ], | ||
38 | + 'footer' => 'Footer' | ||
39 | + // the footer label in list-group | ||
40 | + ], | ||
41 | + [ | ||
42 | + 'label' => 'Collapsible Group Item #1', | ||
43 | + 'content' => [ | ||
44 | + 'Anim pariatur cliche...', | ||
45 | + 'Anim pariatur cliche...', | ||
46 | + ], | ||
47 | + 'footer' => 'Footer', | ||
48 | + // the footer label in list-group | ||
49 | + ], | ||
50 | + ], | ||
51 | + 'options' => [ | ||
52 | + 'class' => 'accordion', | ||
53 | + ], | ||
54 | + 'encodeLabels' => false, | ||
16 | ] | 55 | ] |
17 | ); | 56 | ); |
18 | - echo "Velox nuclear vexatum iaceres ducunt ad eleates."; | ||
19 | $panel::end(); | 57 | $panel::end(); |
20 | -?> | ||
21 | -<div class="site-index"> | ||
22 | - <div class="x_panel"> | ||
23 | - <div class="x_title"> | ||
24 | - <h2>Test</h2> | ||
25 | - <ul class="nav navbar-right panel_toolbox"> | ||
26 | - <li> | ||
27 | - <a class="collapse-link"> | ||
28 | - <i class="fa fa-chevron-up"></i> | ||
29 | - </a> | ||
30 | - </li> | ||
31 | - <li> | ||
32 | - <a class="close-link"> | ||
33 | - <i class="fa fa-close"></i> | ||
34 | - </a> | ||
35 | - </li> | ||
36 | - </ul> | ||
37 | - <div class="clearfix"></div> | ||
38 | - </div> | ||
39 | - <div class="x_content">Velox nuclear vexatum iaceres ducunt ad eleates.</div> | ||
40 | - </div> | ||
41 | -</div> | 58 | +?> |
42 | \ No newline at end of file | 59 | \ No newline at end of file |
@@ -2,8 +2,8 @@ | @@ -2,8 +2,8 @@ | ||
2 | 2 | ||
3 | return [ | 3 | return [ |
4 | 1 => [ | 4 | 1 => [ |
5 | - 'id' => '1', | ||
6 | - 'name' => 'Admin', | 5 | + 'id' => '1', |
6 | + 'name' => 'Admin321', | ||
7 | 'description' => 'Site administrator', | 7 | 'description' => 'Site administrator', |
8 | ], | 8 | ], |
9 | ]; | 9 | ]; |
10 | \ No newline at end of file | 10 | \ No newline at end of file |
common/models/LoginForm.php
1 | <?php | 1 | <?php |
2 | -namespace common\models; | ||
3 | - | ||
4 | -use Yii; | ||
5 | -use yii\base\Model; | ||
6 | - | ||
7 | -/** | ||
8 | - * Login form | ||
9 | - */ | ||
10 | -class LoginForm extends Model | ||
11 | -{ | ||
12 | - public $username; | ||
13 | - public $password; | ||
14 | - public $rememberMe = true; | ||
15 | - | ||
16 | - private $_user; | ||
17 | - | ||
18 | - | 2 | + namespace common\models; |
3 | + | ||
4 | + use artweb\artbox\core\models\User; | ||
5 | + use Yii; | ||
6 | + use yii\base\Model; | ||
7 | + | ||
19 | /** | 8 | /** |
20 | - * @inheritdoc | 9 | + * Login form |
21 | */ | 10 | */ |
22 | - public function rules() | 11 | + class LoginForm extends Model |
23 | { | 12 | { |
24 | - return [ | ||
25 | - // username and password are both required | ||
26 | - [['username', 'password'], 'required'], | ||
27 | - // rememberMe must be a boolean value | ||
28 | - ['rememberMe', 'boolean'], | ||
29 | - // password is validated by validatePassword() | ||
30 | - ['password', 'validatePassword'], | ||
31 | - ]; | ||
32 | - } | ||
33 | - | ||
34 | - /** | ||
35 | - * Validates the password. | ||
36 | - * This method serves as the inline validation for password. | ||
37 | - * | ||
38 | - * @param string $attribute the attribute currently being validated | ||
39 | - * @param array $params the additional name-value pairs given in the rule | ||
40 | - */ | ||
41 | - public function validatePassword($attribute, $params) | ||
42 | - { | ||
43 | - if (!$this->hasErrors()) { | ||
44 | - $user = $this->getUser(); | ||
45 | - if (!$user || !$user->validatePassword($this->password)) { | ||
46 | - $this->addError($attribute, 'Incorrect username or password.'); | 13 | + public $username; |
14 | + public $password; | ||
15 | + public $rememberMe = true; | ||
16 | + | ||
17 | + private $_user; | ||
18 | + | ||
19 | + /** | ||
20 | + * @inheritdoc | ||
21 | + */ | ||
22 | + public function rules() | ||
23 | + { | ||
24 | + return [ | ||
25 | + // username and password are both required | ||
26 | + [ | ||
27 | + [ | ||
28 | + 'username', | ||
29 | + 'password', | ||
30 | + ], | ||
31 | + 'required', | ||
32 | + ], | ||
33 | + // rememberMe must be a boolean value | ||
34 | + [ | ||
35 | + 'rememberMe', | ||
36 | + 'boolean', | ||
37 | + ], | ||
38 | + // password is validated by validatePassword() | ||
39 | + [ | ||
40 | + 'password', | ||
41 | + 'validatePassword', | ||
42 | + ], | ||
43 | + ]; | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * Validates the password. | ||
48 | + * This method serves as the inline validation for password. | ||
49 | + * | ||
50 | + * @param string $attribute the attribute currently being validated | ||
51 | + * @param array $params the additional name-value pairs given in the rule | ||
52 | + */ | ||
53 | + public function validatePassword($attribute, $params) | ||
54 | + { | ||
55 | + if (!$this->hasErrors()) { | ||
56 | + $user = $this->getUser(); | ||
57 | + if (!$user || !$user->validatePassword($this->password)) { | ||
58 | + $this->addError($attribute, 'Incorrect username or password.'); | ||
59 | + } | ||
47 | } | 60 | } |
48 | } | 61 | } |
49 | - } | ||
50 | - | ||
51 | - /** | ||
52 | - * Logs in a user using the provided username and password. | ||
53 | - * | ||
54 | - * @return bool whether the user is logged in successfully | ||
55 | - */ | ||
56 | - public function login() | ||
57 | - { | ||
58 | - if ($this->validate()) { | ||
59 | - return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0); | ||
60 | - } else { | ||
61 | - return false; | 62 | + |
63 | + /** | ||
64 | + * Logs in a user using the provided username and password. | ||
65 | + * | ||
66 | + * @return bool whether the user is logged in successfully | ||
67 | + */ | ||
68 | + public function login() | ||
69 | + { | ||
70 | + if ($this->validate()) { | ||
71 | + return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0); | ||
72 | + } else { | ||
73 | + return false; | ||
74 | + } | ||
62 | } | 75 | } |
63 | - } | ||
64 | - | ||
65 | - /** | ||
66 | - * Finds user by [[username]] | ||
67 | - * | ||
68 | - * @return User|null | ||
69 | - */ | ||
70 | - protected function getUser() | ||
71 | - { | ||
72 | - if ($this->_user === null) { | ||
73 | - $this->_user = User::findByUsername($this->username); | 76 | + |
77 | + /** | ||
78 | + * Finds user by [[username]] | ||
79 | + * | ||
80 | + * @return User|null | ||
81 | + */ | ||
82 | + protected function getUser() | ||
83 | + { | ||
84 | + if ($this->_user === null) { | ||
85 | + $this->_user = User::findByUsername($this->username); | ||
86 | + } | ||
87 | + | ||
88 | + return $this->_user; | ||
74 | } | 89 | } |
75 | - | ||
76 | - return $this->_user; | ||
77 | } | 90 | } |
78 | -} |
common/models/User.php deleted
1 | -<?php | ||
2 | -namespace common\models; | ||
3 | - | ||
4 | -use Yii; | ||
5 | -use yii\base\NotSupportedException; | ||
6 | -use yii\behaviors\TimestampBehavior; | ||
7 | -use yii\db\ActiveRecord; | ||
8 | -use yii\web\IdentityInterface; | ||
9 | - | ||
10 | -/** | ||
11 | - * User model | ||
12 | - * | ||
13 | - * @property integer $id | ||
14 | - * @property string $username | ||
15 | - * @property string $password_hash | ||
16 | - * @property string $password_reset_token | ||
17 | - * @property string $email | ||
18 | - * @property string $auth_key | ||
19 | - * @property integer $status | ||
20 | - * @property integer $created_at | ||
21 | - * @property integer $updated_at | ||
22 | - * @property string $password write-only password | ||
23 | - */ | ||
24 | -class User extends ActiveRecord implements IdentityInterface | ||
25 | -{ | ||
26 | - const STATUS_DELETED = 0; | ||
27 | - const STATUS_ACTIVE = 10; | ||
28 | - | ||
29 | - | ||
30 | - /** | ||
31 | - * @inheritdoc | ||
32 | - */ | ||
33 | - public static function tableName() | ||
34 | - { | ||
35 | - return '{{%user}}'; | ||
36 | - } | ||
37 | - | ||
38 | - /** | ||
39 | - * @inheritdoc | ||
40 | - */ | ||
41 | - public function behaviors() | ||
42 | - { | ||
43 | - return [ | ||
44 | - TimestampBehavior::className(), | ||
45 | - ]; | ||
46 | - } | ||
47 | - | ||
48 | - /** | ||
49 | - * @inheritdoc | ||
50 | - */ | ||
51 | - public function rules() | ||
52 | - { | ||
53 | - return [ | ||
54 | - ['status', 'default', 'value' => self::STATUS_ACTIVE], | ||
55 | - ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]], | ||
56 | - ]; | ||
57 | - } | ||
58 | - | ||
59 | - /** | ||
60 | - * @inheritdoc | ||
61 | - */ | ||
62 | - public static function findIdentity($id) | ||
63 | - { | ||
64 | - return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]); | ||
65 | - } | ||
66 | - | ||
67 | - /** | ||
68 | - * @inheritdoc | ||
69 | - */ | ||
70 | - public static function findIdentityByAccessToken($token, $type = null) | ||
71 | - { | ||
72 | - throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.'); | ||
73 | - } | ||
74 | - | ||
75 | - /** | ||
76 | - * Finds user by username | ||
77 | - * | ||
78 | - * @param string $username | ||
79 | - * @return static|null | ||
80 | - */ | ||
81 | - public static function findByUsername($username) | ||
82 | - { | ||
83 | - return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]); | ||
84 | - } | ||
85 | - | ||
86 | - /** | ||
87 | - * Finds user by password reset token | ||
88 | - * | ||
89 | - * @param string $token password reset token | ||
90 | - * @return static|null | ||
91 | - */ | ||
92 | - public static function findByPasswordResetToken($token) | ||
93 | - { | ||
94 | - if (!static::isPasswordResetTokenValid($token)) { | ||
95 | - return null; | ||
96 | - } | ||
97 | - | ||
98 | - return static::findOne([ | ||
99 | - 'password_reset_token' => $token, | ||
100 | - 'status' => self::STATUS_ACTIVE, | ||
101 | - ]); | ||
102 | - } | ||
103 | - | ||
104 | - /** | ||
105 | - * Finds out if password reset token is valid | ||
106 | - * | ||
107 | - * @param string $token password reset token | ||
108 | - * @return bool | ||
109 | - */ | ||
110 | - public static function isPasswordResetTokenValid($token) | ||
111 | - { | ||
112 | - if (empty($token)) { | ||
113 | - return false; | ||
114 | - } | ||
115 | - | ||
116 | - $timestamp = (int) substr($token, strrpos($token, '_') + 1); | ||
117 | - $expire = Yii::$app->params['user.passwordResetTokenExpire']; | ||
118 | - return $timestamp + $expire >= time(); | ||
119 | - } | ||
120 | - | ||
121 | - /** | ||
122 | - * @inheritdoc | ||
123 | - */ | ||
124 | - public function getId() | ||
125 | - { | ||
126 | - return $this->getPrimaryKey(); | ||
127 | - } | ||
128 | - | ||
129 | - /** | ||
130 | - * @inheritdoc | ||
131 | - */ | ||
132 | - public function getAuthKey() | ||
133 | - { | ||
134 | - return $this->auth_key; | ||
135 | - } | ||
136 | - | ||
137 | - /** | ||
138 | - * @inheritdoc | ||
139 | - */ | ||
140 | - public function validateAuthKey($authKey) | ||
141 | - { | ||
142 | - return $this->getAuthKey() === $authKey; | ||
143 | - } | ||
144 | - | ||
145 | - /** | ||
146 | - * Validates password | ||
147 | - * | ||
148 | - * @param string $password password to validate | ||
149 | - * @return bool if password provided is valid for current user | ||
150 | - */ | ||
151 | - public function validatePassword($password) | ||
152 | - { | ||
153 | - return Yii::$app->security->validatePassword($password, $this->password_hash); | ||
154 | - } | ||
155 | - | ||
156 | - /** | ||
157 | - * Generates password hash from password and sets it to the model | ||
158 | - * | ||
159 | - * @param string $password | ||
160 | - */ | ||
161 | - public function setPassword($password) | ||
162 | - { | ||
163 | - $this->password_hash = Yii::$app->security->generatePasswordHash($password); | ||
164 | - } | ||
165 | - | ||
166 | - /** | ||
167 | - * Generates "remember me" authentication key | ||
168 | - */ | ||
169 | - public function generateAuthKey() | ||
170 | - { | ||
171 | - $this->auth_key = Yii::$app->security->generateRandomString(); | ||
172 | - } | ||
173 | - | ||
174 | - /** | ||
175 | - * Generates new password reset token | ||
176 | - */ | ||
177 | - public function generatePasswordResetToken() | ||
178 | - { | ||
179 | - $this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time(); | ||
180 | - } | ||
181 | - | ||
182 | - /** | ||
183 | - * Removes password reset token | ||
184 | - */ | ||
185 | - public function removePasswordResetToken() | ||
186 | - { | ||
187 | - $this->password_reset_token = null; | ||
188 | - } | ||
189 | -} |
console/controllers/CreateController.php