From c2c5e3030a8ea56f9e6eadbcd36a4150c7978b92 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 16 Dec 2015 12:52:26 +0200 Subject: [PATCH] VItaliy 04.12.2015 --- backend/views/user/_form.php | 1 - backend/web/.gitignore | 2 +- composer.json | 3 ++- frontend/.gitignore | 3 ++- frontend/controllers/AccountsController.php | 49 ++++++++++++++++++++++++++++++++++++++++++++----- frontend/models/AccountsForm.php | 1 + frontend/models/ChangePasswordForm.php | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ frontend/views/accounts/cabinet.php | 18 ++++++------------ frontend/views/accounts/change-password.php | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ frontend/web/.gitignore | 1 + 10 files changed, 179 insertions(+), 21 deletions(-) create mode 100644 frontend/models/ChangePasswordForm.php create mode 100644 frontend/views/accounts/change-password.php diff --git a/backend/views/user/_form.php b/backend/views/user/_form.php index 58caad8..2556ea7 100755 --- a/backend/views/user/_form.php +++ b/backend/views/user/_form.php @@ -34,7 +34,6 @@ use yii\helpers\ArrayHelper; $form, 'model'=> $model, 'field'=>'photo', 'width'=>200, diff --git a/backend/web/.gitignore b/backend/web/.gitignore index 3adbc3f..ad89b64 100755 --- a/backend/web/.gitignore +++ b/backend/web/.gitignore @@ -1,3 +1,3 @@ /index.php /index-test.php -uploads/ +/assets diff --git a/composer.json b/composer.json index 4df532f..1b624c5 100755 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "mihaildev/yii2-ckeditor": "^1.0", "kartik-v/yii2-widget-fileinput": "@dev", "phpmailer/phpmailer": "^5.2", - "mihaildev/yii2-elfinder": "*" + "mihaildev/yii2-elfinder": "*", + "yiisoft/yii2-apidoc": "*" }, "require-dev": { "yiisoft/yii2-codeception": "*", diff --git a/frontend/.gitignore b/frontend/.gitignore index 36445e5..424d953 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -1 +1,2 @@ -/temp +/tmp +/runtime/temp diff --git a/frontend/controllers/AccountsController.php b/frontend/controllers/AccountsController.php index 5cac7f2..31949f4 100644 --- a/frontend/controllers/AccountsController.php +++ b/frontend/controllers/AccountsController.php @@ -1,9 +1,9 @@ AccessControl::className(), 'rules' => [ [ - 'actions' => ['cabinet',], + 'actions' => ['cabinet','change-password'], 'allow' => true, 'roles' => ['@'], ], @@ -39,9 +40,22 @@ class AccountsController extends Controller public function actionCabinet() { - return $this->render('cabinet',[ - 'model' => $this->findModel(Yii::$app->user->identity->id) + + $model = $this->findModel(Yii::$app->user->identity->id); + + + if ($model->load(Yii::$app->request->post()) && $model->validate()) { + + $model->save(); + + } + + return $this->render('cabinet', [ + 'model' => $model ]); + + + } public function actionIndex() @@ -83,6 +97,31 @@ class AccountsController extends Controller } + public function actionChangePassword(){ + + + $form = new ChangePasswordForm(); + + + if ($form->load(Yii::$app->request->post()) && $form->validate()) { + + $model = Accounts::findOne(Yii::$app->user->identity->id); + + $model->load(Yii::$app->request->post(), 'ChangePasswordForm'); + + $model->save(); + + return $this->redirect(['cabinet']); + + } else { + + return $this->render('change-password', [ + 'model' => $form + ]); + + } + } + diff --git a/frontend/models/AccountsForm.php b/frontend/models/AccountsForm.php index 81d1661..27b352d 100644 --- a/frontend/models/AccountsForm.php +++ b/frontend/models/AccountsForm.php @@ -98,6 +98,7 @@ class AccountsForm extends Accounts 'if_manager' => 'Статус менеджера', 'email' => 'E-mail (Логин)', 'pass' => 'Пароль', + 're_pass' => 'Повторите пароль', 'margin_id' => 'Тип цены', 'name' => 'Имя', 'phones' => 'Телефоны', diff --git a/frontend/models/ChangePasswordForm.php b/frontend/models/ChangePasswordForm.php new file mode 100644 index 0000000..720f85c --- /dev/null +++ b/frontend/models/ChangePasswordForm.php @@ -0,0 +1,63 @@ + 30], + ['re_pass', 'compare', 'compareAttribute' => 'pass'], + ['old_pass', 'validatePassword'], + ]; + } + + public function validatePassword($attribute, $params) + { + if (!$this->hasErrors()) { + $user = Accounts::findOne(Yii::$app->user->identity->id); + if (!$user || $user->pass != $this->old_pass) { + $this->addError($attribute, 'Неправильный логин или пароль'); + } + } + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'old_pass' => 'Старый пароль', + 'pass' => 'Новый пароль', + 're_pass' => 'Повторите пароль', + ]; + } + + + + + + + +} diff --git a/frontend/views/accounts/cabinet.php b/frontend/views/accounts/cabinet.php index 499cf63..fac0dd2 100755 --- a/frontend/views/accounts/cabinet.php +++ b/frontend/views/accounts/cabinet.php @@ -3,6 +3,7 @@ use \yii\widgets\ActiveForm; use \yii\helpers\ArrayHelper; use \common\models\DicCities; use \common\models\Deliveries; +use \yii\helpers\Html; use \yii\helpers\Url; $this->registerCssFile('/css/about_company.css'); @@ -35,9 +36,10 @@ $this->params['breadcrumbs'][] = $this->title;

Личные данные

- - ['enctype'=> 'multipart/form-data','class'=>'my_profile'], 'method'=>'post','action' => '/site/signup',]); ?> + 'purple top'])?> + + ['enctype'=> 'multipart/form-data','class'=>'my_profile'], 'method'=>'post',]); ?> field($model, 'is_firm')->hiddenInput(['value'=>'0'])->label(false) ?> @@ -45,16 +47,10 @@ $this->params['breadcrumbs'][] = $this->title; field($model, 'name',['options'=>['class'=>'input2']])->textInput(['maxlength' => 45,'placeholder'=>'Имя']) ?> - field($model, 'surname',['options'=>['class'=>'input2']])->textInput(['maxlength' => 45,'placeholder'=>'Фамилия']) ?> - field($model, 'phones',['options'=>['class'=>'input2']])->textInput(['maxlength' => 45,'placeholder'=>'Телефон']) ?> field($model, 'email',['options'=>['class'=>'input2']])->textInput(['maxlength' => 45,'placeholder'=>'E-mail','class'=>'form-control telephone_registration']) ?> - field($model, 'pass',['options'=>['class'=>'input2']])->passwordInput(['maxlength' => 45,'placeholder'=>'Пароль','class'=>'form-control telephone_registration']) ?> - - field($model, 're_pass',['options'=>['class'=>'input2']])->passwordInput(['maxlength' => 45,'placeholder'=>'Пароль','class'=>'form-control telephone_registration']) ?> - field($model, 'country',['options'=>['class'=>'selectize_item2 input2' ]])->dropDownList( ArrayHelper::map(DicCities::find()->where(['parent' => 0])->all(), 'id', 'name'), ['prompt' => 'Выберите область'] @@ -72,10 +68,8 @@ $this->params['breadcrumbs'][] = $this->title; ['prompt' => 'Выберите тип перевозки'] ); ?> - - - - + 'purple_white'])?> + diff --git a/frontend/views/accounts/change-password.php b/frontend/views/accounts/change-password.php new file mode 100644 index 0000000..7fda06f --- /dev/null +++ b/frontend/views/accounts/change-password.php @@ -0,0 +1,59 @@ +registerCssFile('/css/about_company.css'); +$this->registerCssFile('/css/style/my_profile.css'); + +$this->title = 'Смена пароля'; +$this->params['breadcrumbs'][] = $this->title; +?> + +
+

Мой профиль

+
+ ['class' => 'side_menu-list'], + 'items' => [ + ['label' => 'Личные данные', 'url' => Url::toRoute(['/accounts/cabinet'])], + ['label' => 'Блокнот', 'url' => Url::toRoute(['/accounts/cabinet'])], + ['label' => 'Корзина', 'url' => Url::toRoute(['/accounts/cabinet'])], + ['label' => 'Заказы', 'url' => Url::toRoute(['/accounts/cabinet'])], + ['label' => 'Выйти', 'url' => Url::toRoute(['/site/logout'])], + + ], + ]); + ?> +
+
+

Личные данные

+
+ ['enctype'=> 'multipart/form-data','class'=>'my_profile'], 'method'=>'post',]); ?> + + field($model, 'old_pass',['options'=>['class'=>'input2']])->passwordInput(['maxlength' => 45,'placeholder'=>'Пароль','class'=>'form-control telephone_registration']) ?> + + field($model, 'pass',['options'=>['class'=>'input2']])->passwordInput(['maxlength' => 45,'placeholder'=>'Пароль','class'=>'form-control telephone_registration']) ?> + + field($model, 're_pass',['options'=>['class'=>'input2']])->passwordInput(['maxlength' => 45,'placeholder'=>'Пароль','class'=>'form-control telephone_registration']) ?> + + + 'purple_white'])?> + + + + + +
+ + + +
+ + + +
+
+ +
diff --git a/frontend/web/.gitignore b/frontend/web/.gitignore index 25c74e6..9429da8 100755 --- a/frontend/web/.gitignore +++ b/frontend/web/.gitignore @@ -1,2 +1,3 @@ +/assets /index.php /index-test.php -- libgit2 0.21.4