This commit is contained in:
count-null 2025-02-25 19:21:31 -05:00
parent 27df1a73b5
commit a0cb5fb6b0
36 changed files with 1886 additions and 187 deletions

View file

@ -3,6 +3,7 @@ namespace app\controllers;
use app\models\addresses;
use app\models\users;
use app\models\emails;
use app\models\user_addresses;
use app\models\magic_links;
@ -138,6 +139,49 @@ class account
}
}
public static function verify($defaults)
{
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$code = $_POST['code'];
$link = magic_links::validateCode($code);
if ($link) {
$user = $link['user_id'] ? users::getById($link['user_id']) : users::getByEmail($link['email']);
if ($user) {
$_SESSION['user_email'] = $link['email'];
$_SESSION['user_id'] = $user['id'];
if (!$user['verified']) {
users::verify($link['email']);
}
header('Location: /account');
exit;
} else {
$_SESSION['user_email'] = $link['email'];
header('Location: /account/signup');
exit;
}
} else {
$_SESSION['error'] = "Invalid or expired verification code.";
header('Location: /account/verify');
exit;
}
}
echo $GLOBALS['twig']->render('lib/page/index.twig', array_merge($defaults, [
'child_template' => 'account/verify.twig',
'page_title' => $_ENV['APP_NAME'],
'breadcrumbs' => [
[
'url' => '/account',
'title' => 'My Account'
],
[
'url' => null,
'title' => 'Verify'
]
]
]));
}
public static function login($defaults)
{
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
@ -148,7 +192,7 @@ class account
exit;
} else {
$token = magic_links::add($email, null);
header('Location: /account/login');
header('Location: /account/verify');
exit;
}
}
@ -339,6 +383,7 @@ class account
$verified,
$dark_theme
);
emails::updateUserIdByEmail($email, $user_id);
user_addresses::add(
user_id: $user_id,
address_id: $ship_id