sojorn/reset-password.html

272 lines
9 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reset Password - Sojorn</title>
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;700&display=swap" rel="stylesheet">
<style>
:root {
--primary: #10B981;
--primary-dark: #059669;
--bg: #09090b;
--card: #18181b;
--text: #ffffff;
--text-muted: #a1a1aa;
--error: #ef4444;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Outfit', sans-serif;
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background-color: var(--bg);
color: var(--text);
overflow: hidden;
}
.container {
text-align: center;
background: var(--card);
padding: 3rem;
border-radius: 24px;
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
max-width: 440px;
width: 90%;
border: 1px solid rgba(255, 255, 255, 0.1);
position: relative;
z-index: 10;
}
h1 {
font-size: 2rem;
font-weight: 700;
margin-bottom: 0.75rem;
background: linear-gradient(to bottom right, #ffffff, #a1a1aa);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
}
p {
font-size: 1.1rem;
margin-bottom: 2rem;
color: var(--text-muted);
line-height: 1.6;
}
.form-group {
margin-bottom: 1.5rem;
text-align: left;
}
label {
display: block;
margin-bottom: 0.5rem;
color: var(--text-muted);
font-size: 0.9rem;
}
input {
width: 100%;
padding: 1rem;
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 12px;
color: white;
font-size: 1rem;
font-family: inherit;
transition: all 0.2s;
}
input:focus {
outline: none;
border-color: var(--primary);
background: rgba(255, 255, 255, 0.1);
}
.btn {
display: inline-block;
background-color: var(--primary);
color: white;
padding: 1rem 2.5rem;
text-decoration: none;
border-radius: 12px;
font-weight: 600;
font-size: 1.1rem;
transition: all 0.2s ease;
box-shadow: 0 10px 15px -3px rgba(16, 185, 129, 0.4);
border: none;
cursor: pointer;
width: 100%;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 20px 25px -5px rgba(16, 185, 129, 0.4);
}
.btn:disabled {
opacity: 0.7;
cursor: not-allowed;
transform: none;
}
.error-message {
color: var(--error);
font-size: 0.9rem;
margin-top: 0.5rem;
display: none;
}
.bg-gradient {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: radial-gradient(circle at 50% 50%, rgba(16, 185, 129, 0.05) 0%, rgba(9, 9, 11, 1) 70%);
z-index: 1;
}
.hidden {
display: none !important;
}
</style>
</head>
<body>
<div class="bg-gradient"></div>
<div class="container">
<!-- Reset Form -->
<div id="reset-form">
<h1>Reset Password</h1>
<p>Enter your new password below.</p>
<form id="passwordForm" onsubmit="handleReset(event)">
<div class="form-group">
<label for="password">New Password</label>
<input type="password" id="password" required minlength="6" placeholder="At least 6 characters">
</div>
<div class="form-group">
<label for="confirmPassword">Confirm Password</label>
<input type="password" id="confirmPassword" required minlength="6"
placeholder="Confirm new password">
<div id="error-msg" class="error-message">Passwords do not match</div>
</div>
<button type="submit" id="submitBtn" class="btn">Reset Password</button>
</form>
</div>
<!-- Success State -->
<div id="success-state" class="hidden">
<svg class="icon" style="width: 64px; height: 64px; color: var(--primary); margin-bottom: 1rem;" fill="none"
stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
</svg>
<h1>Password Reset!</h1>
<p>Your password has been successfully updated. You can now log in with your new password.</p>
<a href="sojorn://login" class="btn">Open App</a>
</div>
<!-- Error State -->
<div id="error-state" class="hidden">
<svg class="icon" style="width: 64px; height: 64px; color: var(--error); margin-bottom: 1rem;" fill="none"
stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
<h1>Reset Failed</h1>
<p id="api-error-msg">The password reset link is invalid or has expired.</p>
<button onclick="window.location.reload()" class="btn"
style="background-color: #3f3f46; box-shadow: none;">Try Again</button>
</div>
</div>
<script>
const API_BASE = window.location.origin + '/api/v1'; // Assumes served from same domain or proxy
// If served statically separate from API, you might need to hardcode or env var this:
const ACTUAL_API_BASE = 'https://sojorn.net/api/v1';
async function handleReset(e) {
e.preventDefault();
const password = document.getElementById('password').value;
const confirm = document.getElementById('confirmPassword').value;
const errorMsg = document.getElementById('error-msg');
const submitBtn = document.getElementById('submitBtn');
const params = new URLSearchParams(window.location.search);
const token = params.get('token');
if (!token) {
showError('Invalid reset link.');
return;
}
if (password !== confirm) {
errorMsg.textContent = 'Passwords do not match';
errorMsg.style.display = 'block';
return;
}
if (password.length < 6) {
errorMsg.textContent = 'Password must be at least 6 characters';
errorMsg.style.display = 'block';
return;
}
errorMsg.style.display = 'none';
submitBtn.disabled = true;
submitBtn.textContent = 'Resetting...';
try {
const response = await fetch(`${ACTUAL_API_BASE}/auth/reset-password`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
token: token,
new_password: password
})
});
const data = await response.json();
if (response.ok) {
document.getElementById('reset-form').classList.add('hidden');
document.getElementById('success-state').classList.remove('hidden');
// Try to auto-open app
setTimeout(() => {
window.location.href = "sojorn://login";
}, 2000);
} else {
showError(data.error || 'Failed to reset password');
}
} catch (err) {
showError('Connection error. Please try again.');
} finally {
submitBtn.disabled = false;
submitBtn.textContent = 'Reset Password';
}
}
function showError(msg) {
document.getElementById('reset-form').classList.add('hidden');
document.getElementById('error-state').classList.remove('hidden');
document.getElementById('api-error-msg').textContent = msg;
}
</script>
</body>
</html>