52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/includes/bootstrap.php';
|
|
|
|
$error = '';
|
|
$returnPath = website_safe_return_path((string)($_GET['return'] ?? $_POST['return'] ?? $_SESSION['website_login_return'] ?? 'account.php'), 'account.php');
|
|
|
|
if (website_is_logged_in()) {
|
|
if ($returnPath === 'panel') {
|
|
header('Location: ' . website_control_panel_url(), true, 302);
|
|
exit;
|
|
}
|
|
header('Location: ' . website_url($returnPath), true, 302);
|
|
exit;
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$login = trim((string)($_POST['login'] ?? ''));
|
|
$password = (string)($_POST['password'] ?? '');
|
|
$user = website_authenticate_user($login, $password);
|
|
|
|
if ($user) {
|
|
website_set_user_session($user);
|
|
website_log_activity('Website login succeeded for ' . (string)$user['users_login'], (int)$user['user_id'], 'website_login_success');
|
|
unset($_SESSION['website_login_return']);
|
|
|
|
if ($returnPath === 'panel') {
|
|
header('Location: ' . website_control_panel_url(), true, 302);
|
|
exit;
|
|
}
|
|
|
|
header('Location: ' . website_url($returnPath), true, 302);
|
|
exit;
|
|
}
|
|
|
|
website_log_activity('Website login failed for ' . $login, 0, 'website_login_failure');
|
|
$error = 'Invalid username or password.';
|
|
}
|
|
|
|
website_render(
|
|
'login.php',
|
|
[
|
|
'activePage' => 'account',
|
|
'pageTitle' => 'Account Login - Gameservers.World',
|
|
'metaDescription' => 'Log in to your Gameservers.World account.',
|
|
'canonicalPath' => 'login.php',
|
|
'error' => $error,
|
|
'returnPath' => $returnPath,
|
|
]
|
|
);
|