-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auth: Implement account verification by token
- Loading branch information
Showing
6 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE `registration_verification` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`user_id` int(11) DEFAULT NULL, | ||
`token` varchar(255) DEFAULT NULL, | ||
PRIMARY KEY (`id`), | ||
KEY `user_id` (`user_id`), | ||
CONSTRAINT `registration_verification_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/Frontend/Authentication/VerifyRegistrationController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace A11yBuddy\Frontend\Authentication; | ||
|
||
use A11yBuddy\Application; | ||
use A11yBuddy\Frontend\BasePage\NotFoundController; | ||
use A11yBuddy\Frontend\Controller; | ||
|
||
class VerifyRegistrationController extends Controller | ||
{ | ||
|
||
public function run(array $data = []): void | ||
{ | ||
$db = Application::getInstance()->getDatabase(); | ||
|
||
$result = $db->query('SELECT * FROM registration_verification WHERE token = :token', [':token' => $data['token']]); | ||
|
||
$result = $result->fetch(\PDO::FETCH_ASSOC); | ||
|
||
// If the token is not found, show an error message. | ||
if ($result === false) { | ||
$nf = new NotFoundController(); | ||
$nf->run(); | ||
} else { | ||
// If the token is found, update the user's status to verified. | ||
$db->query('UPDATE users SET status = 1 WHERE id = :id', [':id' => $result['user_id']]); | ||
// Delete the token from the database. | ||
$db->query('DELETE FROM registration_verification WHERE token = :token', [':token' => $data['token']]); | ||
?> | ||
<h1>Registration Verified</h1> | ||
<p>Your registration has been verified. You can now log in to your account.</p> | ||
<a href="/login">Log In</a> | ||
<?php | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters