Commit 181169e7bbf1f47b346fdf638426d4348e196b3e
Merge branch 'master' of gitlab.artweb.com.ua:root/new_rukzachok
Showing
15 changed files
with
263 additions
and
179 deletions
Show diff stats
backend/controllers/SiteController.php
backend/controllers/UserController.php
... | ... | @@ -5,10 +5,13 @@ namespace backend\controllers; |
5 | 5 | use Yii; |
6 | 6 | use backend\models\User; |
7 | 7 | use backend\models\UserSearch; |
8 | +use yii\filters\AccessControl; | |
8 | 9 | use yii\web\Controller; |
9 | 10 | use yii\web\NotFoundHttpException; |
10 | 11 | use yii\filters\VerbFilter; |
11 | -use developeruz\db_rbac\behaviors\AccessBehavior; | |
12 | +use yii\web\Response; | |
13 | +use yii\widgets\ActiveForm; | |
14 | + | |
12 | 15 | /** |
13 | 16 | * UserController implements the CRUD actions for User model. |
14 | 17 | */ |
... | ... | @@ -19,32 +22,30 @@ class UserController extends Controller |
19 | 22 | */ |
20 | 23 | public function behaviors() |
21 | 24 | { |
25 | + | |
26 | + | |
22 | 27 | return [ |
23 | - 'access'=>[ | |
24 | - 'class' => AccessBehavior::className(), | |
25 | - 'rules' => | |
26 | - ['site' => | |
27 | - [ | |
28 | - [ | |
29 | - 'actions' => ['login', 'error'], | |
30 | - 'allow' => true, | |
31 | - ] | |
32 | - ], | |
33 | - 'user' => | |
34 | - [ | |
35 | - [ | |
36 | - 'actions' => ['index', 'create', 'update'], | |
37 | - 'allow' => true, | |
38 | - ] | |
39 | - ] | |
40 | - ], | |
41 | - ], | |
42 | 28 | 'verbs' => [ |
43 | 29 | 'class' => VerbFilter::className(), |
44 | 30 | 'actions' => [ |
45 | 31 | 'delete' => ['POST'], |
46 | 32 | ], |
47 | 33 | ], |
34 | + 'access' => [ | |
35 | + 'class' => AccessControl::className(), | |
36 | + 'rules' => [ | |
37 | + [ | |
38 | + 'allow' => true, | |
39 | +// 'actions' => ['login', 'signup'], | |
40 | + 'roles' => ['admin'], | |
41 | + ], | |
42 | + [ | |
43 | +// 'allow' => true, | |
44 | +// 'actions' => ['logout'], | |
45 | +// 'roles' => ['@'], | |
46 | + ], | |
47 | + ], | |
48 | + ], | |
48 | 49 | ]; |
49 | 50 | } |
50 | 51 | |
... | ... | @@ -83,8 +84,19 @@ class UserController extends Controller |
83 | 84 | public function actionCreate() |
84 | 85 | { |
85 | 86 | $model = new User(); |
87 | + if (Yii::$app->request->isAjax) { | |
88 | + Yii::$app->response->format = Response::FORMAT_JSON; | |
89 | + $model->load(Yii::$app->request->post()); | |
90 | + return ActiveForm::validate($model); | |
91 | + }else if ($model->load(Yii::$app->request->post()) && $model->validate()) { | |
92 | + $model->save(); | |
93 | + | |
94 | + foreach($model->role as $k => $role){ | |
95 | + $auth = Yii::$app->authManager; | |
96 | + $authorRole = $auth->getRole($role); | |
97 | + $auth->assign($authorRole, $model->id); | |
98 | + } | |
86 | 99 | |
87 | - if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
88 | 100 | return $this->redirect(['view', 'id' => $model->id]); |
89 | 101 | } else { |
90 | 102 | return $this->render('create', [ |
... | ... | @@ -104,6 +116,11 @@ class UserController extends Controller |
104 | 116 | $model = $this->findModel($id); |
105 | 117 | |
106 | 118 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
119 | + | |
120 | + $auth = Yii::$app->authManager; | |
121 | + $authorRole = $auth->getRole('author'); | |
122 | + $auth->assign($authorRole, $model->id); | |
123 | + | |
107 | 124 | return $this->redirect(['view', 'id' => $model->id]); |
108 | 125 | } else { |
109 | 126 | return $this->render('update', [ | ... | ... |
backend/models/User.php
... | ... | @@ -6,8 +6,11 @@ use developeruz\db_rbac\interfaces\UserRbacInterface; |
6 | 6 | use common\models\Share; |
7 | 7 | use common\modules\comment\models\Comment; |
8 | 8 | use common\modules\comment\models\Rating; |
9 | +use yii\base\NotSupportedException; | |
9 | 10 | use Yii; |
10 | - | |
11 | +use yii\behaviors\TimestampBehavior; | |
12 | +use yii\db\ActiveRecord; | |
13 | +use yii\web\IdentityInterface; | |
11 | 14 | /** |
12 | 15 | * This is the model class for table "user". |
13 | 16 | * |
... | ... | @@ -25,8 +28,13 @@ use Yii; |
25 | 28 | * @property Rating[] $ratings |
26 | 29 | * @property Share[] $shares |
27 | 30 | */ |
28 | -class User extends \common\models\User implements UserRbacInterface | |
31 | +class User extends ActiveRecord implements UserRbacInterface, IdentityInterface | |
29 | 32 | { |
33 | + | |
34 | + const STATUS_DELETED = 0; | |
35 | + const STATUS_ACTIVE = 10; | |
36 | + public $password; | |
37 | + | |
30 | 38 | /** |
31 | 39 | * @inheritdoc |
32 | 40 | */ |
... | ... | @@ -41,16 +49,41 @@ class User extends \common\models\User implements UserRbacInterface |
41 | 49 | public function rules() |
42 | 50 | { |
43 | 51 | return [ |
44 | - [['username', 'auth_key', 'password_hash', 'email'], 'required'], | |
52 | + [['username', 'password', 'email'], 'required'], | |
45 | 53 | [['status', 'created_at', 'updated_at'], 'integer'], |
46 | 54 | [['username', 'password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255], |
47 | 55 | [['auth_key'], 'string', 'max' => 32], |
48 | - [['email'], 'unique'], | |
49 | 56 | [['password_reset_token'], 'unique'], |
50 | - [['username'], 'unique'], | |
57 | + ['email', 'unique', 'targetClass' => '\backend\models\User', 'message' => Yii::t('app','message',[ | |
58 | + 'field' => 'Email' | |
59 | + ])], | |
60 | + ]; | |
61 | + } | |
62 | + | |
63 | + | |
64 | + /** | |
65 | + * @inheritdoc | |
66 | + */ | |
67 | + public function behaviors() | |
68 | + { | |
69 | + return [ | |
70 | + TimestampBehavior::className(), | |
71 | + [ | |
72 | + 'class' => 'common\behaviors\ShowImage', | |
73 | + ], | |
51 | 74 | ]; |
52 | 75 | } |
53 | 76 | |
77 | + | |
78 | + public function beforeSave($insert) | |
79 | + { | |
80 | + $this->setPassword($this->password); | |
81 | + $this->generateAuthKey(); | |
82 | + return parent::beforeSave($insert); | |
83 | + } | |
84 | + | |
85 | + | |
86 | + | |
54 | 87 | /** |
55 | 88 | * @inheritdoc |
56 | 89 | */ |
... | ... | @@ -69,6 +102,74 @@ class User extends \common\models\User implements UserRbacInterface |
69 | 102 | ]; |
70 | 103 | } |
71 | 104 | |
105 | + | |
106 | + /** | |
107 | + * Generates "remember me" authentication key | |
108 | + */ | |
109 | + public function generateAuthKey() | |
110 | + { | |
111 | + $this->auth_key = Yii::$app->security->generateRandomString(); | |
112 | + } | |
113 | + | |
114 | + /** | |
115 | + * Generates password hash from password and sets it to the model | |
116 | + * | |
117 | + * @param string $password | |
118 | + */ | |
119 | + public function setPassword($password) | |
120 | + { | |
121 | + $this->password_hash = Yii::$app->security->generatePasswordHash($password); | |
122 | + } | |
123 | + | |
124 | + | |
125 | + | |
126 | + | |
127 | + | |
128 | + public function getRole(){ | |
129 | + return !empty($this->id) ? \Yii::$app->authManager->getRolesByUser($this->id) : ""; | |
130 | + } | |
131 | + | |
132 | + /** | |
133 | + * @inheritdoc | |
134 | + */ | |
135 | + public function getId() | |
136 | + { | |
137 | + return $this->getPrimaryKey(); | |
138 | + } | |
139 | + | |
140 | + /** | |
141 | + * @inheritdoc | |
142 | + */ | |
143 | + public function getAuthKey() | |
144 | + { | |
145 | + return $this->auth_key; | |
146 | + } | |
147 | + | |
148 | + /** | |
149 | + * @inheritdoc | |
150 | + */ | |
151 | + public function validateAuthKey($authKey) | |
152 | + { | |
153 | + return $this->getAuthKey() === $authKey; | |
154 | + } | |
155 | + | |
156 | + | |
157 | + /** | |
158 | + * @inheritdoc | |
159 | + */ | |
160 | + public static function findIdentityByAccessToken($token, $type = null) | |
161 | + { | |
162 | + throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.'); | |
163 | + } | |
164 | + | |
165 | + /** | |
166 | + * @inheritdoc | |
167 | + */ | |
168 | + public static function findIdentity($id) | |
169 | + { | |
170 | + return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]); | |
171 | + } | |
172 | + | |
72 | 173 | /** |
73 | 174 | * @return \yii\db\ActiveQuery |
74 | 175 | */ |
... | ... | @@ -93,19 +194,11 @@ class User extends \common\models\User implements UserRbacInterface |
93 | 194 | return $this->hasMany(Share::className(), ['user_id' => 'id']); |
94 | 195 | } |
95 | 196 | |
96 | - public function getId() | |
97 | - { | |
98 | - return $this->getPrimaryKey(); | |
99 | - } | |
100 | 197 | |
101 | 198 | public function getUserName() |
102 | 199 | { |
103 | 200 | return $this->username; |
104 | 201 | } |
105 | 202 | |
106 | - public static function findIdentity($id) | |
107 | - { | |
108 | - return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]); | |
109 | - } | |
110 | 203 | |
111 | 204 | } | ... | ... |
backend/views/layouts/header.php
... | ... | @@ -6,9 +6,11 @@ |
6 | 6 | use yii\helpers\Html; |
7 | 7 | use yii\bootstrap\Nav; |
8 | 8 | use yii\bootstrap\NavBar; |
9 | +use yii\helpers\Url; | |
9 | 10 | use yii\widgets\Breadcrumbs; |
10 | 11 | use frontend\assets\AppAsset; |
11 | 12 | use common\widgets\Alert; |
13 | +use yii\widgets\Menu; | |
12 | 14 | |
13 | 15 | AppAsset::register($this); |
14 | 16 | ?> |
... | ... | @@ -28,31 +30,6 @@ AppAsset::register($this); |
28 | 30 | </a> |
29 | 31 | |
30 | 32 | <div class="navbar-custom-menu"> |
31 | - <?php | |
32 | - NavBar::begin([ | |
33 | - 'options' => [ | |
34 | - 'class' => 'navbar-inverse navbar-fixed-top', | |
35 | - ], | |
36 | - ]); | |
37 | - if (Yii::$app->user->isGuest) { | |
38 | - $menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']]; | |
39 | - $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']]; | |
40 | - } else { | |
41 | - $menuItems[] = '<li>' | |
42 | - . Html::beginForm(['/site/logout'], 'post') | |
43 | - . Html::submitButton( | |
44 | - 'Logout (' . Yii::$app->user->identity->username . ')', | |
45 | - ['class' => 'btn btn-link'] | |
46 | - ) | |
47 | - . Html::endForm() | |
48 | - . '</li>'; | |
49 | - } | |
50 | - echo Nav::widget([ | |
51 | - 'options' => ['class' => 'navbar-nav navbar-right'], | |
52 | - 'items' => $menuItems, | |
53 | - ]); | |
54 | - NavBar::end(); | |
55 | - ?> | |
56 | 33 | </div> |
57 | 34 | </nav> |
58 | 35 | </header> |
59 | 36 | \ No newline at end of file | ... | ... |
backend/views/layouts/main-sidebar.php
... | ... | @@ -4,70 +4,84 @@ use yii\widgets\Menu; |
4 | 4 | <aside class="main-sidebar"> |
5 | 5 | <!-- sidebar: style can be found in sidebar.less --> |
6 | 6 | <section class="sidebar"> |
7 | - <?= | |
8 | - Menu::widget([ | |
9 | - 'options' => ['class' => 'sidebar-menu'], | |
10 | - 'submenuTemplate' => "\n<ul class='treeview-menu'>\n{items}\n</ul>\n", | |
7 | + <?php | |
8 | + | |
9 | + $items = [ | |
10 | + ['label' => 'Заказы', 'url' => ['/orders/index'], 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-shopping-cart"></i> <span>{label}</span></a>'], | |
11 | + [ | |
12 | + 'label' => 'eCommerce', | |
13 | + 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-barcode"></i> <span>{label}</span></a>', | |
14 | + 'url' => ['/product/manage'], | |
15 | + 'items' => [ | |
16 | + ['label' => 'Товары', 'url' => ['/product/manage']], | |
17 | + ['label' => 'Категории', 'url' => ['/category']], | |
18 | + ['label' => 'Бренды', 'url' => ['/brand']], | |
19 | + ['label' => 'Характеристики', 'url' => ['/rubrication/tax-group']], | |
20 | + ['label' => 'Единицы измерения', 'url' => ['/product/product-unit']], | |
21 | + ['label' => 'Статистика импорта', 'url' => ['/product/manage/import-stat']], | |
22 | + ] | |
23 | + ], | |
24 | + [ | |
25 | + 'label' => 'Слайдер/Банеры', | |
26 | + 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-barcode"></i> <span>{label}</span></a>', | |
27 | + 'items' => [ | |
28 | + ['label' => 'Слайдер', 'url' => ['/slider/index']], | |
29 | + ['label' => 'Банер', 'url' => ['/banner/index']], | |
30 | + ] | |
31 | + ], | |
32 | + [ | |
33 | + 'label' => 'Характеристики', | |
34 | + 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-search"></i> <span>{label}</span></a>', | |
35 | + 'url' => ['/rubrication/tax-group'], | |
36 | + 'items' => [ | |
37 | + ['label' => 'Характеристики', 'url' => ['/rubrication/tax-group']], | |
38 | + ['label' => 'Зависимости', 'url' => ['/relation/manage']] | |
39 | + ] | |
40 | + ], | |
41 | + ['label' => 'Текстовые страницы', 'url' => ['/page/index']], | |
42 | + ['label' => 'Статьи', 'url' => ['/articles/index']], | |
43 | + ['label' => 'Акции', 'url' => ['/event/index']], | |
44 | + [ | |
45 | + 'label' => 'SEO', | |
46 | + 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-search"></i> <span>{label}</span></a>', | |
47 | + 'items' => [ | |
48 | + ['label' => 'URL', 'url' => ['/seo/index']], | |
49 | + ['label' => 'Шаблоны', 'url' => ['/seo-category/index']] | |
50 | + ] | |
51 | + ], | |
52 | + ['label' => 'Фон', 'url' => ['/bg/index']], | |
53 | + ['label' => 'Подписка', 'url' => ['/subscribe/index']], | |
54 | + ['label' => 'Пользователи', 'url' => ['/customer/index']], | |
55 | + ['label' => 'Группы пользователей', 'url' => ['/group/index']], | |
56 | + [ | |
57 | + 'label' => 'Настройка ролей', | |
58 | + 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-search"></i> <span>{label}</span></a>', | |
59 | + 'items' => [ | |
60 | + ['label' => 'Администраторы', 'url' => ['/user/index']], | |
61 | + ['label' => 'управление ролями', 'url' => ['/permit/access/role']], | |
62 | + ['label' => 'управление правами доступа', 'url' => ['/permit/access/permission']] | |
63 | + ] | |
64 | + ], | |
11 | 65 | |
12 | - 'items' => [ | |
13 | - ['label' => 'Заказы', 'url' => ['/orders/index'], 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-shopping-cart"></i> <span>{label}</span></a>'], | |
14 | - [ | |
15 | - 'label' => 'eCommerce', | |
16 | - 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-barcode"></i> <span>{label}</span></a>', | |
17 | - 'url' => ['/product/manage'], | |
18 | - 'items' => [ | |
19 | - ['label' => 'Товары', 'url' => ['/product/manage']], | |
20 | - ['label' => 'Категории', 'url' => ['/category']], | |
21 | - ['label' => 'Бренды', 'url' => ['/brand']], | |
22 | - ['label' => 'Характеристики', 'url' => ['/rubrication/tax-group']], | |
23 | - ['label' => 'Единицы измерения', 'url' => ['/product/product-unit']], | |
24 | - ['label' => 'Статистика импорта', 'url' => ['/product/manage/import-stat']], | |
25 | - ] | |
26 | - ], | |
27 | - [ | |
28 | - 'label' => 'Слайдер/Банеры', | |
29 | - 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-barcode"></i> <span>{label}</span></a>', | |
30 | - 'items' => [ | |
31 | - ['label' => 'Слайдер', 'url' => ['/slider/index']], | |
32 | - ['label' => 'Банер', 'url' => ['/banner/index']], | |
33 | - ] | |
34 | - ], | |
35 | - [ | |
36 | - 'label' => 'Характеристики', | |
37 | - 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-search"></i> <span>{label}</span></a>', | |
38 | - 'url' => ['/rubrication/tax-group'], | |
39 | - 'items' => [ | |
40 | - ['label' => 'Характеристики', 'url' => ['/rubrication/tax-group']], | |
41 | - ['label' => 'Зависимости', 'url' => ['/relation/manage']] | |
42 | - ] | |
43 | - ], | |
44 | - ['label' => 'Текстовые страницы', 'url' => ['/page/index']], | |
45 | - ['label' => 'Статьи', 'url' => ['/articles/index']], | |
46 | - ['label' => 'Акции', 'url' => ['/event/index']], | |
47 | - [ | |
48 | - 'label' => 'SEO', | |
49 | - 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-search"></i> <span>{label}</span></a>', | |
50 | - 'items' => [ | |
51 | - ['label' => 'URL', 'url' => ['/seo/index']], | |
52 | - ['label' => 'Шаблоны', 'url' => ['/seo-category/index']] | |
53 | - ] | |
54 | - ], | |
55 | - ['label' => 'Фон', 'url' => ['/bg/index']], | |
56 | - ['label' => 'Подписка', 'url' => ['/subscribe/index']], | |
57 | - ['label' => 'Пользователи', 'url' => ['/customer/index']], | |
58 | - ['label' => 'Группы пользователей', 'url' => ['/group/index']], | |
59 | - [ | |
60 | - 'label' => 'Настройка ролей', | |
61 | - 'template'=>'<a href="{url}"> <i class="glyphicon glyphicon-search"></i> <span>{label}</span></a>', | |
62 | - 'items' => [ | |
63 | - ['label' => 'Администраторы', 'url' => ['/user/index']], | |
64 | - ['label' => 'управление ролями', 'url' => ['/permit/access/role']], | |
65 | - ['label' => 'управление правами доступа', 'url' => ['/permit/access/permission']] | |
66 | - ] | |
67 | - ], | |
68 | 66 | |
69 | 67 | |
70 | - ], | |
68 | + ]; | |
69 | + | |
70 | + | |
71 | + if (Yii::$app->user->isGuest) { | |
72 | + array_push($items, | |
73 | + ['label' => 'Signup', 'url' => ['/admin/site/signup']], ['label' => 'Login', 'url' => ['/admin/site/login']] | |
74 | + ); | |
75 | + } else { | |
76 | + array_push($items, | |
77 | + ['label' => 'Logout (' . Yii::$app->user->identity->username . ')','url'=>'/admin/site/logout'] | |
78 | + ); | |
79 | + } | |
80 | + echo Menu::widget([ | |
81 | + 'options' => ['class' => 'sidebar-menu'], | |
82 | + 'submenuTemplate' => "\n<ul class='treeview-menu'>\n{items}\n</ul>\n", | |
83 | + | |
84 | + 'items' =>$items, | |
71 | 85 | |
72 | 86 | ]); |
73 | 87 | ?> | ... | ... |
backend/views/user/_form.php
1 | 1 | <?php |
2 | 2 | |
3 | +use kartik\select2\Select2; | |
3 | 4 | use yii\helpers\Html; |
4 | 5 | use yii\widgets\ActiveForm; |
5 | 6 | |
... | ... | @@ -14,19 +15,13 @@ use yii\widgets\ActiveForm; |
14 | 15 | |
15 | 16 | <?= $form->field($model, 'username')->textInput(['maxlength' => true]) ?> |
16 | 17 | |
17 | - <?= $form->field($model, 'auth_key')->textInput(['maxlength' => true]) ?> | |
18 | + <?= $form->field($model, 'password')->textInput(['maxlength' => true]) ?> | |
18 | 19 | |
19 | - <?= $form->field($model, 'password_hash')->textInput(['maxlength' => true]) ?> | |
20 | - | |
21 | - <?= $form->field($model, 'password_reset_token')->textInput(['maxlength' => true]) ?> | |
22 | - | |
23 | - <?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?> | |
24 | - | |
25 | - <?= $form->field($model, 'status')->textInput() ?> | |
20 | + <?= $form->field($model, 'email',['enableAjaxValidation' => true])->textInput(['maxlength' => true]) ?> | |
26 | 21 | |
27 | 22 | |
28 | 23 | <div class="form-group"> |
29 | - <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
24 | + <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
30 | 25 | </div> |
31 | 26 | |
32 | 27 | <?php ActiveForm::end(); ?> | ... | ... |
backend/views/user/_search.php
... | ... | @@ -19,13 +19,7 @@ use yii\widgets\ActiveForm; |
19 | 19 | |
20 | 20 | <?= $form->field($model, 'username') ?> |
21 | 21 | |
22 | - <?= $form->field($model, 'auth_key') ?> | |
23 | - | |
24 | - <?= $form->field($model, 'password_hash') ?> | |
25 | - | |
26 | - <?= $form->field($model, 'password_reset_token') ?> | |
27 | - | |
28 | - <?php // echo $form->field($model, 'email') ?> | |
22 | + <?= $form->field($model, 'email') ?> | |
29 | 23 | |
30 | 24 | <?php // echo $form->field($model, 'status') ?> |
31 | 25 | |
... | ... | @@ -34,8 +28,8 @@ use yii\widgets\ActiveForm; |
34 | 28 | <?php // echo $form->field($model, 'updated_at') ?> |
35 | 29 | |
36 | 30 | <div class="form-group"> |
37 | - <?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?> | |
38 | - <?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?> | |
31 | + <?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?> | |
32 | + <?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?> | |
39 | 33 | </div> |
40 | 34 | |
41 | 35 | <?php ActiveForm::end(); ?> | ... | ... |
backend/views/user/create.php
... | ... | @@ -6,8 +6,8 @@ use yii\helpers\Html; |
6 | 6 | /* @var $this yii\web\View */ |
7 | 7 | /* @var $model backend\models\User */ |
8 | 8 | |
9 | -$this->title = 'Create User'; | |
10 | -$this->params['breadcrumbs'][] = ['label' => 'Users', 'url' => ['index']]; | |
9 | +$this->title = Yii::t('app', 'Create User'); | |
10 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Users'), 'url' => ['index']]; | |
11 | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | 12 | ?> |
13 | 13 | <div class="user-create"> | ... | ... |
backend/views/user/index.php
... | ... | @@ -8,7 +8,7 @@ use yii\helpers\Url; |
8 | 8 | /* @var $searchModel backend\models\UserSearch */ |
9 | 9 | /* @var $dataProvider yii\data\ActiveDataProvider */ |
10 | 10 | |
11 | -$this->title = 'Users'; | |
11 | +$this->title = Yii::t('app', 'Users'); | |
12 | 12 | $this->params['breadcrumbs'][] = $this->title; |
13 | 13 | ?> |
14 | 14 | <div class="user-index"> |
... | ... | @@ -17,7 +17,7 @@ $this->params['breadcrumbs'][] = $this->title; |
17 | 17 | <?php // echo $this->render('_search', ['model' => $searchModel]); ?> |
18 | 18 | |
19 | 19 | <p> |
20 | - <?= Html::a('Create User', ['create'], ['class' => 'btn btn-success']) ?> | |
20 | + <?= Html::a(Yii::t('app', 'Create User'), ['create'], ['class' => 'btn btn-success']) ?> | |
21 | 21 | </p> |
22 | 22 | <?= GridView::widget([ |
23 | 23 | 'dataProvider' => $dataProvider, |
... | ... | @@ -27,10 +27,10 @@ $this->params['breadcrumbs'][] = $this->title; |
27 | 27 | |
28 | 28 | 'id', |
29 | 29 | 'username', |
30 | - 'auth_key', | |
31 | - 'password_hash', | |
32 | - 'password_reset_token', | |
33 | - | |
30 | + 'email:email', | |
31 | + // 'status', | |
32 | + // 'created_at', | |
33 | + // 'updated_at', | |
34 | 34 | |
35 | 35 | ['class' => 'yii\grid\ActionColumn', |
36 | 36 | 'template' => '{view} {update} {permit} {delete}', | ... | ... |
backend/views/user/update.php
... | ... | @@ -5,10 +5,12 @@ use yii\helpers\Html; |
5 | 5 | /* @var $this yii\web\View */ |
6 | 6 | /* @var $model backend\models\User */ |
7 | 7 | |
8 | -$this->title = 'Update User: ' . $model->id; | |
9 | -$this->params['breadcrumbs'][] = ['label' => 'Users', 'url' => ['index']]; | |
8 | +$this->title = Yii::t('app', 'Update {modelClass}: ', [ | |
9 | + 'modelClass' => 'User', | |
10 | +]) . $model->id; | |
11 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Users'), 'url' => ['index']]; | |
10 | 12 | $this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; |
11 | -$this->params['breadcrumbs'][] = 'Update'; | |
13 | +$this->params['breadcrumbs'][] = Yii::t('app', 'Update'); | |
12 | 14 | ?> |
13 | 15 | <div class="user-update"> |
14 | 16 | ... | ... |
backend/views/user/view.php
... | ... | @@ -7,7 +7,7 @@ use yii\widgets\DetailView; |
7 | 7 | /* @var $model backend\models\User */ |
8 | 8 | |
9 | 9 | $this->title = $model->id; |
10 | -$this->params['breadcrumbs'][] = ['label' => 'Users', 'url' => ['index']]; | |
10 | +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Users'), 'url' => ['index']]; | |
11 | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | 12 | ?> |
13 | 13 | <div class="user-view"> |
... | ... | @@ -15,11 +15,11 @@ $this->params['breadcrumbs'][] = $this->title; |
15 | 15 | <h1><?= Html::encode($this->title) ?></h1> |
16 | 16 | |
17 | 17 | <p> |
18 | - <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> | |
19 | - <?= Html::a('Delete', ['delete', 'id' => $model->id], [ | |
18 | + <?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> | |
19 | + <?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [ | |
20 | 20 | 'class' => 'btn btn-danger', |
21 | 21 | 'data' => [ |
22 | - 'confirm' => 'Are you sure you want to delete this item?', | |
22 | + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), | |
23 | 23 | 'method' => 'post', |
24 | 24 | ], |
25 | 25 | ]) ?> |
... | ... | @@ -30,11 +30,10 @@ $this->params['breadcrumbs'][] = $this->title; |
30 | 30 | 'attributes' => [ |
31 | 31 | 'id', |
32 | 32 | 'username', |
33 | - 'auth_key', | |
34 | - 'password_hash', | |
35 | - 'password_reset_token', | |
36 | 33 | 'email:email', |
37 | 34 | 'status', |
35 | + 'created_at', | |
36 | + 'updated_at', | |
38 | 37 | ], |
39 | 38 | ]) ?> |
40 | 39 | ... | ... |
common/components/Mailer.php
... | ... | @@ -9,6 +9,7 @@ class Mailer extends Widget{ |
9 | 9 | public $email; |
10 | 10 | public $text; |
11 | 11 | public $subject; |
12 | + public $type; | |
12 | 13 | |
13 | 14 | public function init(){ |
14 | 15 | |
... | ... | @@ -27,14 +28,16 @@ class Mailer extends Widget{ |
27 | 28 | $mail->Password = "k0l0b04eg"; |
28 | 29 | $mail->SetFrom('dockdep@gmail.com'); |
29 | 30 | $mail->Subject = $this->subject; |
30 | - $mail->MsgHTML($this->text); | |
31 | + $mail->MsgHTML('test'); | |
31 | 32 | $address = "dockdep@gmail.com"; |
32 | 33 | $mail->AddAddress($address); |
33 | 34 | $mail->AddAddress($this->email); |
34 | 35 | if(!$mail->send()) { |
36 | + | |
35 | 37 | \Yii::$app->getSession()->setFlash('error', 'Mailer Error: ' . $mail->ErrorInfo); |
36 | 38 | return 'Mailer Error: ' . $mail->ErrorInfo; |
37 | 39 | } else { |
40 | + | |
38 | 41 | \Yii::$app->getSession()->setFlash('success', 'Мастер-приемщик свяжется с вами в ближайшее время'); |
39 | 42 | return 'Message has been sent'; |
40 | 43 | } | ... | ... |
common/models/Customer.php
... | ... | @@ -74,17 +74,7 @@ class Customer extends \yii\db\ActiveRecord implements \yii\web\IdentityInterfac |
74 | 74 | ->exists()) |
75 | 75 | $this->addError('username','Такой пользователь уже есть.'); |
76 | 76 | } |
77 | - | |
78 | - public function sendMsg(){ | |
79 | - $body = 'Вас приветствует сайт Rukzachok'; | |
80 | - $body .= "\n\r"; | |
81 | - $body .= 'Ваш логин: '.$this->username; | |
82 | - $body .= "\n\r"; | |
83 | - $body .= 'Ваш пароль: '.$this->password; | |
84 | - | |
85 | - Mailer::widget(['text'=> $body, 'subject'=> 'Спасибо за регистрацию', 'email' => $this->username ]); | |
86 | - | |
87 | - } | |
77 | + | |
88 | 78 | |
89 | 79 | public function afterSave($insert, $changedAttributes) |
90 | 80 | { |
... | ... | @@ -98,30 +88,28 @@ class Customer extends \yii\db\ActiveRecord implements \yii\web\IdentityInterfac |
98 | 88 | } |
99 | 89 | $auth->assign($role, $this->id); |
100 | 90 | |
101 | - if($this->isNewRecord){ | |
102 | - $this->sendMsg(); | |
103 | - } | |
91 | + | |
104 | 92 | } |
105 | 93 | |
106 | 94 | public function beforeSave($insert) { |
107 | 95 | |
108 | 96 | |
109 | - $this->date_time = new \yii\db\Expression('NOW()'); | |
110 | - | |
97 | + $this->date_time = new \yii\db\Expression('NOW()'); | |
98 | + | |
111 | 99 | /** |
112 | - if($image = UploadedFile::getInstance($this,'image')){ | |
113 | - | |
100 | + if($image = UploadedFile::getInstance($this,'image')){ | |
101 | + | |
114 | 102 | $this->deleteImage($this->old_image); |
115 | 103 | //$this->image = $image; |
116 | 104 | $this->image = time() . '_' . rand(1, 1000) . '.' . $image->extension; |
117 | 105 | $image->saveAs('upload/profile/'.$this->image); |
118 | - | |
106 | + | |
119 | 107 | $resizeObj = new resize('upload/profile/'.$this->image); |
120 | 108 | $resizeObj -> resizeImage(240, 240, 'crop'); |
121 | 109 | $resizeObj -> saveImage('upload/profile/ico/'.$this->image, 100); |
122 | 110 | }elseif(!empty($this->old_image)) $this->image = $this->old_image; |
123 | - **/ | |
124 | - | |
111 | + **/ | |
112 | + | |
125 | 113 | return parent::beforeSave($insert); |
126 | 114 | } |
127 | 115 | ... | ... |
frontend/controllers/RegController.php
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | |
3 | 3 | namespace frontend\controllers; |
4 | 4 | |
5 | +use common\components\Mailer; | |
5 | 6 | use Yii; |
6 | 7 | use yii\web\Controller; |
7 | 8 | use yii\filters\AccessControl; |
... | ... | @@ -57,6 +58,7 @@ class RegController extends Controller |
57 | 58 | $modelLogin->username = $model->username; |
58 | 59 | $modelLogin->password = $model->password; |
59 | 60 | $modelLogin->login(); |
61 | + Mailer::widget(['type' => 'registration', 'subject'=> 'Спасибо за регистрацию', 'email' => $model->username ]); | |
60 | 62 | $this->redirect(['/iam']); |
61 | 63 | } |
62 | 64 | ... | ... |