Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -238,40 +238,24 @@ public function createAuthenticationForm(IFormDocument $form, Setup $setup): voi
*/
public function processAuthenticationForm(IFormDocument $form, Setup $setup): void
{
$userCode = $form->getData()['data']['code'];

$sql = "SELECT code
FROM wcf1_user_multifactor_email
WHERE setupID = ?
AND createTime > ?
FOR UPDATE";
$statement = WCF::getDB()->prepare($sql);
$statement->execute([
$this->invalidateUsedCode(
$setup->getId(),
(\TIME_NOW - self::LIFETIME),
]);
$codes = $statement->fetchAll(\PDO::FETCH_ASSOC);

$usedCode = $this->findValidCode($userCode, $codes);

if ($usedCode === null) {
throw new \RuntimeException('Unable to find a valid code.');
}
$form->getData()['data']['code']
);
}

private function invalidateUsedCode(int $id, string $code): void
{
$sql = "DELETE FROM wcf1_user_multifactor_email
WHERE setupID = ?
AND createTime > ?
AND code = ?";
$statement = WCF::getDB()->prepare($sql);
$statement->execute([
$setup->getId(),
$id,
(\TIME_NOW - self::LIFETIME),
$usedCode['code'],
$code,
]);

if ($statement->getAffectedRows() !== 1) {
throw new \RuntimeException('Unable to invalidate the code.');
}
}

/**
Expand Down