Commit 86a325610d4af33c6a62eda10c2244084ede9cdc
1 parent
dee603c7
restet password mail
Showing
1 changed file
with
50 additions
and
1 deletions
Show diff stats
common/models/Customer.php
| ... | ... | @@ -3,6 +3,10 @@ |
| 3 | 3 | namespace common\models; |
| 4 | 4 | use common\widgets\Mailer; |
| 5 | 5 | use Yii; |
| 6 | +use Yii; | |
| 7 | +use yii\base\NotSupportedException; | |
| 8 | +use yii\behaviors\TimestampBehavior; | |
| 9 | +use yii\db\ActiveRecord; | |
| 6 | 10 | |
| 7 | 11 | class Customer extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface |
| 8 | 12 | { |
| ... | ... | @@ -210,5 +214,50 @@ class Customer extends \yii\db\ActiveRecord implements \yii\web\IdentityInterfac |
| 210 | 214 | |
| 211 | 215 | public function getImageProfile(){ |
| 212 | 216 | return !empty($this->image) ? $this->image : 'user_photo.png'; |
| 213 | - } | |
| 217 | + } | |
| 218 | + | |
| 219 | + public static function findByPasswordResetToken($token) | |
| 220 | + { | |
| 221 | + if (!static::isPasswordResetTokenValid($token)) { | |
| 222 | + return null; | |
| 223 | + } | |
| 224 | + | |
| 225 | + return static::findOne([ | |
| 226 | + 'password_reset_token' => $token, | |
| 227 | + 'status' => self::STATUS_ACTIVE, | |
| 228 | + ]); | |
| 229 | + } | |
| 230 | + | |
| 231 | + /** | |
| 232 | + * Finds out if password reset token is valid | |
| 233 | + * | |
| 234 | + * @param string $token password reset token | |
| 235 | + * @return boolean | |
| 236 | + */ | |
| 237 | + public static function isPasswordResetTokenValid($token) | |
| 238 | + { | |
| 239 | + if (empty($token)) { | |
| 240 | + return false; | |
| 241 | + } | |
| 242 | + | |
| 243 | + $timestamp = (int) substr($token, strrpos($token, '_') + 1); | |
| 244 | + $expire = Yii::$app->params['user.passwordResetTokenExpire']; | |
| 245 | + return $timestamp + $expire >= time(); | |
| 246 | + } | |
| 247 | + | |
| 248 | + /** | |
| 249 | + * Generates new password reset token | |
| 250 | + */ | |
| 251 | + public function generatePasswordResetToken() | |
| 252 | + { | |
| 253 | + $this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time(); | |
| 254 | + } | |
| 255 | + | |
| 256 | + /** | |
| 257 | + * Removes password reset token | |
| 258 | + */ | |
| 259 | + public function removePasswordResetToken() | |
| 260 | + { | |
| 261 | + $this->password_reset_token = null; | |
| 262 | + } | |
| 214 | 263 | } | ... | ... |