2021-07-30 02:26:14 +09:00
< ? php
namespace App\Entity ;
use App\Core\Entity ;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface ;
class ResetPasswordRequest extends Entity implements ResetPasswordRequestInterface
{
// {{{ Autocode
// @codeCoverageIgnoreStart
2021-07-30 02:47:58 +09:00
private int $id ;
private int $user_id ;
private ? string $selector ;
private ? string $token ;
private \DateTimeInterface $expires ;
2021-07-30 02:26:14 +09:00
private \DateTimeInterface $created ;
2021-07-30 02:47:58 +09:00
public function setId ( int $id ) : self
2021-07-30 02:26:14 +09:00
{
2021-07-30 02:47:58 +09:00
$this -> id = $id ;
2021-07-30 02:26:14 +09:00
return $this ;
}
2021-07-30 02:47:58 +09:00
public function getId () : int
2021-07-30 02:26:14 +09:00
{
2021-07-30 02:47:58 +09:00
return $this -> id ;
2021-07-30 02:26:14 +09:00
}
2021-07-30 02:47:58 +09:00
public function setUserId ( int $user_id ) : self
{
$this -> user_id = $user_id ;
return $this ;
}
public function getUserId () : int
{
return $this -> user_id ;
}
public function setSelector ( ? string $selector ) : self
{
$this -> selector = $selector ;
return $this ;
}
public function getSelector () : ? string
{
return $this -> selector ;
}
public function setToken ( ? string $token ) : self
{
$this -> token = $token ;
return $this ;
}
public function getToken () : ? string
{
return $this -> token ;
}
public function setExpires ( \DateTimeInterface $expires ) : self
{
$this -> expires = $expires ;
return $this ;
}
public function getExpires () : \DateTimeInterface
{
return $this -> expires ;
}
public function setCreated ( \DateTimeInterface $created ) : self
2021-07-30 02:26:14 +09:00
{
$this -> created = $created ;
return $this ;
}
2021-07-30 02:47:58 +09:00
public function getCreated () : \DateTimeInterface
2021-07-30 02:26:14 +09:00
{
return $this -> created ;
}
// @codeCoverageIgnoreEnd
// }}} Autocode
2021-08-19 01:30:02 +09:00
// {{{ Interface
// @codeCoverageIgnoreStart
2021-07-30 02:26:14 +09:00
public function __construct ( object $user , \DateTimeInterface $expiresAt , string $selector , string $hashedToken )
{
$this -> user_id = $user -> getId ();
$this -> expires = $expiresAt ;
$this -> selector = $selector ;
$this -> token = $hashedToken ;
}
public function getUser () : object
{
return LocalUser :: getWithPK ( $this -> user_id );
}
public function getRequestedAt () : \DateTimeInterface
{
return $this -> created ;
}
public function isExpired () : bool
{
return $this -> expires -> getTimestamp () <= time ();
}
public function getExpiresAt () : \DateTimeInterface
{
return $this -> expires ;
}
public function getHashedToken () : string
{
return $this -> token ;
}
2021-08-19 01:30:02 +09:00
// @codeCoverageIgnoreEnd
// }}}
2021-07-30 02:26:14 +09:00
public static function schemaDef () : array
{
return [
'name' => 'reset_password_request' ,
'description' => 'Represents a request made by a user to change their passowrd' ,
'fields' => [
'id' => [ 'type' => 'serial' , 'not null' => true ],
'user_id' => [ 'type' => 'int' , 'foreign key' => true , 'target' => 'LocalUser.id' , 'multiplicity' => 'many to many' , 'not null' => true , 'description' => 'foreign key to local_user table' ],
'selector' => [ 'type' => 'char' , 'length' => 20 ],
'token' => [ 'type' => 'char' , 'length' => 100 ],
'expires' => [ 'type' => 'datetime' , 'not null' => true ],
'created' => [ 'type' => 'datetime' , 'not null' => true , 'default' => 'CURRENT_TIMESTAMP' , 'description' => 'date this record was created' ],
],
'primary key' => [ 'id' ],
];
}
}