Files
Job-Info/frontend/signin.html
T
2025-12-12 10:52:35 -06:00

217 lines
5.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign In</title>
<script src="https://cdn.jsdelivr.net/npm/pocketbase@0.26.5/dist/pocketbase.umd.js"></script>
<script src="auth.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.container {
background: white;
padding: 3rem;
border-radius: 1rem;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
text-align: center;
max-width: 400px;
width: 90%;
}
h1 {
color: #333;
margin-bottom: 0.5rem;
font-size: 1.75rem;
}
p {
color: #666;
margin-bottom: 2rem;
}
button {
background: #0078d4;
color: white;
border: none;
padding: 0.875rem 2rem;
font-size: 1rem;
border-radius: 0.375rem;
cursor: pointer;
transition: background 0.2s;
font-weight: 500;
}
button:hover:not(:disabled) {
background: #005a9e;
}
button:disabled {
background: #ccc;
cursor: not-allowed;
}
.user-info {
display: none;
margin-top: 2rem;
text-align: left;
background: #f8f9fa;
padding: 1.5rem;
border-radius: 0.5rem;
}
.user-info h2 {
font-size: 1.125rem;
margin-bottom: 1rem;
color: #333;
}
.user-info p {
margin-bottom: 0.75rem;
color: #555;
word-break: break-all;
}
.user-info strong {
color: #333;
}
.error {
color: #d32f2f;
margin-top: 1rem;
display: none;
}
.logout-btn {
background: #6c757d;
margin-top: 1rem;
}
.logout-btn:hover {
background: #5a6268;
}
.notes-section {
display: none;
margin-top: 2rem;
text-align: left;
}
.notes-section h3 {
font-size: 1rem;
margin-bottom: 1rem;
color: #333;
}
textarea {
width: 100%;
padding: 0.75rem;
border: 1px solid #ddd;
border-radius: 0.375rem;
font-family: inherit;
font-size: 0.9rem;
resize: vertical;
min-height: 80px;
}
textarea:focus {
outline: none;
border-color: #0078d4;
}
.submit-btn {
margin-top: 0.75rem;
width: 100%;
}
.success {
color: #2e7d32;
margin-top: 0.75rem;
display: none;
font-size: 0.9rem;
}
</style>
</head>
<body>
<div class="container">
<h1>Welcome</h1>
<p>Sign in with your Microsoft account</p>
<button id="loginBtn" onclick="login()">Sign in with Microsoft</button>
<div class="error" id="error"></div>
<div class="user-info" id="userInfo">
<h2>Signed in</h2>
<p><strong>Name:</strong> <span id="displayName"></span></p>
<p><strong>Email:</strong> <span id="email"></span></p>
<button id="continueBtn" style="display:none;margin-top:1rem;" onclick="goToIndex()">Continue to Job Info</button>
<button class="logout-btn" onclick="logout()">Sign out</button>
</div>
</div>
<script>
const { pb, getDisplayName } = window.Auth;
const loginBtn = document.getElementById('loginBtn');
const errorEl = document.getElementById('error');
const userInfo = document.getElementById('userInfo');
const continueBtn = document.getElementById('continueBtn');
function goToIndex() {
window.location.href = 'index.html';
}
function showAuthedUI(displayName, email) {
loginBtn.style.display = 'none';
loginBtn.disabled = false;
loginBtn.textContent = 'Sign in with Microsoft';
userInfo.style.display = 'block';
continueBtn.style.display = 'block';
document.getElementById('displayName').textContent = displayName || 'Unknown';
document.getElementById('email').textContent = email || 'Not available';
}
async function login() {
loginBtn.disabled = true;
loginBtn.textContent = 'Signing in...';
errorEl.style.display = 'none';
try {
const authData = await pb.collection('users').authWithOAuth2({
provider: 'microsoft',
});
displayUserInfo(authData);
} catch (error) {
console.error('Login failed:', error);
errorEl.textContent = error.message || 'Authentication failed. Please try again.';
errorEl.style.display = 'block';
loginBtn.disabled = false;
loginBtn.textContent = 'Sign in with Microsoft';
}
}
function logout() {
pb.authStore.clear();
loginBtn.style.display = 'block';
userInfo.style.display = 'none';
continueBtn.style.display = 'none';
loginBtn.disabled = false;
loginBtn.textContent = 'Sign in with Microsoft';
}
function displayUserInfo(authData) {
const displayName = getDisplayName();
const email = authData?.meta?.rawUser?.email || authData?.record?.email || pb.authStore.model?.email || 'Not available';
showAuthedUI(displayName, email);
}
(async () => {
if (pb.authStore.isValid) {
try {
const authData = await pb.collection('users').authRefresh();
displayUserInfo(authData);
} catch (err) {
pb.authStore.clear();
logout();
}
}
})();
</script>
</body>
</html>