Commit 4de21bc2ca1d82fb2eff79ef7a00be3e864f15a0
1 parent
ebd016c8
add create_item to translate
Showing
1 changed file
with
55 additions
and
6 deletions
Show diff stats
models/Customer.php
| @@ -27,7 +27,12 @@ | @@ -27,7 +27,12 @@ | ||
| 27 | */ | 27 | */ |
| 28 | class Customer extends User implements IdentityInterface | 28 | class Customer extends User implements IdentityInterface |
| 29 | { | 29 | { |
| 30 | - | 30 | + |
| 31 | + public $password_repeat; | ||
| 32 | + public $password; | ||
| 33 | + const SCENARIO_CHANGE = 'change'; | ||
| 34 | + | ||
| 35 | + | ||
| 31 | /** | 36 | /** |
| 32 | * @inheritdoc | 37 | * @inheritdoc |
| 33 | */ | 38 | */ |
| @@ -87,16 +92,40 @@ | @@ -87,16 +92,40 @@ | ||
| 87 | ], | 92 | ], |
| 88 | [ | 93 | [ |
| 89 | [ | 94 | [ |
| 95 | + 'phone', | ||
| 96 | + 'email', | ||
| 97 | + ], | ||
| 98 | + 'unique' | ||
| 99 | + ], | ||
| 100 | + [ | ||
| 101 | + [ | ||
| 90 | 'gender', | 102 | 'gender', |
| 91 | 'auth_key', | 103 | 'auth_key', |
| 92 | ], | 104 | ], |
| 93 | 'string', | 105 | 'string', |
| 94 | 'max' => 32, | 106 | 'max' => 32, |
| 95 | ], | 107 | ], |
| 108 | + | ||
| 109 | + ['password', 'string', 'min' => 6,'on'=>[Customer::SCENARIO_CHANGE]], | ||
| 110 | + | ||
| 111 | + ['password', 'validatePasswordCompare', 'on'=>[Customer::SCENARIO_CHANGE]], | ||
| 112 | + | ||
| 113 | + ['password_repeat', 'compare', 'compareAttribute'=>'password', 'message'=> Yii::t('app', 'message_match_password'),'on'=>[Customer::SCENARIO_CHANGE] ], | ||
| 114 | + | ||
| 115 | + | ||
| 116 | + | ||
| 96 | ]; | 117 | ]; |
| 97 | } | 118 | } |
| 98 | 119 | ||
| 99 | 120 | ||
| 121 | + public function validatePasswordCompare($attribute, $params) | ||
| 122 | + { | ||
| 123 | + if(!empty($this->password) && empty($this->password_repeat)){ | ||
| 124 | + $this->addError('password_repeat', \Yii::t('app', 'message_match_password')); | ||
| 125 | + } | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + | ||
| 100 | 129 | ||
| 101 | 130 | ||
| 102 | /** | 131 | /** |
| @@ -106,14 +135,14 @@ | @@ -106,14 +135,14 @@ | ||
| 106 | { | 135 | { |
| 107 | return [ | 136 | return [ |
| 108 | 'id' => Yii::t('app', 'id'), | 137 | 'id' => Yii::t('app', 'id'), |
| 109 | - 'username' => Yii::t('app', 'username'), | 138 | + 'username' => Yii::t('app', 'Фамилия Имя Очество'), |
| 110 | 'surname' => Yii::t('app', 'surname'), | 139 | 'surname' => Yii::t('app', 'surname'), |
| 111 | 'phone' => Yii::t('app', 'Мобильный телефон'), | 140 | 'phone' => Yii::t('app', 'Мобильный телефон'), |
| 112 | - 'gender' => Yii::t('app', 'gender'), | ||
| 113 | - 'birthday' => Yii::t('app', 'birthday'), | 141 | + 'gender' => Yii::t('app', 'Пол'), |
| 142 | + 'birthday' => Yii::t('app', 'Дата рождения'), | ||
| 114 | 'body' => Yii::t('app', 'body'), | 143 | 'body' => Yii::t('app', 'body'), |
| 115 | 'group_id' => Yii::t('app', 'group_id'), | 144 | 'group_id' => Yii::t('app', 'group_id'), |
| 116 | - 'email' => Yii::t('app', 'email'), | 145 | + 'email' => Yii::t('app', 'Ваш e-mail'), |
| 117 | 'auth_key' => Yii::t('app', 'auth_key'), | 146 | 'auth_key' => Yii::t('app', 'auth_key'), |
| 118 | 'password_reset_token' => Yii::t('app', 'password_reset_token'), | 147 | 'password_reset_token' => Yii::t('app', 'password_reset_token'), |
| 119 | 'status' => Yii::t('app', 'status'), | 148 | 'status' => Yii::t('app', 'status'), |
| @@ -121,6 +150,8 @@ | @@ -121,6 +150,8 @@ | ||
| 121 | 'updated_at' => Yii::t('app', 'updated_at'), | 150 | 'updated_at' => Yii::t('app', 'updated_at'), |
| 122 | 'city' => Yii::t('app', 'Город'), | 151 | 'city' => Yii::t('app', 'Город'), |
| 123 | 'address' => Yii::t('app', 'Адрес'), | 152 | 'address' => Yii::t('app', 'Адрес'), |
| 153 | + 'password' => Yii::t('app', 'Пароль'), | ||
| 154 | + 'password_repeat' => Yii::t('app', 'Пароль повторно'), | ||
| 124 | ]; | 155 | ]; |
| 125 | } | 156 | } |
| 126 | 157 | ||
| @@ -152,20 +183,38 @@ | @@ -152,20 +183,38 @@ | ||
| 152 | } | 183 | } |
| 153 | 184 | ||
| 154 | 185 | ||
| 186 | + public function afterFind() | ||
| 187 | + { | ||
| 188 | + parent::afterFind(); | ||
| 189 | + $this->birthday = !empty($this->birthday) ? date('d.m.Y',$this->birthday) : ''; | ||
| 190 | + | ||
| 191 | + } | ||
| 192 | + | ||
| 155 | public function beforeSave($insert) | 193 | public function beforeSave($insert) |
| 156 | { | 194 | { |
| 157 | if (parent::beforeSave($insert)) { | 195 | if (parent::beforeSave($insert)) { |
| 158 | 196 | ||
| 159 | - $this->birthday = !empty($this->birthday) ? (string)strtotime($this->birthday) : ''; | 197 | + $this->convertBirthday(); |
| 160 | return true; | 198 | return true; |
| 161 | } | 199 | } |
| 162 | return false; | 200 | return false; |
| 163 | 201 | ||
| 164 | } | 202 | } |
| 203 | + | ||
| 204 | + public function convertBirthday(){ | ||
| 205 | + if(!empty($this->birthday)){ | ||
| 206 | + $birthday = new \DateTime($this->birthday); | ||
| 207 | + $birthday->format("d.m.Y"); | ||
| 208 | + $this->birthday = $birthday->getTimestamp(); | ||
| 209 | + | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + } | ||
| 165 | 213 | ||
| 166 | public function getPassword() | 214 | public function getPassword() |
| 167 | { | 215 | { |
| 168 | return false; | 216 | return false; |
| 169 | } | 217 | } |
| 218 | + | ||
| 170 | 219 | ||
| 171 | } | 220 | } |