v1.2 initial commit
This commit is contained in:
15733
pub/login/css/style.css
Normal file
15733
pub/login/css/style.css
Normal file
File diff suppressed because it is too large
Load Diff
15733
pub/login/css/style.full.css
Normal file
15733
pub/login/css/style.full.css
Normal file
File diff suppressed because it is too large
Load Diff
1
pub/login/css/style.min.css
vendored
Normal file
1
pub/login/css/style.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
120
pub/login/forgotPassword.php
Normal file
120
pub/login/forgotPassword.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
session_start();
|
||||
if (isset($_SESSION['user']['user_uuid'])) {
|
||||
header('Location: /');
|
||||
exit;
|
||||
}
|
||||
|
||||
include_once $_SERVER['DOCUMENT_ROOT'] . '/login/php/authFunctions.php';
|
||||
$loginAttempts = checkLoginAttempts();
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html data-coreui-theme="dark" lang="en">
|
||||
<head>
|
||||
<base href="./">
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
|
||||
<meta name="description" content="Sentri - Configure phone configs">
|
||||
<meta name="author" content="Marco Mooij">
|
||||
<meta name="keyword" content="sentri">
|
||||
<title>Sentri | Login</title>
|
||||
|
||||
<!-- favicon -->
|
||||
<link rel="icon" type="image/png" href="/src/images/favicon/favicon-96x96.png" sizes="96x96">
|
||||
<link rel="icon" type="image/svg+xml" href="/src/images/favicon/favicon-96x96.png">
|
||||
<link rel="shortcut icon" href="/src/images/favicon/favicon.ico">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/src/images/favicon/apple-touch-icon.png">
|
||||
<link rel="manifest" href="/src/images/favicon/site.webmanifest">
|
||||
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #1d222b;
|
||||
}
|
||||
|
||||
.portal-image {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
aspect-ratio: 3 / 1;
|
||||
object-fit: contain;
|
||||
display: block;
|
||||
min-height: 200px; /* Prevent layout shift during image load */
|
||||
}
|
||||
|
||||
#code-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.code-input {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
font-size: 24px;
|
||||
text-align: center;
|
||||
margin: 5px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<link rel="stylesheet" href="css/style.full.css" as="style">
|
||||
</head>
|
||||
<body>
|
||||
<div class="bg-body-tertiary min-vh-100 d-flex flex-row align-items-center">
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-8 col-md-10 col-12 d-flex align-items-center justify-content-center">
|
||||
<div class="card-group d-block d-md-flex row">
|
||||
<div class="card col-md-7 mb-0">
|
||||
<div class="card-body p-3">
|
||||
<div class="card-body justify-content-center align-items-center">
|
||||
<?php if (isset($_GET['result'])) {
|
||||
if ($_GET['result'] == "success") { ?>
|
||||
<h1 class="">Request sent!</h1>
|
||||
<p class="">If an account with that email address exists, we’ve sent a password reset link to your inbox. Please check your email.</p>
|
||||
<hr>
|
||||
<a href="/login/" class="btn btn-primary px-4">
|
||||
<i class="fa-solid fa-check"></i> Go to login
|
||||
</a>
|
||||
<?php } elseif ($_GET['result'] == "failed") { ?>
|
||||
<h1 class="text-center">Something went wrong :(</h1>
|
||||
<p class="text-center">Something went wrong in requesting your forgotten password. Please contact support!</p>
|
||||
<?php } elseif ($_GET['result'] == "blocked") { ?>
|
||||
<h1 class="text-center">Blocked</h1>
|
||||
<p class="text-center">You’ve been temporarily blocked after multiple failed login attempts. Please try again later or contact support.</p>
|
||||
<?php } ?>
|
||||
<?php } else { ?>
|
||||
<h1>Forgot password</h1>
|
||||
<p>Enter your email and we’ll send you a reset link.</p>
|
||||
<hr>
|
||||
<form method="post" action="/login/php/forgotPasswordRequest.php">
|
||||
<div class="mb-3 text-reset">
|
||||
<label for="email" class="form-label">Email</label>
|
||||
<input type="email" class="form-control" name="user_email" id="email" placeholder="somebody@somewhere.what" required>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary w-100" id="submitBtn">
|
||||
<i class="fa-solid fa-envelope"></i> Request email
|
||||
</button>
|
||||
</form>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card col-md-5 text-white bg-transparent py-5">
|
||||
<div class="card-body text-center pt-5">
|
||||
<div>
|
||||
<img class="pt-3 w-100 portal-image" alt="portal-image" src="/src/images/logo-login-dark.webp" width="500" height="265" style="height: auto;">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
||||
</body>
|
||||
</html>
|
||||
166
pub/login/index.php
Normal file
166
pub/login/index.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
session_start();
|
||||
include_once $_SERVER['DOCUMENT_ROOT'] . '/login/php/authFunctions.php';
|
||||
|
||||
if (isset($_SESSION['user'])) {
|
||||
header('location: /');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($loginAttemptCount = checkLoginAttempts() > 3) {
|
||||
setcookie('login_error', 'Too many failed login attempts, please try again later.', time() + 3600, '/');
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html data-coreui-theme="dark" lang="en">
|
||||
<head>
|
||||
<base href="./">
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
|
||||
<meta name="description" content="Sentri - Configure phone configs">
|
||||
<meta name="author" content="Marco Mooij">
|
||||
<meta name="keyword" content="sentri">
|
||||
<title>Sentri | Login</title>
|
||||
|
||||
<!-- favicon -->
|
||||
<link rel="icon" type="image/png" href="/src/images/favicon/favicon-96x96.png" sizes="96x96">
|
||||
<link rel="icon" type="image/svg+xml" href="/src/images/favicon/favicon-96x96.png">
|
||||
<link rel="shortcut icon" href="/src/images/favicon/favicon.ico">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/src/images/favicon/apple-touch-icon.png">
|
||||
<link rel="manifest" href="/src/images/favicon/site.webmanifest">
|
||||
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #1d222b;
|
||||
}
|
||||
|
||||
.portal-image {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
aspect-ratio: 3 / 1;
|
||||
object-fit: contain;
|
||||
display: block;
|
||||
min-height: 200px; /* Prevent layout shift during image load */
|
||||
}
|
||||
|
||||
#code-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.code-input {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
font-size: 24px;
|
||||
text-align: center;
|
||||
margin: 5px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<link rel="stylesheet" href="css/style.full.css" as="style">
|
||||
</head>
|
||||
<body>
|
||||
<div class="bg-body-tertiary min-vh-100 d-flex flex-row align-items-center">
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-8 col-md-8 col-12 d-flex align-items-center justify-content-center">
|
||||
<div class="card-group d-block d-md-flex row">
|
||||
<div class="card col-md-7 mb-0">
|
||||
<div class="card-body p-3">
|
||||
<?php if (isset($_COOKIE['loggedout'])) { ?>
|
||||
<div class="row mt-0 pt-0">
|
||||
<div class="col">
|
||||
<div class="card bg-success">
|
||||
<div class="card-body">
|
||||
<i class="fa-solid fa-right-from-bracket"></i> You have been logged out successfully!
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php setcookie('loggedout', '', time() - 3600, '/');
|
||||
}
|
||||
|
||||
if (isset($_COOKIE['login_error'])) { ?>
|
||||
<div class="row mt-0 pt-0">
|
||||
<div class="col">
|
||||
<div class="card bg-danger">
|
||||
<div class="card-body">
|
||||
<i class="fa-solid fa-triangle-exclamation"></i> <?php echo $_COOKIE['login_error']; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php setcookie('login_error', '', time() - 3600, '/'); ?><?php }
|
||||
|
||||
if (($loginAttemptCount <= 3)) {
|
||||
if (!isset($_SESSION['mfa'])) { ?>
|
||||
<form method="post" action="/login/php/auth.php">
|
||||
<h1>Login</h1>
|
||||
<p class="text-body-secondary">Login with your account</p>
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text"><i class="fa-solid fa-user"></i></span>
|
||||
<input name="username" class="form-control" type="text" placeholder="Username">
|
||||
</div>
|
||||
<div class="input-group mb-4">
|
||||
<span class="input-group-text"><i class="fa-solid fa-lock"></i></span>
|
||||
<input name="password" class="form-control" type="password" placeholder="Password">
|
||||
</div>
|
||||
<div class="row pb-1">
|
||||
<div class="col-auto">
|
||||
<button class="btn btn-primary px-4" type="submit">
|
||||
<i class="fa-solid fa-right-to-bracket"></i> Login
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-6 text-end">
|
||||
<a class="btn btn-link px-0" type="button" href="/login/forgotPassword.php">Forgot password?</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<?php } else { ?>
|
||||
<div class="card-body text-center justify-content-center align-items-center">
|
||||
<h1>Verification code</h1>
|
||||
<form method="post" action="/login/php/mfaAuth.php">
|
||||
<h5>Enter code from your app:</h5>
|
||||
<div class="mb-3">
|
||||
<div id="code-container">
|
||||
<input name="verification-1" type="text" maxlength="1" class="code-input" autocomplete="off" autofocus>
|
||||
<input name="verification-2" type="text" maxlength="1" class="code-input" autocomplete="off">
|
||||
<input name="verification-3" type="text" maxlength="1" class="code-input" autocomplete="off">
|
||||
<input name="verification-4" type="text" maxlength="1" class="code-input" autocomplete="off">
|
||||
<input name="verification-5" type="text" maxlength="1" class="code-input" autocomplete="off">
|
||||
<input name="verification-6" type="text" maxlength="1" class="code-input" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-primary px-4" type="submit">
|
||||
<i class="fa-solid fa-certificate"></i> Verify
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php } ?><?php } else { ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
Too many failed login attempts, please try again later.
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card col-md-5 text-white bg-transparent py-5">
|
||||
<div class="card-body text-center pt-3">
|
||||
<div>
|
||||
<img class="pt-3 w-100 portal-image" alt="portal-image" src="/src/images/logo-login-dark.webp" width="500" height="265" style="height: auto;">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
||||
<script src="/login/js/mfa.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
41
pub/login/js/mfa.js
Normal file
41
pub/login/js/mfa.js
Normal file
@@ -0,0 +1,41 @@
|
||||
const inputs = document.querySelectorAll('.code-input');
|
||||
const form = document.querySelector('form');
|
||||
|
||||
inputs.forEach((input, index) => {
|
||||
input.addEventListener('input', (e) => {
|
||||
// Allow only numbers
|
||||
let value = e.target.value.replace(/\D/g, ''); // Remove non-digits
|
||||
|
||||
// Only set the cleaned value (in case user pasted multiple)
|
||||
e.target.value = value;
|
||||
|
||||
if (value.length === 1) {
|
||||
if (index < inputs.length - 1) {
|
||||
inputs[index + 1].focus();
|
||||
} else {
|
||||
form.submit(); // Submit form when last input is filled
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
input.addEventListener('keydown', (e) => {
|
||||
if (e.key === "Backspace" && !e.target.value && index > 0) {
|
||||
inputs[index - 1].focus();
|
||||
}
|
||||
});
|
||||
|
||||
input.addEventListener('paste', (e) => {
|
||||
e.preventDefault();
|
||||
const pasteData = (e.clipboardData || window.clipboardData).getData('text');
|
||||
const digits = pasteData.replace(/\D/g, '').substring(0, inputs.length);
|
||||
digits.split('').forEach((char, i) => {
|
||||
inputs[i].value = char;
|
||||
});
|
||||
|
||||
if (digits.length === inputs.length) {
|
||||
form.submit(); // Submit form if paste fills all inputs
|
||||
} else {
|
||||
inputs[digits.length].focus();
|
||||
}
|
||||
});
|
||||
});
|
||||
28
pub/login/logout.php
Normal file
28
pub/login/logout.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (isset($_POST['logout'])) {
|
||||
// Clear session data
|
||||
$_SESSION = array();
|
||||
|
||||
// Delete the session cookie
|
||||
if (ini_get("session.use_cookies")) {
|
||||
$params = session_get_cookie_params();
|
||||
setcookie(session_name(), '', time() - 3600,
|
||||
$params["path"], $params["domain"],
|
||||
$params["secure"], $params["httponly"]
|
||||
);
|
||||
}
|
||||
|
||||
session_destroy();
|
||||
|
||||
// Set "logged out" indicator cookie
|
||||
setcookie('loggedout', '1', time() + 3600, '/');
|
||||
|
||||
// Redirect to login
|
||||
header('Location: /login/');
|
||||
exit;
|
||||
} else {
|
||||
header('Location: /');
|
||||
exit;
|
||||
}
|
||||
130
pub/login/mfaSetup.php
Normal file
130
pub/login/mfaSetup.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
require $_SERVER['DOCUMENT_ROOT'] . '/../vendor/autoload.php';
|
||||
include_once $_SERVER['DOCUMENT_ROOT'] . '/login/php/authFunctions.php';
|
||||
|
||||
|
||||
use RobThree\Auth\TwoFactorAuth;
|
||||
use RobThree\Auth\Providers\Qr\EndroidQrCodeWithLogoProvider;
|
||||
|
||||
# check if user sessions exists
|
||||
if (!isset($_SESSION['user']['user_uuid'])) {
|
||||
header('Location: /');
|
||||
exit;
|
||||
}
|
||||
|
||||
# update the user session params
|
||||
setSessionParams();
|
||||
|
||||
# if 2fa is already set, go fuck yourself
|
||||
if ($_SESSION['user']['user_two_factor_enabled'] == 1) {
|
||||
header('Location: /userprofile/');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (checkLoginAttempts() > 10) {
|
||||
echo 'too many attempts, please try again later.';
|
||||
exit;
|
||||
}
|
||||
|
||||
# Init vars
|
||||
$tfa = new TwoFactorAuth(new EndroidQrCodeWithLogoProvider());
|
||||
$secret = $tfa->createSecret('160');
|
||||
$_SESSION['mfasetup']['secret'] = $secret;
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html data-coreui-theme="dark" lang="en">
|
||||
<head>
|
||||
<base href="./">
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
|
||||
<meta name="description" content="Sentri - Operations centre">
|
||||
<meta name="author" content="Marco Mooij">
|
||||
<meta name="keyword" content="sentri">
|
||||
<title>Sentri | Login</title>
|
||||
|
||||
<!-- favicon -->
|
||||
<link rel="icon" type="image/png" href="/src/images/favicon/favicon-96x96.png" sizes="96x96">
|
||||
<link rel="icon" type="image/svg+xml" href="/src/images/favicon/favicon-96x96.png">
|
||||
<link rel="shortcut icon" href="/src/images/favicon/favicon.ico">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/src/images/favicon/apple-touch-icon.png">
|
||||
<link rel="manifest" href="/src/images/favicon/site.webmanifest">
|
||||
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #1d222b;
|
||||
}
|
||||
|
||||
.portal-image {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
aspect-ratio: 3 / 1;
|
||||
object-fit: contain;
|
||||
display: block;
|
||||
min-height: 200px; /* Prevent layout shift during image load */
|
||||
}
|
||||
|
||||
.code-input {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
font-size: 24px;
|
||||
text-align: center;
|
||||
margin: 5px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<link rel="stylesheet" href="css/style.full.css" as="style">
|
||||
</head>
|
||||
<body>
|
||||
<div class="bg-body-tertiary min-vh-100 d-flex flex-row align-items-center">
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-8 col-md-8 col-12 d-flex align-items-center justify-content-center">
|
||||
<div class="card-group d-block d-md-flex row">
|
||||
<div class="card col-md-6 text-white bg-transparent">
|
||||
<div class="card-body text-center">
|
||||
<h2>Step 1.</h2>
|
||||
<small>Scan this code with your authentication app:</small><br><br>
|
||||
<img class=" w-100 portal-image" alt="portal-image" src="<?php echo $tfa->getQRCodeImageAsDataUri('Sentri - ' . $_SESSION['user']['user_first_name'], $secret); ?>">
|
||||
<br>
|
||||
<small class="">Or enter this code in your app:<br>
|
||||
<b><?php echo $secret ?></b></small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card col-md-6 mb-0">
|
||||
<form method="post" action="/api/v1/users/mfa/">
|
||||
<input type="hidden" name="_return" value="/userprofile/">
|
||||
<div class="card-body text-center">
|
||||
<h2>Step 2.</h2>
|
||||
<small>Enter the code from your authentication app:</small><br>
|
||||
<div class="input-group mb-3">
|
||||
<div id="code-container">
|
||||
<input name="verification-1" type="text" maxlength="1" class="code-input" autocomplete="off" autofocus>
|
||||
<input name="verification-2" type="text" maxlength="1" class="code-input" autocomplete="off">
|
||||
<input name="verification-3" type="text" maxlength="1" class="code-input" autocomplete="off">
|
||||
<input name="verification-4" type="text" maxlength="1" class="code-input" autocomplete="off">
|
||||
<input name="verification-5" type="text" maxlength="1" class="code-input" autocomplete="off">
|
||||
<input name="verification-6" type="text" maxlength="1" class="code-input" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-primary px-4" type="submit">
|
||||
<i class="fa-solid fa-certificate"></i> Verify
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
||||
<script src="/login/js/mfa.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
84
pub/login/php/auth.php
Normal file
84
pub/login/php/auth.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
include_once $_SERVER['DOCUMENT_ROOT'] . '/login/php/authFunctions.php';
|
||||
|
||||
if (checkLoginAttempts() > 3) {
|
||||
header('Location: /login/');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$username = trim($_POST['username'] ?? '');
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
if (empty($username) || empty($password)) {
|
||||
die("Username and password are required.");
|
||||
}
|
||||
|
||||
if ($username !== 'superuser' && !filter_var($username, FILTER_VALIDATE_EMAIL)) {
|
||||
die("Invalid email address.");
|
||||
}
|
||||
|
||||
$stmt = $GLOBALS['conn']->prepare("SELECT * FROM vc_users WHERE user_email = ? LIMIT 1");
|
||||
$stmt->bind_param('s', $username);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$user = $result->fetch_assoc();
|
||||
|
||||
if (!$user) {
|
||||
setcookie('login_error', 'Invalid username or password', time() + 3600, '/');
|
||||
addLoginAttempts();
|
||||
header('Location: /login/');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!password_verify($password, $user['user_password'])) {
|
||||
setcookie('login_error', 'Invalid username or password', time() + 3600, '/');
|
||||
addLoginAttempts();
|
||||
header('Location: /login/');
|
||||
exit;
|
||||
}
|
||||
|
||||
switch ($user['user_status']) {
|
||||
case 'banned':
|
||||
setcookie('login_error', 'Account is banned.', time() + 3600, '/');
|
||||
header('Location: /login/');
|
||||
exit;
|
||||
case 'inactive':
|
||||
setcookie('login_error', 'Account is inactive.', time() + 3600, '/');
|
||||
header('Location: /login/');
|
||||
exit;
|
||||
case 'pending':
|
||||
setcookie('login_error', 'Account is pending approval.', time() + 3600, '/');
|
||||
header('Location: /login/');
|
||||
exit;
|
||||
case 'active':
|
||||
// continue
|
||||
break;
|
||||
default:
|
||||
setcookie('login_error', 'something went wrong, contact support', time() + 3600, '/');
|
||||
header('Location: /login/');
|
||||
exit;
|
||||
}
|
||||
|
||||
setTimeZoneCookie();
|
||||
|
||||
# check if mfa2 is enabled
|
||||
if ($user['user_two_factor_enabled'] == 1) {
|
||||
# go to the mfa login
|
||||
session_regenerate_id(true); # create session to store some data
|
||||
$_SESSION['mfa'] = ['user_uuid' => $user['user_uuid'], 'user_secret' => $user['user_two_factor_secret']];
|
||||
header('Location: /login/');
|
||||
exit;
|
||||
} else {
|
||||
# No mfa2 is setup
|
||||
|
||||
loginUser($user['user_uuid']);
|
||||
header('Location: /');
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
118
pub/login/php/authFunctions.php
Normal file
118
pub/login/php/authFunctions.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
include_once $_SERVER['DOCUMENT_ROOT'] . '/bin/php/db_connect.php';
|
||||
function checkLoginAttempts()
|
||||
{
|
||||
$stmt = $GLOBALS['conn']->prepare("SELECT address
|
||||
FROM ip_login_attempts
|
||||
WHERE address LIKE ?
|
||||
AND timestamp > (UNIX_TIMESTAMP() - 600)
|
||||
");
|
||||
$stmt->bind_param('s', $_SERVER['REMOTE_ADDR']);
|
||||
$stmt->execute();
|
||||
$stmt->store_result();
|
||||
return $stmt->num_rows;
|
||||
}
|
||||
|
||||
function addLoginAttempts()
|
||||
{
|
||||
$ip = $_SERVER["REMOTE_ADDR"];
|
||||
$stmt = $GLOBALS['conn']->prepare("INSERT INTO ip_login_attempts (address, timestamp) VALUES (?, UNIX_TIMESTAMP())");
|
||||
$stmt->bind_param('s', $ip);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
function setTimeZoneCookie()
|
||||
{
|
||||
?>
|
||||
<script>
|
||||
document.cookie = "user_timezone=" + Intl.DateTimeFormat().resolvedOptions().timeZone + "; path=/";
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
function getUserTimezone()
|
||||
{
|
||||
$default_timezone = 'America/New_York';
|
||||
if (isset($_COOKIE['user_timezone']) && in_array($_COOKIE['user_timezone'], DateTimeZone::listIdentifiers())) {
|
||||
$timezone = $_COOKIE['user_timezone'];
|
||||
} else {
|
||||
$timezone = $default_timezone;
|
||||
}
|
||||
|
||||
return $timezone;
|
||||
}
|
||||
|
||||
function setSessionParams()
|
||||
{
|
||||
if (isset($_SESSION['user']['user_uuid'])) {
|
||||
$user_uuid = $_SESSION['user']['user_uuid'];
|
||||
$stmt = $GLOBALS['conn']->prepare("SELECT * FROM vc_users INNER JOIN vc_user_groups ON vc_users.user_group_uuid = vc_user_groups.user_group_uuid WHERE user_uuid = ? LIMIT 1");
|
||||
$stmt->bind_param('s', $user_uuid);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$user = $result->fetch_assoc();
|
||||
|
||||
$_SESSION['user'] = ['user_uuid' => $user['user_uuid'],
|
||||
'user_email' => $user['user_email'],
|
||||
'user_first_name' => $user['user_first_name'],
|
||||
'user_full_name' => $user['user_full_name'],
|
||||
'user_group_uuid' => $user['user_group_uuid'],
|
||||
'user_group_weight' => $user['user_group_weight'],
|
||||
'user_group_type' => $user['user_group_type'],
|
||||
'user_pref_language' => $user['user_pref_language'],
|
||||
'user_two_factor_enabled' => $user['user_two_factor_enabled'],
|
||||
'user_profile_picture' => $user['user_profile_picture'],
|
||||
'user_profile_picture_thumbnail' => $user['user_profile_picture_thumbnail'],
|
||||
'user_timezone' => getUserTimezone(),
|
||||
];
|
||||
|
||||
$stmt = $GLOBALS['conn']->prepare("SELECT vc_user_group_permissions_portal.permission_value, vc_permissions.permission_name
|
||||
FROM vc_user_group_permissions_portal
|
||||
INNER JOIN vc_permissions ON vc_user_group_permissions_portal.permission_uuid = vc_permissions.permission_uuid
|
||||
WHERE user_group_uuid = ?");
|
||||
$stmt->bind_param('s', $user['user_group_uuid']);
|
||||
$_SESSION['permission'] = array();
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$_SESSION['permission'][$row['permission_name']] = $row['permission_value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loginUser($user_uuid)
|
||||
{
|
||||
$update = $GLOBALS['conn']->prepare("UPDATE vc_users SET user_last_login_timestamp = ? WHERE user_uuid = ?");
|
||||
$update->bind_param('is', time(), $user_uuid);
|
||||
$update->execute();
|
||||
|
||||
session_regenerate_id(true);
|
||||
|
||||
$_SESSION['user'] = ['user_uuid' => $user_uuid];
|
||||
|
||||
setSessionParams();
|
||||
}
|
||||
|
||||
# link the verification code input and check if its an valid code.
|
||||
function linkVerificationPosts()
|
||||
{
|
||||
$codeParts = [];
|
||||
$allSet = true;
|
||||
for ($i = 1; $i <= 6; $i++) {
|
||||
$key = 'verification-' . $i;
|
||||
if (isset($_POST[$key]) && $_POST[$key] !== '') {
|
||||
$codeParts[] = $_POST[$key];
|
||||
} else {
|
||||
$allSet = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($allSet) {
|
||||
return implode('', $codeParts);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
87
pub/login/php/forgotPasswordRequest.php
Normal file
87
pub/login/php/forgotPasswordRequest.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
use bin\php\Classes\mailBuilder;
|
||||
|
||||
if (!isset($_POST['user_email'])) {
|
||||
header('Location: /');
|
||||
exit;
|
||||
}
|
||||
|
||||
include_once $_SERVER['DOCUMENT_ROOT'] . '/login/php/authFunctions.php';
|
||||
include_once $_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/mailBuilder.php';
|
||||
|
||||
|
||||
$loginAttempts = checkLoginAttempts();
|
||||
|
||||
if ($loginAttempts > 5) {
|
||||
header('location: /login/forgotPassword.php?result=blocked');
|
||||
exit;
|
||||
}
|
||||
|
||||
$user_email = $_POST['user_email'];
|
||||
|
||||
$sql = "SELECT * FROM vc_users WHERE user_email = ?";
|
||||
$stmt = $GLOBALS['conn']->prepare($sql);
|
||||
$stmt->bind_param("s", $user_email);
|
||||
if (!$stmt->execute()) {
|
||||
header('location: /login/forgotPassword.php?result=failed');
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$user_data = $result->fetch_assoc();
|
||||
|
||||
if ($result->num_rows == 0) {
|
||||
header('location: /login/forgotPassword.php?result=success');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($user_data['user_status'] != 'active') {
|
||||
header('location: /login/forgotPassword.php?result=success');
|
||||
exit;
|
||||
}
|
||||
|
||||
$user_uuid = $user_data["user_uuid"];
|
||||
$user_password_reset_token = bin2hex(random_bytes(32));
|
||||
$user_password_reset_expires = time() + 86400;
|
||||
|
||||
$sql = "UPDATE vc_users SET user_password_reset_token = ?, user_password_reset_expires = ? WHERE user_uuid = ?";
|
||||
$stmt = $GLOBALS['conn']->prepare($sql);
|
||||
$stmt->bind_param("sss",
|
||||
$user_password_reset_token,
|
||||
$user_password_reset_expires,
|
||||
$user_uuid
|
||||
);
|
||||
|
||||
|
||||
# Sending an email to the user
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
$verifyLink = "https://{$host}/login/resetPassword.php?token={$user_password_reset_token}";
|
||||
|
||||
$mail = new mailBuilder();
|
||||
$mail->subject = "Hello " . $user_data['user_full_name'] . ", Here’s Your Password Reset Link";
|
||||
$mail->addAddress($user_data['user_email'], $user_data['user_first_name']);
|
||||
$mail->mailText = '
|
||||
Hello ' . $user_data['user_first_name'] . ',<br><br>
|
||||
|
||||
We received a request to reset the password for your account. You can reset your password by clicking the link below.<br>
|
||||
This link is valid for 24 hours from the time of this request:<br>
|
||||
<a href="' . $verifyLink . '" class="btn btn-primary">Reset Password</a><br><br>
|
||||
|
||||
Or copy and paste the following link into your browser: <br>' . $verifyLink . '<br><br>
|
||||
|
||||
If you did not request a password reset, you can safely ignore this message. No changes will be made to your account.<br><br>
|
||||
|
||||
Best regards,<br><br>
|
||||
The Sentri gnome behind the code
|
||||
';
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$mail->sendMail();
|
||||
addLoginAttempts(); # add login attempt to prevent spamming from the forgot password link
|
||||
header('location: /login/forgotPassword.php?result=success');
|
||||
} else {
|
||||
header('location: /login/forgotPassword.php?result=failed');
|
||||
}
|
||||
|
||||
exit;
|
||||
45
pub/login/php/mfaAuth.php
Normal file
45
pub/login/php/mfaAuth.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
# includes
|
||||
require $_SERVER['DOCUMENT_ROOT'] . '/../vendor/autoload.php';
|
||||
include_once $_SERVER['DOCUMENT_ROOT'] . '/login/php/authFunctions.php';
|
||||
|
||||
use RobThree\Auth\Providers\Qr\EndroidQrCodeWithLogoProvider;
|
||||
use RobThree\Auth\TwoFactorAuth;
|
||||
|
||||
if (!isset($_POST['verification-1']) && !isset($_SESSION['mfa']['user_secret']) && !isset($_SESSION['mfa']['user_uuid'])) {
|
||||
unset($_SESSION['mfa']);
|
||||
addLoginAttempts();
|
||||
header('Location: /');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (checkLoginAttempts() > 3) {
|
||||
header('Location: /login/');
|
||||
exit;
|
||||
}
|
||||
|
||||
$tfa = new TwoFactorAuth(new EndroidQrCodeWithLogoProvider());
|
||||
|
||||
$secret = $_SESSION['mfa']['user_secret'];
|
||||
$postedCode = linkVerificationPosts();
|
||||
|
||||
if ($postedCode) {
|
||||
$result = $tfa->verifyCode($secret, $postedCode);
|
||||
|
||||
if ($result) {
|
||||
loginUser($_SESSION['mfa']['user_uuid']);
|
||||
unset($_SESSION['mfa']);
|
||||
|
||||
} else {
|
||||
addLoginAttempts();
|
||||
setcookie('login_error', 'Invalid verification code', time() + 3600, '/');
|
||||
|
||||
}
|
||||
} else {
|
||||
unset($_SESSION['mfa']);
|
||||
|
||||
}
|
||||
header('Location: /');
|
||||
exit;
|
||||
69
pub/login/php/setPassword.php
Normal file
69
pub/login/php/setPassword.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
if ($_POST['password-1'] != $_POST['password-2']) {
|
||||
header('location: /login/resetPassword.php?result=failed');
|
||||
exit;
|
||||
}
|
||||
|
||||
include_once $_SERVER['DOCUMENT_ROOT'] . '/login/php/authFunctions.php';
|
||||
$user_password = password_hash($_POST['password-1'], PASSWORD_BCRYPT, ["cost" => 12]);
|
||||
|
||||
if (isset($_POST['user_uuid'])) {
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['user']['user_uuid'])) {
|
||||
header('location: /login/resetPassword.php?result=failed');
|
||||
exit;
|
||||
}
|
||||
|
||||
$user_uuid = $_SESSION['user']['user_uuid'];
|
||||
$sql = "UPDATE vc_users SET user_password = ?,
|
||||
user_password_reset_token = NULL,
|
||||
user_password_reset_expires = NULL
|
||||
WHERE user_uuid = ?";
|
||||
$userSql = "SELECT COUNT(*) FROM vc_users WHERE user_uuid = ?";
|
||||
$whereValue = $user_uuid;
|
||||
|
||||
} elseif (isset($_POST['user_password_reset_token'])) {
|
||||
$user_password_reset_token = $_POST['user_password_reset_token'];
|
||||
$sql = "UPDATE vc_users SET user_password = ?,
|
||||
user_password_reset_token = NULL,
|
||||
user_password_reset_expires = NULL,
|
||||
user_verified_email = 1,
|
||||
user_status = 'active'
|
||||
WHERE user_password_reset_token = ? AND user_status IN ('active', 'pending')";
|
||||
$userSql = "SELECT COUNT(*) FROM vc_users WHERE user_password_reset_token = ?";
|
||||
$whereValue = $user_password_reset_token;
|
||||
}
|
||||
|
||||
function checkUserExists($whereValue, $conn, $sql)
|
||||
{
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param("s", $whereValue);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($count);
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
return $count > 0;
|
||||
}
|
||||
|
||||
|
||||
if (!checkUserExists($whereValue, $GLOBALS['conn'], $userSql)) {
|
||||
header('location: /');
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $GLOBALS['conn']->prepare($sql);
|
||||
$stmt->bind_param("ss",
|
||||
$user_password,
|
||||
$whereValue
|
||||
);
|
||||
|
||||
|
||||
if ($stmt->execute()) {
|
||||
header('location: /login/resetPassword.php?result=success');
|
||||
exit;
|
||||
} else {
|
||||
header('location: /login/resetPassword.php?result=failed');
|
||||
exit;
|
||||
}
|
||||
195
pub/login/resetPassword.php
Normal file
195
pub/login/resetPassword.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($_GET['token']) && !isset($_GET['result']) && !isset($_SESSION['user']['user_uuid'])) {
|
||||
http_response_code(404);
|
||||
exit;
|
||||
}
|
||||
|
||||
include_once $_SERVER['DOCUMENT_ROOT'] . '/login/php/authFunctions.php';
|
||||
|
||||
|
||||
$tokenfound = false;
|
||||
if (isset($_GET['token'])) {
|
||||
$token = htmlspecialchars($_GET['token'], ENT_QUOTES, 'UTF-8');
|
||||
$stmt = $GLOBALS['conn']->prepare("SELECT * FROM vc_users WHERE user_password_reset_token = ? AND user_password_reset_expires > UNIX_TIMESTAMP()");
|
||||
$stmt->bind_param("s", $token);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
} elseif (isset($_SESSION['user']['user_uuid'])) {
|
||||
$user_uuid = $_SESSION['user']['user_uuid'];
|
||||
$stmt = $GLOBALS['conn']->prepare("SELECT * FROM vc_users WHERE user_uuid = ?");
|
||||
$stmt->bind_param("s", $user_uuid);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
}
|
||||
|
||||
|
||||
if ($result->num_rows == 1) {
|
||||
$tokenfound = true;
|
||||
$user_data = $result->fetch_assoc();
|
||||
} else {
|
||||
addLoginAttempts();
|
||||
}
|
||||
|
||||
if (checkLoginAttempts() > 20) {
|
||||
header('Location: /login/');
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html data-coreui-theme="dark" lang="en">
|
||||
<head>
|
||||
<base href="./">
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
|
||||
<meta name="description" content="Sentri - Configure phone configs">
|
||||
<meta name="author" content="Marco Mooij">
|
||||
<meta name="keyword" content="sentri">
|
||||
<title>Sentri | Login</title>
|
||||
|
||||
<!-- favicon -->
|
||||
<link rel="icon" type="image/png" href="/src/images/favicon/favicon-96x96.png" sizes="96x96">
|
||||
<link rel="icon" type="image/svg+xml" href="/src/images/favicon/favicon-96x96.png">
|
||||
<link rel="shortcut icon" href="/src/images/favicon/favicon.ico">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/src/images/favicon/apple-touch-icon.png">
|
||||
<link rel="manifest" href="/src/images/favicon/site.webmanifest">
|
||||
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #1d222b;
|
||||
}
|
||||
|
||||
.portal-image {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
aspect-ratio: 3 / 1;
|
||||
object-fit: contain;
|
||||
display: block;
|
||||
min-height: 200px; /* Prevent layout shift during image load */
|
||||
}
|
||||
|
||||
#code-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.code-input {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
font-size: 24px;
|
||||
text-align: center;
|
||||
margin: 5px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<link rel="stylesheet" href="css/style.full.css" as="style">
|
||||
</head>
|
||||
<body>
|
||||
<div class="bg-body-tertiary min-vh-100 d-flex flex-row align-items-center">
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-8 col-md-10 col-12 d-flex align-items-center justify-content-center">
|
||||
<div class="card-group d-block d-md-flex row">
|
||||
<div class="card col-md-7 mb-0">
|
||||
<div class="card-body p-3">
|
||||
<div class="card-body text-center justify-content-center align-items-center">
|
||||
<?php if (isset($_GET['result'])) {
|
||||
if ($_GET['result'] == "success") { ?>
|
||||
<h1 class="text-center">Password set</h1>
|
||||
<p class="text-center">Your password was set successfully. Use the button below to proceed to the login page.</p>
|
||||
<hr>
|
||||
<a href="/login/" class="btn btn-primary px-4">
|
||||
<i class="fa-solid fa-check"></i> Go to login
|
||||
</a>
|
||||
<?php } elseif ($_GET['result'] == "failed") { ?>
|
||||
<h1 class="text-center">Something went wrong</h1>
|
||||
<p class="text-center">Something went wrong in changing your password. Please contact support!</p>
|
||||
<?php } ?><?php } else { ?>
|
||||
<h1 class="text-center">Set Password</h1>
|
||||
<p class="text-center">Must be at least 12 characters.</p>
|
||||
<hr>
|
||||
<form method="post" action="/login/php/setPassword.php">
|
||||
<?php if (isset($_GET['token'])) { ?>
|
||||
<input type="hidden" name="user_password_reset_token" value="<?php echo $token ?>">
|
||||
<?php } elseif (isset($_SESSION['user']['user_uuid'])) { ?>
|
||||
<input type="hidden" name="user_uuid" value="<?php echo $user_data['user_uuid'] ?>">
|
||||
<?php } ?>
|
||||
<label for="password" class="form-label">New Password</label>
|
||||
<input type="password" class="form-control" name="password-1" id="password" placeholder="Enter password" required autocomplete="new-password">
|
||||
<div id="passwordPolicyError" class="form-text text-danger d-none">Password is too short.</div>
|
||||
<br>
|
||||
|
||||
<div class="mb-3 text-reset">
|
||||
<label for="confirmPassword" class="form-label">Confirm Password</label>
|
||||
<input type="password" class="form-control" name="password-2" id="confirmPassword" placeholder="Repeat password" required>
|
||||
<div id="passwordHelp" class="form-text text-danger d-none">Passwords do not match.</div>
|
||||
</div>
|
||||
|
||||
|
||||
<button type="submit" class="btn btn-primary w-100" id="submitBtn" disabled>
|
||||
<i class="fa-solid fa-key"></i> Set Password
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card col-md-5 text-white bg-transparent py-5">
|
||||
<div class="card-body text-center pt-5">
|
||||
<div>
|
||||
<img class="pt-3 w-100 portal-image" alt="portal-image" src="/src/images/logo-login-dark.webp" width="500" height="265" style="height: auto;">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
||||
<script>
|
||||
const password = document.getElementById("password");
|
||||
const confirmPassword = document.getElementById("confirmPassword");
|
||||
const submitBtn = document.getElementById("submitBtn");
|
||||
const passwordHelp = document.getElementById("passwordHelp");
|
||||
const passwordPolicyError = document.getElementById("passwordPolicyError");
|
||||
|
||||
function checkPasswords() {
|
||||
const pwValue = password.value;
|
||||
const confirmValue = confirmPassword.value;
|
||||
|
||||
// Check length
|
||||
if (pwValue.length < 13) {
|
||||
passwordPolicyError.classList.remove("d-none");
|
||||
submitBtn.disabled = true;
|
||||
return;
|
||||
} else {
|
||||
passwordPolicyError.classList.add("d-none");
|
||||
}
|
||||
|
||||
// Check match
|
||||
if (pwValue && confirmValue) {
|
||||
if (pwValue === confirmValue) {
|
||||
passwordHelp.classList.add("d-none");
|
||||
submitBtn.disabled = false;
|
||||
} else {
|
||||
passwordHelp.classList.remove("d-none");
|
||||
submitBtn.disabled = true;
|
||||
}
|
||||
} else {
|
||||
passwordHelp.classList.add("d-none");
|
||||
submitBtn.disabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
password.addEventListener("input", checkPasswords);
|
||||
confirmPassword.addEventListener("input", checkPasswords);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
125
pub/login/verifyEmail.php
Normal file
125
pub/login/verifyEmail.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
if (!isset($_GET['token'])) {
|
||||
http_response_code(404);
|
||||
exit;
|
||||
}
|
||||
|
||||
include_once $_SERVER['DOCUMENT_ROOT'] . '/login/php/authFunctions.php';
|
||||
|
||||
$token = htmlspecialchars($_GET['token'], ENT_QUOTES, 'UTF-8');
|
||||
$stmt = $GLOBALS['conn']->prepare("SELECT * FROM vc_users WHERE user_password_reset_token = ? AND user_password_reset_expires > UNIX_TIMESTAMP()");
|
||||
$stmt->bind_param("s", $token);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$tokenfound = false;
|
||||
|
||||
if ($result->num_rows == 1) {
|
||||
$tokenfound = true;
|
||||
$user_data = $result->fetch_assoc();
|
||||
} else {
|
||||
addLoginAttempts();
|
||||
}
|
||||
|
||||
if (checkLoginAttempts() > 20) {
|
||||
header('Location: /login/');
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html data-coreui-theme="dark" lang="en">
|
||||
<head>
|
||||
<base href="./">
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
|
||||
<meta name="description" content="Sentri - Configure phone configs">
|
||||
<meta name="author" content="Marco Mooij">
|
||||
<meta name="keyword" content="sentri">
|
||||
<title>Sentri | Login</title>
|
||||
|
||||
<!-- favicon -->
|
||||
<link rel="icon" type="image/png" href="/src/images/favicon/favicon-96x96.png" sizes="96x96">
|
||||
<link rel="icon" type="image/svg+xml" href="/src/images/favicon/favicon-96x96.png">
|
||||
<link rel="shortcut icon" href="/src/images/favicon/favicon.ico">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/src/images/favicon/apple-touch-icon.png">
|
||||
<link rel="manifest" href="/src/images/favicon/site.webmanifest">
|
||||
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #1d222b;
|
||||
}
|
||||
|
||||
.portal-image {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
aspect-ratio: 3 / 1;
|
||||
object-fit: contain;
|
||||
display: block;
|
||||
min-height: 200px; /* Prevent layout shift during image load */
|
||||
}
|
||||
|
||||
#code-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.code-input {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
font-size: 24px;
|
||||
text-align: center;
|
||||
margin: 5px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<link rel="stylesheet" href="css/style.full.css" as="style">
|
||||
</head>
|
||||
<body>
|
||||
<div class="bg-body-tertiary min-vh-100 d-flex flex-row align-items-center">
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-8 col-md-10 col-12 d-flex align-items-center justify-content-center">
|
||||
<div class="card-group d-block d-md-flex row">
|
||||
<div class="card col-md-7 mb-0">
|
||||
<div class="card-body p-3">
|
||||
<div class="card-body text-center justify-content-center align-items-center">
|
||||
<h1>Verify email</h1>
|
||||
<hr>
|
||||
<?php if ($user_data['user_verified_email'] == 1) { ?>
|
||||
<p>Your email is already verified, set a password to continue</p>
|
||||
<br>
|
||||
<a href="/login/resetPassword.php?token=<?php echo urlencode($_GET['token']); ?>" class="btn btn-primary px-4">
|
||||
<i class="fa-solid fa-check"></i> Set password
|
||||
</a>
|
||||
<?php } elseif (!$tokenfound) { ?>
|
||||
<p>This link has expired or does not exist. Please contact your administrator to request a new one.</p>
|
||||
<br>
|
||||
<?php } else { ?>
|
||||
<p>Click the following button to verify your account and set a password.</p>
|
||||
<br>
|
||||
<a href="/login/resetPassword.php?token=<?php echo urlencode($_GET['token']); ?>" class="btn btn-primary px-4">
|
||||
<i class="fa-solid fa-check"></i> Yup, its me!
|
||||
</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card col-md-5 text-white bg-transparent py-5">
|
||||
<div class="card-body text-center pt-5">
|
||||
<div>
|
||||
<img class="pt-3 w-100 portal-image" alt="portal-image" src="/src/images/logo-login-dark.webp" width="500" height="265" style="height: auto;">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user