diff --git a/common/models/Customer.php b/common/models/Customer.php index 019da3a..ee1b101 100755 --- a/common/models/Customer.php +++ b/common/models/Customer.php @@ -3,6 +3,10 @@ namespace common\models; use common\widgets\Mailer; use Yii; +use Yii; +use yii\base\NotSupportedException; +use yii\behaviors\TimestampBehavior; +use yii\db\ActiveRecord; class Customer extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface { @@ -210,5 +214,50 @@ class Customer extends \yii\db\ActiveRecord implements \yii\web\IdentityInterfac public function getImageProfile(){ return !empty($this->image) ? $this->image : 'user_photo.png'; - } + } + + public static function findByPasswordResetToken($token) + { + if (!static::isPasswordResetTokenValid($token)) { + return null; + } + + return static::findOne([ + 'password_reset_token' => $token, + 'status' => self::STATUS_ACTIVE, + ]); + } + + /** + * Finds out if password reset token is valid + * + * @param string $token password reset token + * @return boolean + */ + public static function isPasswordResetTokenValid($token) + { + if (empty($token)) { + return false; + } + + $timestamp = (int) substr($token, strrpos($token, '_') + 1); + $expire = Yii::$app->params['user.passwordResetTokenExpire']; + return $timestamp + $expire >= time(); + } + + /** + * Generates new password reset token + */ + public function generatePasswordResetToken() + { + $this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time(); + } + + /** + * Removes password reset token + */ + public function removePasswordResetToken() + { + $this->password_reset_token = null; + } } -- libgit2 0.21.4