lifetime = Config::get("auth.password_reset_lifetime", 10 * 60); } /** * @param $name * @return mixed */ public function __get($name) { return $this->{$name}; } /** * @return User */ public function getOwner(): User { return $this->owner; } /** * @param User $owner */ public function setOwner(User $owner): void { $this->owner = $owner; } /** * @return int */ public function getLifetime(): int { return $this->lifetime; } /** * @param int $lifetime */ public function setLifetime(int $lifetime): void { $this->lifetime = $lifetime; } /** * @return string */ public function getHash(): string { return $this->hash; } public const TokenLen = 50; /** * @return string */ public function generateToken(): string { $token = strval($this->id).str_random(self::TokenLen); $this->hash = self::hash($token); return $token; } /** * @param string $token * @return bool */ public function compare(string $token):bool{ return $this->hash == self::hash($token); } /** * @param string $token * @return string */ public static function hash(string $token):string{ return md5($token); } /** * @return \DateTime */ public function getRedeemAt(): \DateTime { return $this->redeem_at; } public function redeem():void{ $this->redeem_at = new \DateTime('now', new \DateTimeZone('UTC')); } /** * @return bool */ public function isRedeem():bool { return !is_null($this->redeem_at); } /** * @return bool */ public function isValid():bool{ $void_date = $this->created_at->add(new \DateInterval('PT'.$this->lifetime.'S')); $now = new \DateTime('now', new \DateTimeZone('UTC')); return $void_date > $now; } /** * @ORM\PostPersist */ public function inserted($args){ Event::fire(new UserPasswordResetRequestCreated($this->getId())); } }