Skip to content

Commit

Permalink
Merge pull request #26 from lankaixi/master
Browse files Browse the repository at this point in the history
modified userresettokenmapper
  • Loading branch information
Saeven authored Jul 20, 2017
2 parents 904842a + aab27d2 commit 869b8bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/CirclicalUser/Entity/UserResetToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class UserResetToken implements UserResetTokenInterface

/**
* @var string
* @ORM\Column(type="string", length=255)
* @ORM\Column(type="string", length=2048)
*/
private $token;

Expand Down Expand Up @@ -100,6 +100,11 @@ public function getToken(): string
return $this->token;
}

public function getId(): int
{
return $this->id;
}

public function setStatus(int $status)
{
if (!in_array($status, [UserResetTokenInterface::STATUS_UNUSED, UserResetTokenInterface::STATUS_INVALID, UserResetTokenInterface::STATUS_USED], true)) {
Expand All @@ -110,6 +115,7 @@ public function setStatus(int $status)

public function isValid(AuthenticationRecordInterface $authenticationRecord, string $checkToken, string $requestingIpAddress, bool $validateFingerprint, bool $validateIp): bool
{

if ($this->token !== $checkToken) {
return false;
}
Expand Down Expand Up @@ -146,7 +152,7 @@ public function isValid(AuthenticationRecordInterface $authenticationRecord, str
}
}

return false;
return true;

}
}
11 changes: 8 additions & 3 deletions src/CirclicalUser/Mapper/UserResetTokenMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getRequestCount(AuthenticationRecordInterface $authenticationRec
$fiveMinutesAgo->modify('-5 minutes');

$query = $this->getRepository()->createQueryBuilder('r')
->select('COUNT(*) AS total')
->select('COUNT(r.id) AS total')
->where('r.authentication = :authentication')
->andWhere('r.request_time > :since')
->setParameter('authentication', $authenticationRecord)
Expand Down Expand Up @@ -68,8 +68,13 @@ public function invalidateUnusedTokens(AuthenticationRecordInterface $authentica
->update()
->set('r.status', UserResetTokenInterface::STATUS_INVALID)
->where('r.authentication = :authentication')
->andWhere('r.status', UserResetTokenInterface::STATUS_UNUSED)
->setParameter('authentication', $authenticationRecord)
->andWhere('r.status = :status_unused')
->setParameters(
[
'authentication' => $authenticationRecord,
'status_unused' => UserResetTokenInterface::STATUS_UNUSED,
]
)
->getQuery();

$query->execute();
Expand Down

0 comments on commit 869b8bc

Please sign in to comment.