Spaces:
Sleeping
Sleeping
Commit ·
11dcbe4
1
Parent(s): bccf9f9
Add forgot password flow and password visibility toggle
Browse files- app/main.py +17 -0
- static/css/style.css +46 -0
- static/js/app.js +27 -0
- templates/index.html +52 -3
app/main.py
CHANGED
|
@@ -121,6 +121,23 @@ def logout():
|
|
| 121 |
return response
|
| 122 |
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
@app.get("/api/me")
|
| 125 |
def me(user: Optional[User] = Depends(get_current_user)):
|
| 126 |
if not user:
|
|
|
|
| 121 |
return response
|
| 122 |
|
| 123 |
|
| 124 |
+
class PasswordReset(BaseModel):
|
| 125 |
+
email: str
|
| 126 |
+
new_password: str
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
@app.post("/api/auth/reset-password")
|
| 130 |
+
def reset_password(data: PasswordReset, db: Session = Depends(get_db)):
|
| 131 |
+
if len(data.new_password) < 6:
|
| 132 |
+
raise HTTPException(status_code=400, detail="Password must be at least 6 characters")
|
| 133 |
+
user = get_user_by_email(db, data.email)
|
| 134 |
+
if not user:
|
| 135 |
+
raise HTTPException(status_code=404, detail="No account found with that email")
|
| 136 |
+
user.hashed_password = get_password_hash(data.new_password)
|
| 137 |
+
db.commit()
|
| 138 |
+
return {"ok": True, "message": "Password has been reset. You can now sign in."}
|
| 139 |
+
|
| 140 |
+
|
| 141 |
@app.get("/api/me")
|
| 142 |
def me(user: Optional[User] = Depends(get_current_user)):
|
| 143 |
if not user:
|
static/css/style.css
CHANGED
|
@@ -124,6 +124,52 @@ body::before {
|
|
| 124 |
}
|
| 125 |
.toggle-auth a:hover { text-decoration: underline; }
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
/* ---- Cards ---- */
|
| 128 |
.card {
|
| 129 |
background: var(--bg-card);
|
|
|
|
| 124 |
}
|
| 125 |
.toggle-auth a:hover { text-decoration: underline; }
|
| 126 |
|
| 127 |
+
.forgot-link {
|
| 128 |
+
text-align: right;
|
| 129 |
+
margin-top: -0.5rem;
|
| 130 |
+
margin-bottom: 0.25rem;
|
| 131 |
+
}
|
| 132 |
+
.forgot-link a {
|
| 133 |
+
color: var(--text-dim);
|
| 134 |
+
font-size: 0.82rem;
|
| 135 |
+
text-decoration: none;
|
| 136 |
+
transition: color var(--transition);
|
| 137 |
+
}
|
| 138 |
+
.forgot-link a:hover { color: var(--accent); }
|
| 139 |
+
|
| 140 |
+
/* ---- Password input with eye toggle ---- */
|
| 141 |
+
.input-password-wrap {
|
| 142 |
+
position: relative;
|
| 143 |
+
display: flex;
|
| 144 |
+
align-items: center;
|
| 145 |
+
}
|
| 146 |
+
.input-password-wrap input {
|
| 147 |
+
padding-right: 2.8rem;
|
| 148 |
+
}
|
| 149 |
+
.password-toggle {
|
| 150 |
+
position: absolute;
|
| 151 |
+
right: 0.6rem;
|
| 152 |
+
top: 50%;
|
| 153 |
+
transform: translateY(-50%);
|
| 154 |
+
background: none;
|
| 155 |
+
border: none;
|
| 156 |
+
cursor: pointer;
|
| 157 |
+
color: var(--text-dim);
|
| 158 |
+
padding: 0.25rem;
|
| 159 |
+
display: flex;
|
| 160 |
+
align-items: center;
|
| 161 |
+
justify-content: center;
|
| 162 |
+
border-radius: var(--radius-xs);
|
| 163 |
+
transition: color var(--transition), background var(--transition);
|
| 164 |
+
}
|
| 165 |
+
.password-toggle:hover {
|
| 166 |
+
color: var(--accent);
|
| 167 |
+
background: rgba(45, 212, 191, 0.08);
|
| 168 |
+
}
|
| 169 |
+
.password-toggle svg.eye-closed { display: none; }
|
| 170 |
+
.password-toggle.active svg.eye-open { display: none !important; }
|
| 171 |
+
.password-toggle.active svg.eye-closed { display: block !important; }
|
| 172 |
+
|
| 173 |
/* ---- Cards ---- */
|
| 174 |
.card {
|
| 175 |
background: var(--bg-card);
|
static/js/app.js
CHANGED
|
@@ -75,12 +75,39 @@ document.getElementById('form-register')?.addEventListener('submit', async (e) =
|
|
| 75 |
} catch (err) { showError('register-error', err.message); }
|
| 76 |
});
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
document.querySelectorAll('[data-view]').forEach((a) => {
|
| 79 |
a.addEventListener('click', (e) => {
|
| 80 |
e.preventDefault();
|
| 81 |
showView(a.getAttribute('data-view'));
|
| 82 |
hideError('login-error');
|
| 83 |
hideError('register-error');
|
|
|
|
|
|
|
| 84 |
});
|
| 85 |
});
|
| 86 |
|
|
|
|
| 75 |
} catch (err) { showError('register-error', err.message); }
|
| 76 |
});
|
| 77 |
|
| 78 |
+
// ---- Forgot password ----
|
| 79 |
+
document.getElementById('form-forgot')?.addEventListener('submit', async (e) => {
|
| 80 |
+
e.preventDefault();
|
| 81 |
+
hideError('forgot-error');
|
| 82 |
+
hideError('forgot-success');
|
| 83 |
+
const email = document.getElementById('forgot-email').value.trim();
|
| 84 |
+
const new_password = document.getElementById('forgot-password').value;
|
| 85 |
+
try {
|
| 86 |
+
const data = await api('POST', '/api/auth/reset-password', { body: JSON.stringify({ email, new_password }) });
|
| 87 |
+
showSuccess('forgot-success', data.message || 'Password reset! You can now sign in.');
|
| 88 |
+
document.getElementById('form-forgot').reset();
|
| 89 |
+
} catch (err) { showError('forgot-error', err.message); }
|
| 90 |
+
});
|
| 91 |
+
|
| 92 |
+
// ---- Password visibility toggle ----
|
| 93 |
+
document.querySelectorAll('.password-toggle').forEach((btn) => {
|
| 94 |
+
btn.addEventListener('click', () => {
|
| 95 |
+
const input = document.getElementById(btn.dataset.target);
|
| 96 |
+
if (!input) return;
|
| 97 |
+
const isPassword = input.type === 'password';
|
| 98 |
+
input.type = isPassword ? 'text' : 'password';
|
| 99 |
+
btn.classList.toggle('active', isPassword);
|
| 100 |
+
});
|
| 101 |
+
});
|
| 102 |
+
|
| 103 |
document.querySelectorAll('[data-view]').forEach((a) => {
|
| 104 |
a.addEventListener('click', (e) => {
|
| 105 |
e.preventDefault();
|
| 106 |
showView(a.getAttribute('data-view'));
|
| 107 |
hideError('login-error');
|
| 108 |
hideError('register-error');
|
| 109 |
+
hideError('forgot-error');
|
| 110 |
+
hideError('forgot-success');
|
| 111 |
});
|
| 112 |
});
|
| 113 |
|
templates/index.html
CHANGED
|
@@ -28,10 +28,17 @@
|
|
| 28 |
</div>
|
| 29 |
<div class="form-group">
|
| 30 |
<label for="login-password">Password</label>
|
| 31 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
</div>
|
| 33 |
<button type="submit" class="btn btn-primary btn-block">Sign in</button>
|
| 34 |
</form>
|
|
|
|
| 35 |
<p class="toggle-auth">Don't have an account? <a href="#" data-view="register">Create one</a></p>
|
| 36 |
</div>
|
| 37 |
</div>
|
|
@@ -61,7 +68,13 @@
|
|
| 61 |
</div>
|
| 62 |
<div class="form-group">
|
| 63 |
<label for="register-password">Password</label>
|
| 64 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
</div>
|
| 66 |
<button type="submit" class="btn btn-primary btn-block">Create account</button>
|
| 67 |
</form>
|
|
@@ -70,6 +83,42 @@
|
|
| 70 |
</div>
|
| 71 |
</section>
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
<!-- Dashboard view -->
|
| 74 |
<section id="view-dashboard" class="view">
|
| 75 |
<nav class="nav">
|
|
@@ -222,6 +271,6 @@
|
|
| 222 |
</div>
|
| 223 |
</div>
|
| 224 |
|
| 225 |
-
<script src="/static/js/app.js?v=
|
| 226 |
</body>
|
| 227 |
</html>
|
|
|
|
| 28 |
</div>
|
| 29 |
<div class="form-group">
|
| 30 |
<label for="login-password">Password</label>
|
| 31 |
+
<div class="input-password-wrap">
|
| 32 |
+
<input type="password" id="login-password" required placeholder="Enter your password" />
|
| 33 |
+
<button type="button" class="password-toggle" data-target="login-password" aria-label="Show password">
|
| 34 |
+
<svg class="eye-open" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
|
| 35 |
+
<svg class="eye-closed" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17.94 17.94A10.07 10.07 0 0112 20c-7 0-11-8-11-8a18.45 18.45 0 015.06-5.94M9.9 4.24A9.12 9.12 0 0112 4c7 0 11 8 11 8a18.5 18.5 0 01-2.16 3.19m-6.72-1.07a3 3 0 11-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/></svg>
|
| 36 |
+
</button>
|
| 37 |
+
</div>
|
| 38 |
</div>
|
| 39 |
<button type="submit" class="btn btn-primary btn-block">Sign in</button>
|
| 40 |
</form>
|
| 41 |
+
<p class="forgot-link"><a href="#" data-view="forgot">Forgot your password?</a></p>
|
| 42 |
<p class="toggle-auth">Don't have an account? <a href="#" data-view="register">Create one</a></p>
|
| 43 |
</div>
|
| 44 |
</div>
|
|
|
|
| 68 |
</div>
|
| 69 |
<div class="form-group">
|
| 70 |
<label for="register-password">Password</label>
|
| 71 |
+
<div class="input-password-wrap">
|
| 72 |
+
<input type="password" id="register-password" required placeholder="Min. 6 characters" minlength="6" />
|
| 73 |
+
<button type="button" class="password-toggle" data-target="register-password" aria-label="Show password">
|
| 74 |
+
<svg class="eye-open" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
|
| 75 |
+
<svg class="eye-closed" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17.94 17.94A10.07 10.07 0 0112 20c-7 0-11-8-11-8a18.45 18.45 0 015.06-5.94M9.9 4.24A9.12 9.12 0 0112 4c7 0 11 8 11 8a18.5 18.5 0 01-2.16 3.19m-6.72-1.07a3 3 0 11-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/></svg>
|
| 76 |
+
</button>
|
| 77 |
+
</div>
|
| 78 |
</div>
|
| 79 |
<button type="submit" class="btn btn-primary btn-block">Create account</button>
|
| 80 |
</form>
|
|
|
|
| 83 |
</div>
|
| 84 |
</section>
|
| 85 |
|
| 86 |
+
<!-- Forgot password view -->
|
| 87 |
+
<section id="view-forgot" class="view">
|
| 88 |
+
<div class="auth-container">
|
| 89 |
+
<div class="auth-logo">
|
| 90 |
+
<div class="auth-logo-icon">
|
| 91 |
+
<svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M2 12h20"/><path d="M12 2a15.3 15.3 0 014 10 15.3 15.3 0 01-4 10 15.3 15.3 0 01-4-10 15.3 15.3 0 014-10z"/></svg>
|
| 92 |
+
</div>
|
| 93 |
+
<span>SatDetect</span>
|
| 94 |
+
</div>
|
| 95 |
+
<div class="card">
|
| 96 |
+
<h2>Reset password</h2>
|
| 97 |
+
<p class="sub">Enter your email and choose a new password.</p>
|
| 98 |
+
<div id="forgot-error" class="alert alert-error hidden"></div>
|
| 99 |
+
<div id="forgot-success" class="alert alert-success hidden"></div>
|
| 100 |
+
<form id="form-forgot">
|
| 101 |
+
<div class="form-group">
|
| 102 |
+
<label for="forgot-email">Email</label>
|
| 103 |
+
<input type="email" id="forgot-email" required placeholder="you@example.com" />
|
| 104 |
+
</div>
|
| 105 |
+
<div class="form-group">
|
| 106 |
+
<label for="forgot-password">New password</label>
|
| 107 |
+
<div class="input-password-wrap">
|
| 108 |
+
<input type="password" id="forgot-password" required placeholder="Min. 6 characters" minlength="6" />
|
| 109 |
+
<button type="button" class="password-toggle" data-target="forgot-password" aria-label="Show password">
|
| 110 |
+
<svg class="eye-open" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
|
| 111 |
+
<svg class="eye-closed" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17.94 17.94A10.07 10.07 0 0112 20c-7 0-11-8-11-8a18.45 18.45 0 015.06-5.94M9.9 4.24A9.12 9.12 0 0112 4c7 0 11 8 11 8a18.5 18.5 0 01-2.16 3.19m-6.72-1.07a3 3 0 11-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/></svg>
|
| 112 |
+
</button>
|
| 113 |
+
</div>
|
| 114 |
+
</div>
|
| 115 |
+
<button type="submit" class="btn btn-primary btn-block">Reset password</button>
|
| 116 |
+
</form>
|
| 117 |
+
<p class="toggle-auth">Remember your password? <a href="#" data-view="login">Sign in</a></p>
|
| 118 |
+
</div>
|
| 119 |
+
</div>
|
| 120 |
+
</section>
|
| 121 |
+
|
| 122 |
<!-- Dashboard view -->
|
| 123 |
<section id="view-dashboard" class="view">
|
| 124 |
<nav class="nav">
|
|
|
|
| 271 |
</div>
|
| 272 |
</div>
|
| 273 |
|
| 274 |
+
<script src="/static/js/app.js?v=6"></script>
|
| 275 |
</body>
|
| 276 |
</html>
|