108 lines
4.0 KiB
PHP
108 lines
4.0 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en" data-bs-theme="dark">
|
|
<head>
|
|
<!-- this is the first file accessed by the user. It sends a request to backend to check where it should send the user -->
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Jakach Login</title>
|
|
<?php
|
|
include "../assets/components.php";
|
|
?>
|
|
</head>
|
|
<body>
|
|
<div class="d-flex flex-column justify-content-center align-items-center" style="height: 100vh;">
|
|
<!-- Spinner -->
|
|
<div class="spinner-border text-primary mb-3" role="status" id="loadingSpinner">
|
|
<span class="visually-hidden">Loading...</span>
|
|
</div>
|
|
<!-- Redirecting Text -->
|
|
<p class="text-center fs-4" id="statusText">Redirecting...</p>
|
|
</div>
|
|
|
|
<div class="modal fade" id="externalWarningModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="externalWarningModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog modal-dialog-centered">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="externalWarningModalLabel">⚠️ External Login Warning</h5>
|
|
</div>
|
|
<div class="modal-body">
|
|
<p>You are being logged in into <strong id="externalDomainDisplay"></strong></p>
|
|
<p>This service is <strong>not operated by Jakach</strong>. The service will have access to:</p>
|
|
<ul>
|
|
<li>Email username</li>
|
|
<li>Telegram ID</li>
|
|
<li>User ID & User Token</li>
|
|
</ul>
|
|
<p class="mb-0 text-muted">Do you want to continue?</p>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<a href="/account/" class="btn btn-secondary">Cancel</a>
|
|
<button type="button" class="btn btn-primary" id="confirmExternalRedirect">Continue</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
const redirect_api="/api/login/redirect.php";
|
|
let pendingRedirectUrl = null;
|
|
|
|
async function redirect() {
|
|
try {
|
|
const response = await fetch(redirect_api);
|
|
|
|
// Check if the response is OK
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
}
|
|
|
|
// Parse the JSON response
|
|
const data = await response.json();
|
|
|
|
// Extract the 'redirect' property from the response
|
|
const redirectUrl = data.redirect;
|
|
|
|
// Check if the redirect URL exists
|
|
if (redirectUrl) {
|
|
if (data.message === 'external_redirect_warning') {
|
|
pendingRedirectUrl = redirectUrl;
|
|
document.getElementById('externalDomainDisplay').textContent = data.domain;
|
|
document.getElementById('loadingSpinner').style.display = 'none';
|
|
document.getElementById('statusText').textContent = 'Login warning';
|
|
var warningModal = new bootstrap.Modal(document.getElementById('externalWarningModal'));
|
|
warningModal.show();
|
|
document.getElementById('externalWarningModal').addEventListener('shown.bs.modal', function () {
|
|
document.getElementById('confirmExternalRedirect').focus();
|
|
});
|
|
} else {
|
|
// Redirect the user to the URL
|
|
window.location.href = redirectUrl;
|
|
}
|
|
}
|
|
} catch (error) {
|
|
// Handle errors (e.g., network issues or API errors)
|
|
console.error("Error fetching data:", error);
|
|
}
|
|
}
|
|
|
|
document.getElementById('confirmExternalRedirect').addEventListener('click', function() {
|
|
confirmExternalRedirect();
|
|
});
|
|
|
|
document.addEventListener('keydown', function(e) {
|
|
if (e.key === 'Enter' && document.getElementById('externalWarningModal').classList.contains('show')) {
|
|
confirmExternalRedirect();
|
|
}
|
|
});
|
|
|
|
function confirmExternalRedirect() {
|
|
fetch('/api/login/confirm_external_redirect.php', { method: 'POST' }).then(() => {
|
|
window.location.href = pendingRedirectUrl;
|
|
});
|
|
}
|
|
|
|
// Call the function on page load
|
|
redirect();
|
|
</script>
|
|
</body>
|
|
</html>
|