format/index.php
2025-09-08 16:25:26 -05:00

92 lines
No EOL
3.2 KiB
PHP

<?php
require_once 'config.php';
require_once 'AuthMiddleware.php';
// Require authentication for this page
$auth = new AuthMiddleware();
$user = $auth->requireAuth();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Markdown to HTML Converter</title>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
<script src="https://alcdn.msauth.net/browser/2.15.0/js/msal-browser.min.js" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<div style="text-align: right; margin-bottom: 10px;">
<span style="margin-right: 10px;">Welcome, <?php echo htmlspecialchars($user['name'] ?? $user['preferred_username'] ?? 'User'); ?></span>
<button id="logout-button" onclick="signOut()">Log Out</button>
</div>
<div class="logo-container">
<img src="MD.svg" alt="MD Logo" class="logo">
</div>
<div class="converter">
<div class="input-area">
<h2>Markdown Input</h2>
<textarea id="markdown-input" placeholder="Enter your Markdown here..."></textarea>
</div>
<div class="output-area">
<h2>HTML Output</h2>
<div id="html-output"></div>
<div class="button-group">
<button id="select-all">Select All</button>
<button id="copy">Copy</button>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/2.0.3/marked.min.js"></script>
<script src="js/script.js"></script>
<script>
const msalConfig = {
auth: {
clientId: "9079054c-9620-4757-a256-23413042f1ef",
authority: "https://login.microsoftonline.com/e519c2e6-bc6d-4fdf-8d9c-923c2f002385",
redirectUri: window.location.origin + window.location.pathname.replace(/\/$/, '')
},
cache: {
cacheLocation: "sessionStorage",
storeAuthStateInCookie: true,
}
};
const myMSALObj = new msal.PublicClientApplication(msalConfig);
function signOut() {
// Call server to clear cookie
fetch('auth.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
action: 'logout'
})
})
.then(() => {
// Also clear MSAL session
myMSALObj.logoutPopup().then(() => {
window.location.reload();
}).catch(error => {
console.error("Logout error:", error);
window.location.reload(); // Reload anyway
});
})
.catch(error => {
console.error("Logout error:", error);
window.location.reload();
});
}
</script>
</body>
</html>