diff --git a/models/Customer.php b/models/Customer.php index 4be6346..065b594 100755 --- a/models/Customer.php +++ b/models/Customer.php @@ -27,7 +27,12 @@ */ class Customer extends User implements IdentityInterface { - + + public $password_repeat; + public $password; + const SCENARIO_CHANGE = 'change'; + + /** * @inheritdoc */ @@ -87,16 +92,40 @@ ], [ [ + 'phone', + 'email', + ], + 'unique' + ], + [ + [ 'gender', 'auth_key', ], 'string', 'max' => 32, ], + + ['password', 'string', 'min' => 6,'on'=>[Customer::SCENARIO_CHANGE]], + + ['password', 'validatePasswordCompare', 'on'=>[Customer::SCENARIO_CHANGE]], + + ['password_repeat', 'compare', 'compareAttribute'=>'password', 'message'=> Yii::t('app', 'message_match_password'),'on'=>[Customer::SCENARIO_CHANGE] ], + + + ]; } + public function validatePasswordCompare($attribute, $params) + { + if(!empty($this->password) && empty($this->password_repeat)){ + $this->addError('password_repeat', \Yii::t('app', 'message_match_password')); + } + } + + /** @@ -106,14 +135,14 @@ { return [ 'id' => Yii::t('app', 'id'), - 'username' => Yii::t('app', 'username'), + 'username' => Yii::t('app', 'Фамилия Имя Очество'), 'surname' => Yii::t('app', 'surname'), 'phone' => Yii::t('app', 'Мобильный телефон'), - 'gender' => Yii::t('app', 'gender'), - 'birthday' => Yii::t('app', 'birthday'), + 'gender' => Yii::t('app', 'Пол'), + 'birthday' => Yii::t('app', 'Дата рождения'), 'body' => Yii::t('app', 'body'), 'group_id' => Yii::t('app', 'group_id'), - 'email' => Yii::t('app', 'email'), + 'email' => Yii::t('app', 'Ваш e-mail'), 'auth_key' => Yii::t('app', 'auth_key'), 'password_reset_token' => Yii::t('app', 'password_reset_token'), 'status' => Yii::t('app', 'status'), @@ -121,6 +150,8 @@ 'updated_at' => Yii::t('app', 'updated_at'), 'city' => Yii::t('app', 'Город'), 'address' => Yii::t('app', 'Адрес'), + 'password' => Yii::t('app', 'Пароль'), + 'password_repeat' => Yii::t('app', 'Пароль повторно'), ]; } @@ -152,20 +183,38 @@ } + public function afterFind() + { + parent::afterFind(); + $this->birthday = !empty($this->birthday) ? date('d.m.Y',$this->birthday) : ''; + + } + public function beforeSave($insert) { if (parent::beforeSave($insert)) { - $this->birthday = !empty($this->birthday) ? (string)strtotime($this->birthday) : ''; + $this->convertBirthday(); return true; } return false; } + + public function convertBirthday(){ + if(!empty($this->birthday)){ + $birthday = new \DateTime($this->birthday); + $birthday->format("d.m.Y"); + $this->birthday = $birthday->getTimestamp(); + + } + + } public function getPassword() { return false; } + } -- libgit2 0.21.4