78 lines
3.3 KiB
HTML
78 lines
3.3 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 — rokojori</title>
|
||
|
|
<style>
|
||
|
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||
|
|
body { font-family: system-ui, sans-serif; background: #111; color: #eee; display: flex; align-items: center; justify-content: center; min-height: 100vh; }
|
||
|
|
.card { background: #1c1c1c; border: 1px solid #2a2a2a; border-radius: 8px; padding: 2rem; width: 100%; max-width: 360px; }
|
||
|
|
h1 { font-size: 1.4rem; margin-bottom: 1.5rem; }
|
||
|
|
label { display: block; font-size: 0.85rem; color: #aaa; margin-bottom: 0.25rem; }
|
||
|
|
input[type="password"] { display: block; width: 100%; padding: 0.6rem 0.75rem; background: #111; border: 1px solid #333; border-radius: 4px; color: #eee; font-size: 0.95rem; margin-bottom: 1rem; }
|
||
|
|
input[type="password"]:focus { outline: none; border-color: #555; }
|
||
|
|
button { width: 100%; padding: 0.65rem; background: #2563eb; border: none; border-radius: 4px; color: #fff; font-size: 0.95rem; cursor: pointer; }
|
||
|
|
button:hover { background: #1d4ed8; }
|
||
|
|
.error { color: #f87171; font-size: 0.85rem; margin-bottom: 0.75rem; }
|
||
|
|
.invalid { color: #f87171; font-size: 0.95rem; }
|
||
|
|
.invalid a { color: #888; }
|
||
|
|
</style>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div class="card">
|
||
|
|
<h1>Reset password</h1>
|
||
|
|
<p class="invalid" id="invalid" hidden>
|
||
|
|
This reset link is invalid or has expired.
|
||
|
|
<a href="/forgot-password.html">Request a new one.</a>
|
||
|
|
</p>
|
||
|
|
<form id="form" autocomplete="on">
|
||
|
|
<!-- Hidden email field so browsers can associate the new password with the account -->
|
||
|
|
<input type="email" id="email-field" name="email" autocomplete="username" hidden readonly>
|
||
|
|
<label for="new-pw">New password</label>
|
||
|
|
<input type="password" id="new-pw" name="password" required minlength="8" autocomplete="new-password">
|
||
|
|
<p class="error" id="error" hidden></p>
|
||
|
|
<button type="submit">Set new password</button>
|
||
|
|
</form>
|
||
|
|
</div>
|
||
|
|
<script>
|
||
|
|
const token = new URLSearchParams(location.search).get('token');
|
||
|
|
|
||
|
|
if (!token) {
|
||
|
|
document.getElementById('invalid').hidden = false;
|
||
|
|
document.getElementById('form').hidden = true;
|
||
|
|
} else {
|
||
|
|
// Fetch the email for this token so the browser can save the updated password
|
||
|
|
fetch('/api/auth/reset-token-email?token=' + encodeURIComponent(token))
|
||
|
|
.then(r => r.ok ? r.json() : null)
|
||
|
|
.then(data => {
|
||
|
|
if (!data) {
|
||
|
|
document.getElementById('invalid').hidden = false;
|
||
|
|
document.getElementById('form').hidden = true;
|
||
|
|
} else {
|
||
|
|
document.getElementById('email-field').value = data.email;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
document.getElementById('form').addEventListener('submit', async e => {
|
||
|
|
e.preventDefault();
|
||
|
|
const password = document.getElementById('new-pw').value;
|
||
|
|
const res = await fetch('/api/auth/reset-password', {
|
||
|
|
method: 'POST',
|
||
|
|
headers: { 'Content-Type': 'application/json' },
|
||
|
|
body: JSON.stringify({ token, password })
|
||
|
|
});
|
||
|
|
if (res.ok) {
|
||
|
|
location.href = '/login.html';
|
||
|
|
} else {
|
||
|
|
const err = await res.json();
|
||
|
|
const p = document.getElementById('error');
|
||
|
|
p.textContent = err.error;
|
||
|
|
p.hidden = false;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>
|