voice2text/login.php

270 lines
8.6 KiB
PHP
Executable file

<?php
/**
* Login Landing Page
* Displays Microsoft sign-in button
*/
require_once 'auth_config.php';
// In dev mode, bypass login page entirely
if (DEV_MODE) {
header('Location: index.php');
exit;
}
// If already authenticated, redirect to main app
if (isAuthenticated()) {
header('Location: index.php');
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign In - Voice to Text</title>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Montserrat', sans-serif;
background: #000000;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.login-container {
background: #1a1a1a;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(255, 196, 7, 0.2);
border: 1px solid #333;
padding: 60px 50px;
max-width: 500px;
width: 100%;
text-align: center;
animation: fadeIn 0.5s ease-in;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.logo {
width: 350px;
height: auto;
display: block;
margin: 0 auto 40px;
filter: invert(1) brightness(2);
}
h1 {
color: #FFC407;
font-size: 28px;
font-weight: 700;
margin-bottom: 15px;
}
.subtitle {
color: #999;
font-size: 16px;
margin-bottom: 40px;
line-height: 1.6;
}
.microsoft-login-btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 12px;
padding: 16px 40px;
background: #FFC407;
color: #000;
text-decoration: none;
border-radius: 50px;
font-weight: 700;
font-size: 16px;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(255, 196, 7, 0.4);
border: none;
cursor: pointer;
}
.microsoft-login-btn:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(255, 196, 7, 0.6);
background: #ffcd2e;
}
.microsoft-login-btn:active {
transform: translateY(0);
}
.microsoft-icon {
width: 20px;
height: 20px;
}
.info-box {
margin-top: 40px;
padding: 20px;
background: #0a0a0a;
border-radius: 12px;
border: 1px solid #333;
}
.info-box p {
color: #666;
font-size: 14px;
line-height: 1.6;
}
@media screen and (max-width: 600px) {
.login-container {
padding: 40px 30px;
}
.logo {
width: 280px;
}
h1 {
font-size: 24px;
}
.subtitle {
font-size: 14px;
}
}
</style>
</head>
<body>
<div class="login-container">
<img src="V2T.svg" alt="Voice to Text" class="logo">
<h1>Welcome to Voice to Text</h1>
<p class="subtitle">
Transcribe audio files using OpenAI Whisper<br>
Translate with DeepL into 30+ languages
</p>
<button id="loginButton" class="microsoft-login-btn">
<svg class="microsoft-icon" viewBox="0 0 23 23" xmlns="http://www.w3.org/2000/svg">
<rect width="11" height="11" fill="#f25022"/>
<rect x="12" width="11" height="11" fill="#7fba00"/>
<rect y="12" width="11" height="11" fill="#00a4ef"/>
<rect x="12" y="12" width="11" height="11" fill="#ffb900"/>
</svg>
Sign in with Microsoft
</button>
<div id="loginError" style="display: none; margin-top: 20px; padding: 15px; background: #ff3333; color: white; border-radius: 8px; font-size: 14px;"></div>
<div id="loginProgress" style="display: none; margin-top: 20px; padding: 15px; background: #0a0a0a; color: #FFC407; border-radius: 8px; font-size: 14px; border: 1px solid #333;"></div>
<div class="info-box">
<p>
Sign in with your Microsoft account to access the application.<br>
Supported formats: Text, VTT, SRT
</p>
</div>
</div>
<!-- MSAL.js Library -->
<script src="https://alcdn.msauth.net/browser/2.38.1/js/msal-browser.min.js"></script>
<script>
// MSAL Configuration
const msalConfig = {
auth: {
clientId: '<?php echo AZURE_CLIENT_ID; ?>',
authority: '<?php echo AZURE_AUTHORITY; ?>',
redirectUri: '<?php echo AZURE_REDIRECT_URI; ?>'
},
cache: {
cacheLocation: 'sessionStorage',
storeAuthStateInCookie: false
}
};
// Create MSAL instance
const msalInstance = new msal.PublicClientApplication(msalConfig);
// Login request configuration
const loginRequest = {
scopes: ['openid', 'profile', 'email', 'User.Read']
};
// Handle login button click
document.getElementById('loginButton').addEventListener('click', async function() {
try {
document.getElementById('loginProgress').style.display = 'block';
document.getElementById('loginProgress').textContent = 'Redirecting to Microsoft...';
document.getElementById('loginError').style.display = 'none';
// Sign in with redirect
await msalInstance.loginRedirect(loginRequest);
} catch (error) {
console.error('Login error:', error);
document.getElementById('loginError').style.display = 'block';
document.getElementById('loginError').textContent = 'Login failed: ' + error.message;
document.getElementById('loginProgress').style.display = 'none';
}
});
// Handle redirect callback
msalInstance.handleRedirectPromise()
.then(async (response) => {
if (response) {
// User just logged in - we have a response
document.getElementById('loginProgress').style.display = 'block';
document.getElementById('loginProgress').textContent = 'Authentication successful! Creating session...';
const account = response.account;
const accessToken = response.accessToken;
// Send token to PHP backend to create session
const validateResponse = await fetch('validate_token.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
accessToken: accessToken
})
});
const result = await validateResponse.json();
if (result.success) {
// Session created successfully - redirect to app
document.getElementById('loginProgress').textContent = 'Session created! Redirecting...';
window.location.href = 'index.php';
} else {
document.getElementById('loginError').style.display = 'block';
document.getElementById('loginError').textContent = 'Session creation failed: ' + result.error;
document.getElementById('loginProgress').style.display = 'none';
}
}
})
.catch((error) => {
console.error('Redirect callback error:', error);
document.getElementById('loginError').style.display = 'block';
document.getElementById('loginError').textContent = 'Authentication error: ' + error.message;
});
</script>
</body>
</html>