Commit 3629dfb9d63f71a0418c411639e0d8e579bb50d1

Authored by Alexey Boroda
1 parent 35049efa

-User's password change done

Showing 1 changed file with 57 additions and 0 deletions   Show diff stats
models/PasswordForm.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\order\models;
  4 +
  5 + use Yii;
  6 + use yii\base\Model;
  7 +
  8 + class PasswordForm extends Model
  9 + {
  10 + public $oldpass;
  11 + public $newpass;
  12 + public $repeatnewpass;
  13 +
  14 + public function rules()
  15 + {
  16 + return [
  17 + [
  18 + [
  19 + 'oldpass',
  20 + 'newpass',
  21 + 'repeatnewpass',
  22 + ],
  23 + 'required',
  24 + ],
  25 + [
  26 + 'oldpass',
  27 + 'validatePassword',
  28 + ],
  29 + [
  30 + 'repeatnewpass',
  31 + 'compare',
  32 + 'compareAttribute' => 'newpass',
  33 + ],
  34 + ];
  35 + }
  36 +
  37 + public function validatePassword($attribute)
  38 + {
  39 + if (!Yii::$app->getSecurity()
  40 + ->validatePassword(
  41 + $this->oldpass,
  42 + \Yii::$app->user->identity->password_hash
  43 + )
  44 + ) {
  45 + $this->addError($attribute, 'Old password is incorrect');
  46 + }
  47 + }
  48 +
  49 + public function attributeLabels()
  50 + {
  51 + return [
  52 + 'oldpass' => \Yii::t('app', 'Старый пароль'),
  53 + 'newpass' => \Yii::t('app', 'Новый пароль'),
  54 + 'repeatnewpass' => \Yii::t('app', 'Повторите новый пароль'),
  55 + ];
  56 + }
  57 + }
0 58 \ No newline at end of file
... ...