249 lines
8.1 KiB
HTML
249 lines
8.1 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</title>
|
|
<style>
|
|
*,
|
|
*::before,
|
|
*::after {
|
|
box-sizing: border-box;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
|
|
body {
|
|
font-family:
|
|
'Inter',
|
|
'Noto Sans SC',
|
|
'Noto Sans TC',
|
|
'Noto Sans JP',
|
|
'Noto Sans KR',
|
|
'Noto Sans Hebrew',
|
|
'Noto Sans Arabic',
|
|
'Noto Sans Devanagari',
|
|
'Noto Sans Thai',
|
|
system-ui,
|
|
-apple-system,
|
|
BlinkMacSystemFont,
|
|
'Segoe UI',
|
|
Roboto,
|
|
sans-serif;
|
|
background: #0a0a0a;
|
|
color: #e0e0e0;
|
|
min-height: 100vh;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.container {
|
|
width: 100%;
|
|
max-width: 380px;
|
|
padding: 2rem;
|
|
}
|
|
|
|
.title {
|
|
font-size: 1.5rem;
|
|
font-weight: 600;
|
|
letter-spacing: -0.02em;
|
|
color: #fff;
|
|
text-align: center;
|
|
margin-bottom: 2.5rem;
|
|
}
|
|
|
|
.btn {
|
|
width: 100%;
|
|
padding: 0.75rem 1rem;
|
|
border: 1px solid #2a2a2a;
|
|
border-radius: 8px;
|
|
background: #151515;
|
|
color: #e0e0e0;
|
|
font-size: 0.925rem;
|
|
font-family: inherit;
|
|
cursor: pointer;
|
|
transition:
|
|
background 0.15s,
|
|
border-color 0.15s;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.btn:hover {
|
|
background: #1e1e1e;
|
|
border-color: #3a3a3a;
|
|
}
|
|
|
|
.btn:disabled {
|
|
opacity: 0.5;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.btn-primary {
|
|
background: #fff;
|
|
color: #0a0a0a;
|
|
border-color: #fff;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
background: #e0e0e0;
|
|
border-color: #e0e0e0;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.form-group input {
|
|
width: 100%;
|
|
padding: 0.75rem 1rem;
|
|
border: 1px solid #2a2a2a;
|
|
border-radius: 8px;
|
|
background: #151515;
|
|
color: #e0e0e0;
|
|
font-size: 0.925rem;
|
|
font-family: inherit;
|
|
outline: none;
|
|
transition: border-color 0.15s;
|
|
}
|
|
|
|
.form-group input:focus {
|
|
border-color: #555;
|
|
}
|
|
|
|
.message {
|
|
padding: 0.75rem 1rem;
|
|
border-radius: 8px;
|
|
font-size: 0.85rem;
|
|
margin-bottom: 1rem;
|
|
display: none;
|
|
}
|
|
|
|
.error-msg {
|
|
background: #1a0000;
|
|
border: 1px solid #3a1111;
|
|
color: #ff6b6b;
|
|
}
|
|
|
|
.success-msg {
|
|
background: #001a00;
|
|
border: 1px solid #113a11;
|
|
color: #6bff6b;
|
|
}
|
|
|
|
.spinner {
|
|
width: 18px;
|
|
height: 18px;
|
|
border: 2px solid transparent;
|
|
border-top-color: currentColor;
|
|
border-radius: 50%;
|
|
animation: spin 0.6s linear infinite;
|
|
display: none;
|
|
}
|
|
|
|
@keyframes spin {
|
|
to {
|
|
transform: rotate(360deg);
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1 class="title">Reset your Monochrome password</h1>
|
|
|
|
<div id="error" class="message error-msg"></div>
|
|
<div id="success" class="message success-msg"></div>
|
|
|
|
<form id="reset-form">
|
|
<div class="form-group">
|
|
<input type="password" id="password" placeholder="New Password" required minlength="8" />
|
|
</div>
|
|
<div class="form-group">
|
|
<input
|
|
type="password"
|
|
id="password-confirm"
|
|
placeholder="Confirm New Password"
|
|
required
|
|
minlength="8"
|
|
/>
|
|
</div>
|
|
<button type="submit" id="reset-btn" class="btn btn-primary">
|
|
<span id="reset-btn-text">Reset Password</span>
|
|
<span id="reset-btn-spinner" class="spinner"></span>
|
|
</button>
|
|
</form>
|
|
</div>
|
|
|
|
<script type="module">
|
|
import { Client, Account } from 'appwrite';
|
|
|
|
const getEndpoint = () => {
|
|
const hostname = window.location.hostname;
|
|
if (hostname.endsWith('monochrome.tf') || hostname === 'monochrome.tf') {
|
|
return 'https://auth.monochrome.tf/v1';
|
|
}
|
|
return 'https://auth.samidy.com/v1';
|
|
};
|
|
|
|
const client = new Client().setEndpoint(getEndpoint()).setProject('auth-for-monochrome');
|
|
const account = new Account(client);
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const userId = urlParams.get('userId');
|
|
const secret = urlParams.get('secret');
|
|
|
|
const errorEl = document.getElementById('error');
|
|
const successEl = document.getElementById('success');
|
|
const form = document.getElementById('reset-form');
|
|
const btn = document.getElementById('reset-btn');
|
|
const btnText = document.getElementById('reset-btn-text');
|
|
const spinner = document.getElementById('reset-btn-spinner');
|
|
|
|
if (!userId || !secret) {
|
|
errorEl.textContent = 'Invalid or missing password reset link.';
|
|
errorEl.style.display = 'block';
|
|
form.style.display = 'none';
|
|
}
|
|
|
|
form.addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
errorEl.style.display = 'none';
|
|
successEl.style.display = 'none';
|
|
|
|
const password = document.getElementById('password').value;
|
|
const passwordConfirm = document.getElementById('password-confirm').value;
|
|
|
|
if (password !== passwordConfirm) {
|
|
errorEl.textContent = 'Passwords do not match.';
|
|
errorEl.style.display = 'block';
|
|
return;
|
|
}
|
|
|
|
btn.disabled = true;
|
|
btnText.style.display = 'none';
|
|
spinner.style.display = 'inline-block';
|
|
|
|
try {
|
|
await account.updateRecovery(userId, secret, password, passwordConfirm);
|
|
successEl.textContent = 'Password reset successfully. Redirecting...';
|
|
successEl.style.display = 'block';
|
|
form.style.display = 'none';
|
|
setTimeout(() => {
|
|
window.location.href = '/';
|
|
}, 3000);
|
|
} catch (err) {
|
|
errorEl.textContent = err.message || 'Failed to reset password.';
|
|
errorEl.style.display = 'block';
|
|
btn.disabled = false;
|
|
btnText.style.display = 'inline';
|
|
spinner.style.display = 'none';
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|