Commit c2c5e3030a8ea56f9e6eadbcd36a4150c7978b92
1 parent
ea47d08d
VItaliy 04.12.2015
Showing
10 changed files
with
179 additions
and
21 deletions
Show diff stats
backend/views/user/_form.php
| @@ -34,7 +34,6 @@ use yii\helpers\ArrayHelper; | @@ -34,7 +34,6 @@ use yii\helpers\ArrayHelper; | ||
| 34 | 34 | ||
| 35 | 35 | ||
| 36 | <?= \backend\components\ImageUploader::widget([ | 36 | <?= \backend\components\ImageUploader::widget([ |
| 37 | - 'form'=>$form, | ||
| 38 | 'model'=> $model, | 37 | 'model'=> $model, |
| 39 | 'field'=>'photo', | 38 | 'field'=>'photo', |
| 40 | 'width'=>200, | 39 | 'width'=>200, |
backend/web/.gitignore
composer.json
| @@ -27,7 +27,8 @@ | @@ -27,7 +27,8 @@ | ||
| 27 | "mihaildev/yii2-ckeditor": "^1.0", | 27 | "mihaildev/yii2-ckeditor": "^1.0", |
| 28 | "kartik-v/yii2-widget-fileinput": "@dev", | 28 | "kartik-v/yii2-widget-fileinput": "@dev", |
| 29 | "phpmailer/phpmailer": "^5.2", | 29 | "phpmailer/phpmailer": "^5.2", |
| 30 | - "mihaildev/yii2-elfinder": "*" | 30 | + "mihaildev/yii2-elfinder": "*", |
| 31 | + "yiisoft/yii2-apidoc": "*" | ||
| 31 | }, | 32 | }, |
| 32 | "require-dev": { | 33 | "require-dev": { |
| 33 | "yiisoft/yii2-codeception": "*", | 34 | "yiisoft/yii2-codeception": "*", |
frontend/.gitignore
frontend/controllers/AccountsController.php
| 1 | <?php | 1 | <?php |
| 2 | namespace frontend\controllers; | 2 | namespace frontend\controllers; |
| 3 | 3 | ||
| 4 | - | ||
| 5 | -use common\models\Accounts; | ||
| 6 | use Yii; | 4 | use Yii; |
| 5 | +use common\models\Accounts; | ||
| 6 | +use frontend\models\ChangePasswordForm; | ||
| 7 | use common\models\News; | 7 | use common\models\News; |
| 8 | use yii\data\ActiveDataProvider; | 8 | use yii\data\ActiveDataProvider; |
| 9 | use yii\filters\AccessControl; | 9 | use yii\filters\AccessControl; |
| @@ -16,6 +16,7 @@ use yii\web\NotFoundHttpException; | @@ -16,6 +16,7 @@ use yii\web\NotFoundHttpException; | ||
| 16 | */ | 16 | */ |
| 17 | class AccountsController extends Controller | 17 | class AccountsController extends Controller |
| 18 | { | 18 | { |
| 19 | + | ||
| 19 | public $layout = '/internal'; | 20 | public $layout = '/internal'; |
| 20 | 21 | ||
| 21 | 22 | ||
| @@ -26,7 +27,7 @@ class AccountsController extends Controller | @@ -26,7 +27,7 @@ class AccountsController extends Controller | ||
| 26 | 'class' => AccessControl::className(), | 27 | 'class' => AccessControl::className(), |
| 27 | 'rules' => [ | 28 | 'rules' => [ |
| 28 | [ | 29 | [ |
| 29 | - 'actions' => ['cabinet',], | 30 | + 'actions' => ['cabinet','change-password'], |
| 30 | 'allow' => true, | 31 | 'allow' => true, |
| 31 | 'roles' => ['@'], | 32 | 'roles' => ['@'], |
| 32 | ], | 33 | ], |
| @@ -39,9 +40,22 @@ class AccountsController extends Controller | @@ -39,9 +40,22 @@ class AccountsController extends Controller | ||
| 39 | public function actionCabinet() | 40 | public function actionCabinet() |
| 40 | { | 41 | { |
| 41 | 42 | ||
| 42 | - return $this->render('cabinet',[ | ||
| 43 | - 'model' => $this->findModel(Yii::$app->user->identity->id) | 43 | + |
| 44 | + $model = $this->findModel(Yii::$app->user->identity->id); | ||
| 45 | + | ||
| 46 | + | ||
| 47 | + if ($model->load(Yii::$app->request->post()) && $model->validate()) { | ||
| 48 | + | ||
| 49 | + $model->save(); | ||
| 50 | + | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + return $this->render('cabinet', [ | ||
| 54 | + 'model' => $model | ||
| 44 | ]); | 55 | ]); |
| 56 | + | ||
| 57 | + | ||
| 58 | + | ||
| 45 | } | 59 | } |
| 46 | 60 | ||
| 47 | public function actionIndex() | 61 | public function actionIndex() |
| @@ -83,6 +97,31 @@ class AccountsController extends Controller | @@ -83,6 +97,31 @@ class AccountsController extends Controller | ||
| 83 | } | 97 | } |
| 84 | 98 | ||
| 85 | 99 | ||
| 100 | + public function actionChangePassword(){ | ||
| 101 | + | ||
| 102 | + | ||
| 103 | + $form = new ChangePasswordForm(); | ||
| 104 | + | ||
| 105 | + | ||
| 106 | + if ($form->load(Yii::$app->request->post()) && $form->validate()) { | ||
| 107 | + | ||
| 108 | + $model = Accounts::findOne(Yii::$app->user->identity->id); | ||
| 109 | + | ||
| 110 | + $model->load(Yii::$app->request->post(), 'ChangePasswordForm'); | ||
| 111 | + | ||
| 112 | + $model->save(); | ||
| 113 | + | ||
| 114 | + return $this->redirect(['cabinet']); | ||
| 115 | + | ||
| 116 | + } else { | ||
| 117 | + | ||
| 118 | + return $this->render('change-password', [ | ||
| 119 | + 'model' => $form | ||
| 120 | + ]); | ||
| 121 | + | ||
| 122 | + } | ||
| 123 | + } | ||
| 124 | + | ||
| 86 | 125 | ||
| 87 | 126 | ||
| 88 | 127 |
frontend/models/AccountsForm.php
| @@ -98,6 +98,7 @@ class AccountsForm extends Accounts | @@ -98,6 +98,7 @@ class AccountsForm extends Accounts | ||
| 98 | 'if_manager' => 'Статус менеджера', | 98 | 'if_manager' => 'Статус менеджера', |
| 99 | 'email' => 'E-mail (Логин)', | 99 | 'email' => 'E-mail (Логин)', |
| 100 | 'pass' => 'Пароль', | 100 | 'pass' => 'Пароль', |
| 101 | + 're_pass' => 'Повторите пароль', | ||
| 101 | 'margin_id' => 'Тип цены', | 102 | 'margin_id' => 'Тип цены', |
| 102 | 'name' => 'Имя', | 103 | 'name' => 'Имя', |
| 103 | 'phones' => 'Телефоны', | 104 | 'phones' => 'Телефоны', |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace frontend\models; | ||
| 4 | + | ||
| 5 | +use common\models\Accounts; | ||
| 6 | +use yii\base\Model; | ||
| 7 | +use Yii; | ||
| 8 | +/** | ||
| 9 | + * @property string $old_pass | ||
| 10 | + * @property string $new_pass | ||
| 11 | + * @property string $re_pass | ||
| 12 | + */ | ||
| 13 | +class ChangePasswordForm extends Accounts | ||
| 14 | +{ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + public $re_pass; | ||
| 18 | + public $old_pass; | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * @inheritdoc | ||
| 24 | + */ | ||
| 25 | + public function rules() | ||
| 26 | + { | ||
| 27 | + return [ | ||
| 28 | + [['old_pass','pass', 're_pass'], 'required'], | ||
| 29 | + [['old_pass','pass', 're_pass'], 'string', 'max' => 30], | ||
| 30 | + ['re_pass', 'compare', 'compareAttribute' => 'pass'], | ||
| 31 | + ['old_pass', 'validatePassword'], | ||
| 32 | + ]; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public function validatePassword($attribute, $params) | ||
| 36 | + { | ||
| 37 | + if (!$this->hasErrors()) { | ||
| 38 | + $user = Accounts::findOne(Yii::$app->user->identity->id); | ||
| 39 | + if (!$user || $user->pass != $this->old_pass) { | ||
| 40 | + $this->addError($attribute, 'Неправильный логин или пароль'); | ||
| 41 | + } | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * @inheritdoc | ||
| 47 | + */ | ||
| 48 | + public function attributeLabels() | ||
| 49 | + { | ||
| 50 | + return [ | ||
| 51 | + 'old_pass' => 'Старый пароль', | ||
| 52 | + 'pass' => 'Новый пароль', | ||
| 53 | + 're_pass' => 'Повторите пароль', | ||
| 54 | + ]; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + | ||
| 60 | + | ||
| 61 | + | ||
| 62 | + | ||
| 63 | +} |
frontend/views/accounts/cabinet.php
| @@ -3,6 +3,7 @@ use \yii\widgets\ActiveForm; | @@ -3,6 +3,7 @@ use \yii\widgets\ActiveForm; | ||
| 3 | use \yii\helpers\ArrayHelper; | 3 | use \yii\helpers\ArrayHelper; |
| 4 | use \common\models\DicCities; | 4 | use \common\models\DicCities; |
| 5 | use \common\models\Deliveries; | 5 | use \common\models\Deliveries; |
| 6 | +use \yii\helpers\Html; | ||
| 6 | use \yii\helpers\Url; | 7 | use \yii\helpers\Url; |
| 7 | 8 | ||
| 8 | $this->registerCssFile('/css/about_company.css'); | 9 | $this->registerCssFile('/css/about_company.css'); |
| @@ -35,9 +36,10 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -35,9 +36,10 @@ $this->params['breadcrumbs'][] = $this->title; | ||
| 35 | <div role="tabpanel" class="tab-pane active" id="profile"> | 36 | <div role="tabpanel" class="tab-pane active" id="profile"> |
| 36 | <p class="tab-content_header">Личные данные</p> | 37 | <p class="tab-content_header">Личные данные</p> |
| 37 | <div class="myprofile"> | 38 | <div class="myprofile"> |
| 38 | - <button class="purple top">Изменить пароль</button> | ||
| 39 | 39 | ||
| 40 | - <?php $form = ActiveForm::begin(['options' => ['enctype'=> 'multipart/form-data','class'=>'my_profile'], 'method'=>'post','action' => '/site/signup',]); ?> | 40 | + <?= Html::a( 'Изменить пароль', Url::toRoute('accounts/change-password'),['class'=>'purple top'])?> |
| 41 | + | ||
| 42 | + <?php $form = ActiveForm::begin(['options' => ['enctype'=> 'multipart/form-data','class'=>'my_profile'], 'method'=>'post',]); ?> | ||
| 41 | 43 | ||
| 42 | <?= $form->field($model, 'is_firm')->hiddenInput(['value'=>'0'])->label(false) ?> | 44 | <?= $form->field($model, 'is_firm')->hiddenInput(['value'=>'0'])->label(false) ?> |
| 43 | 45 | ||
| @@ -45,16 +47,10 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -45,16 +47,10 @@ $this->params['breadcrumbs'][] = $this->title; | ||
| 45 | 47 | ||
| 46 | <?= $form->field($model, 'name',['options'=>['class'=>'input2']])->textInput(['maxlength' => 45,'placeholder'=>'Имя']) ?> | 48 | <?= $form->field($model, 'name',['options'=>['class'=>'input2']])->textInput(['maxlength' => 45,'placeholder'=>'Имя']) ?> |
| 47 | 49 | ||
| 48 | - <?= $form->field($model, 'surname',['options'=>['class'=>'input2']])->textInput(['maxlength' => 45,'placeholder'=>'Фамилия']) ?> | ||
| 49 | - | ||
| 50 | <?= $form->field($model, 'phones',['options'=>['class'=>'input2']])->textInput(['maxlength' => 45,'placeholder'=>'Телефон']) ?> | 50 | <?= $form->field($model, 'phones',['options'=>['class'=>'input2']])->textInput(['maxlength' => 45,'placeholder'=>'Телефон']) ?> |
| 51 | 51 | ||
| 52 | <?= $form->field($model, 'email',['options'=>['class'=>'input2']])->textInput(['maxlength' => 45,'placeholder'=>'E-mail','class'=>'form-control telephone_registration']) ?> | 52 | <?= $form->field($model, 'email',['options'=>['class'=>'input2']])->textInput(['maxlength' => 45,'placeholder'=>'E-mail','class'=>'form-control telephone_registration']) ?> |
| 53 | 53 | ||
| 54 | - <?= $form->field($model, 'pass',['options'=>['class'=>'input2']])->passwordInput(['maxlength' => 45,'placeholder'=>'Пароль','class'=>'form-control telephone_registration']) ?> | ||
| 55 | - | ||
| 56 | - <?= $form->field($model, 're_pass',['options'=>['class'=>'input2']])->passwordInput(['maxlength' => 45,'placeholder'=>'Пароль','class'=>'form-control telephone_registration']) ?> | ||
| 57 | - | ||
| 58 | <?= $form->field($model, 'country',['options'=>['class'=>'selectize_item2 input2' ]])->dropDownList( | 54 | <?= $form->field($model, 'country',['options'=>['class'=>'selectize_item2 input2' ]])->dropDownList( |
| 59 | ArrayHelper::map(DicCities::find()->where(['parent' => 0])->all(), 'id', 'name'), | 55 | ArrayHelper::map(DicCities::find()->where(['parent' => 0])->all(), 'id', 'name'), |
| 60 | ['prompt' => 'Выберите область'] | 56 | ['prompt' => 'Выберите область'] |
| @@ -72,10 +68,8 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -72,10 +68,8 @@ $this->params['breadcrumbs'][] = $this->title; | ||
| 72 | ['prompt' => 'Выберите тип перевозки'] | 68 | ['prompt' => 'Выберите тип перевозки'] |
| 73 | ); | 69 | ); |
| 74 | ?> | 70 | ?> |
| 75 | - | ||
| 76 | - | ||
| 77 | - <button class="purple_white">Отмена</button> | ||
| 78 | - <button class="purple">Изменить</button> | 71 | + <?= Html::a( 'Отмена', Url::toRoute('/'),['class'=>'purple_white'])?> |
| 72 | + <button type="submit" class="purple">Изменить</button> | ||
| 79 | <?php ActiveForm::end(); ?> | 73 | <?php ActiveForm::end(); ?> |
| 80 | 74 | ||
| 81 | 75 |
| 1 | +<?php | ||
| 2 | +use \yii\widgets\ActiveForm; | ||
| 3 | +use \yii\helpers\Url; | ||
| 4 | +use \yii\helpers\Html; | ||
| 5 | + | ||
| 6 | +$this->registerCssFile('/css/about_company.css'); | ||
| 7 | +$this->registerCssFile('/css/style/my_profile.css'); | ||
| 8 | + | ||
| 9 | +$this->title = 'Смена пароля'; | ||
| 10 | +$this->params['breadcrumbs'][] = $this->title; | ||
| 11 | +?> | ||
| 12 | + | ||
| 13 | +<div class="vin"> | ||
| 14 | + <p class="vin_article">Мой профиль</p> | ||
| 15 | + <div class='side_menu'> | ||
| 16 | + <?php | ||
| 17 | + echo \yii\widgets\Menu::widget([ | ||
| 18 | + 'options' => ['class' => 'side_menu-list'], | ||
| 19 | + 'items' => [ | ||
| 20 | + ['label' => 'Личные данные', 'url' => Url::toRoute(['/accounts/cabinet'])], | ||
| 21 | + ['label' => 'Блокнот', 'url' => Url::toRoute(['/accounts/cabinet'])], | ||
| 22 | + ['label' => 'Корзина', 'url' => Url::toRoute(['/accounts/cabinet'])], | ||
| 23 | + ['label' => 'Заказы', 'url' => Url::toRoute(['/accounts/cabinet'])], | ||
| 24 | + ['label' => 'Выйти', 'url' => Url::toRoute(['/site/logout'])], | ||
| 25 | + | ||
| 26 | + ], | ||
| 27 | + ]); | ||
| 28 | + ?> | ||
| 29 | + <div class="tab-content"> | ||
| 30 | + <div role="tabpanel" class="tab-pane active" id="profile"> | ||
| 31 | + <p class="tab-content_header">Личные данные</p> | ||
| 32 | + <div class="myprofile"> | ||
| 33 | + <?php $form = ActiveForm::begin(['options' => ['enctype'=> 'multipart/form-data','class'=>'my_profile'], 'method'=>'post',]); ?> | ||
| 34 | + | ||
| 35 | + <?= $form->field($model, 'old_pass',['options'=>['class'=>'input2']])->passwordInput(['maxlength' => 45,'placeholder'=>'Пароль','class'=>'form-control telephone_registration']) ?> | ||
| 36 | + | ||
| 37 | + <?= $form->field($model, 'pass',['options'=>['class'=>'input2']])->passwordInput(['maxlength' => 45,'placeholder'=>'Пароль','class'=>'form-control telephone_registration']) ?> | ||
| 38 | + | ||
| 39 | + <?= $form->field($model, 're_pass',['options'=>['class'=>'input2']])->passwordInput(['maxlength' => 45,'placeholder'=>'Пароль','class'=>'form-control telephone_registration']) ?> | ||
| 40 | + | ||
| 41 | + | ||
| 42 | + <?= Html::a( 'Отмена', Url::toRoute('/'),['class'=>'purple_white'])?> | ||
| 43 | + <button type="submit" class="purple">Изменить</button> | ||
| 44 | + <?php ActiveForm::end(); ?> | ||
| 45 | + | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + </div> | ||
| 49 | + | ||
| 50 | + | ||
| 51 | + | ||
| 52 | + </div> | ||
| 53 | + | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + </div> | ||
| 57 | + </div> | ||
| 58 | + <img src="/images/lonh_line.png" class='long_line'> | ||
| 59 | +</div> |
frontend/web/.gitignore