|
29 | 29 | span PourScore |
30 | 30 | span.beta-badge Beta |
31 | 31 | li.profile-wrapper |
32 | | - button#profileBtn.profile-btn |
33 | | - i.fa-solid.fa-user |
34 | | - .profile-dropdown#profileDropdown |
35 | | - a(href=`/users/${user_id}`) Your Profile |
36 | | - a.logout-link(href="/logout") Logout |
| 32 | + if user_id |
| 33 | + button#profileBtn.profile-btn |
| 34 | + i.fa-solid.fa-user |
| 35 | + .profile-dropdown#profileDropdown |
| 36 | + a(href=`/users/${user_id}`) Your Profile |
| 37 | + a.logout-link(href="/logout") Logout |
| 38 | + else |
| 39 | + a.header-login-btn(href="#" onclick="showLoginModal(); return false;") Login |
| 40 | + |
37 | 41 |
|
38 | 42 | block content |
39 | 43 |
|
|
72 | 76 | textarea(name="comment" rows="4" required) |
73 | 77 |
|
74 | 78 | button(type="submit") Submit Review |
| 79 | + |
| 80 | + // Login Modal |
| 81 | + #loginModal.modal |
| 82 | + .modal-content.login-container(style="padding: 40px; text-align: center; max-width: 400px; position: relative; margin: 0;") |
| 83 | + span.close-btn(style="color: #888; font-size: 28px; top: 16px; right: 20px;" onclick="document.getElementById('loginModal').classList.remove('show')") × |
| 84 | + |
| 85 | + h2.login-title(style="margin-top: 0;") Login |
| 86 | + |
| 87 | + form#loginForm.login-form(style="text-align: left;") |
| 88 | + .form-group |
| 89 | + label.form-label(for="loginEmail") Email |
| 90 | + input.form-input(type="email", name="email", id="loginEmail", required) |
| 91 | + |
| 92 | + .form-group |
| 93 | + label.form-label(for="loginPassword") Password |
| 94 | + input.form-input(type="password", name="password", id="loginPassword", required) |
| 95 | + |
| 96 | + button.login-button(type="submit") Login |
| 97 | + |
| 98 | + #login-error-popup.error-popup(style="display: none; position: static; transform: none; margin-top: 15px; background-color: #d32f2f; color: white; padding: 10px; border-radius: 8px; font-weight: 600;") |
| 99 | + span#login-error-message |
| 100 | + |
| 101 | + script. |
| 102 | + function showLoginModal() { |
| 103 | + document.getElementById('loginModal').classList.add('show'); |
| 104 | + } |
| 105 | + |
| 106 | + document.addEventListener('DOMContentLoaded', () => { |
| 107 | + const urlParams = new URLSearchParams(window.location.search); |
| 108 | + if (urlParams.get('login') === 'true') { |
| 109 | + showLoginModal(); |
| 110 | + const cleanUrl = window.location.protocol + "//" + window.location.host + window.location.pathname; |
| 111 | + window.history.replaceState({path: cleanUrl}, '', cleanUrl); |
| 112 | + } |
| 113 | + |
| 114 | + const loginForm = document.getElementById('loginForm'); |
| 115 | + if (loginForm) { |
| 116 | + loginForm.addEventListener('submit', async (e) => { |
| 117 | + e.preventDefault(); |
| 118 | + const email = document.getElementById('loginEmail').value; |
| 119 | + const password = document.getElementById('loginPassword').value; |
| 120 | + const popup = document.getElementById('login-error-popup'); |
| 121 | + const msgSpan = document.getElementById('login-error-message'); |
| 122 | + |
| 123 | + try { |
| 124 | + const response = await fetch('/login', { |
| 125 | + method: 'POST', |
| 126 | + headers: { 'Content-Type': 'application/json' }, |
| 127 | + body: JSON.stringify({ email, password }) |
| 128 | + }); |
| 129 | + |
| 130 | + const data = await response.json(); |
| 131 | + |
| 132 | + if (data.success) { |
| 133 | + const redirectUrl = urlParams.get('continue') || '/'; |
| 134 | + window.location.href = redirectUrl; |
| 135 | + } else { |
| 136 | + msgSpan.innerText = data.message; |
| 137 | + popup.style.display = 'block'; |
| 138 | + setTimeout(() => { popup.style.display = 'none'; }, 4000); |
| 139 | + } |
| 140 | + } catch (err) { |
| 141 | + msgSpan.innerText = "Connection lost. Try again."; |
| 142 | + popup.style.display = 'block'; |
| 143 | + } |
| 144 | + }); |
| 145 | + } |
| 146 | + }); |
0 commit comments