Skip to content

Commit d83aafd

Browse files
authored
Merge pull request #111 from jackoturner/Updated-Styles
refactor: replace dedicated login page with a modal integrated into t…
2 parents 7844d15 + 79171f3 commit d83aafd

6 files changed

Lines changed: 151 additions & 112 deletions

File tree

app/app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ const apiRoutes = require("./models/api");
4040
// Middleware to require login
4141
function requireLogin(req, res, next) {
4242
if (!req.session.user_id) {
43-
return res.redirect("/login");
43+
if (req.xhr || (req.headers.accept && req.headers.accept.indexOf('json') > -1)) {
44+
return res.status(401).json({ error: "You must be logged in" });
45+
}
46+
return res.redirect(`/?login=true&continue=${encodeURIComponent(req.originalUrl)}`);
4447
}
4548
next();
4649
}

app/models/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@ const db = require("../services/db");
44
const bcrypt = require("bcrypt");
55

66
router.get("/", (req, res) => {
7-
if (!req.session.user_id) {
8-
return res.redirect("/login");
9-
}
10-
117
res.render("index", {
128
user_email: req.session.user_email,
139
first_name: req.session.first_name
1410
});
1511
});
1612

13+
1714
router.get("/login", (req, res) => {
18-
res.render("login");
15+
res.redirect("/?login=true");
1916
});
2017

2118
router.post("/login", (req, res) => {
@@ -74,7 +71,7 @@ router.get("/logout", (req, res) => {
7471
if (err) {
7572
console.error("Logout error:", err);
7673
}
77-
res.redirect("/login");
74+
res.redirect("/");
7875
});
7976
});
8077

app/views/index.pug

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ block content
44

55
main
66
section.hero
7-
h1 Ready for your next pint, #{first_name}?
7+
if first_name
8+
h1 Ready for your next pint, #{first_name}?
9+
else
10+
h1 Ready for your next pint?
811
p Discover pubs, rate pints, and see what others recommend.
912

1013
section

app/views/layout.pug

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ html
2929
span PourScore
3030
span.beta-badge Beta
3131
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+
3741

3842
block content
3943

@@ -72,3 +76,71 @@ html
7276
textarea(name="comment" rows="4" required)
7377

7478
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+
});

app/views/login.pug

Lines changed: 0 additions & 57 deletions
This file was deleted.

static/styles.css

Lines changed: 63 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,26 @@ nav a:hover {
147147
transition-duration: 300ms;
148148
}
149149

150+
.header-login-btn {
151+
color: white !important;
152+
padding: 6px 16px;
153+
border-radius: 6px;
154+
font-family: 'Instrument Serif', serif;
155+
font-size: 1.4rem;
156+
transition: all 0.3s ease;
157+
border: 1px solid rgba(255, 255, 255, 0.8);
158+
display: inline-block;
159+
}
160+
161+
.header-login-btn:hover {
162+
background-color: white;
163+
color: #B87333 !important;
164+
text-decoration: none !important;
165+
transform: translateY(-1px);
166+
}
167+
168+
169+
150170
/* Sections */
151171
section {
152172
background: white;
@@ -780,53 +800,50 @@ textarea {
780800
}
781801
}
782802

783-
html.login-html,
803+
/* Login adjustments for layout integration */
784804
body.login-page {
785-
height: 100%;
786-
width: 100%;
787-
margin: 0;
788-
padding: 0;
789-
overflow: hidden;
790-
background: #0a0a0a;
805+
background-color: #f5f5f5;
791806
}
792807

808+
793809
/* Beer bubbles background */
794-
.beer-hero {
795-
position: fixed;
796-
top: 0;
797-
left: 0;
798-
width: 100vw;
799-
height: 100vh;
810+
.login-hero {
811+
min-height: 85vh;
800812
display: flex;
801813
align-items: center;
802814
justify-content: center;
803-
background: linear-gradient(to bottom, #ffc979, #ff9800);
815+
background: linear-gradient(135deg, #fbc02d 0%, #f57f17 100%);
816+
position: relative;
804817
overflow: hidden;
805-
z-index: 1;
806818
}
807819

820+
808821
/* Login card */
809822
.login-container {
810823
position: relative;
811824
z-index: 2;
812-
background: rgba(221, 221, 221, 0.85);
813-
backdrop-filter: blur(12px);
814-
padding: 45px 55px;
815-
border-radius: 18px;
816-
box-shadow: 0 15px 50px rgba(0, 0, 0, 0.7);
825+
background: #ffffff;
826+
padding: 40px;
827+
border-radius: 20px;
828+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
817829
width: 100%;
818-
max-width: 420px;
819-
border: 1px solid rgba(212, 175, 55, 0.25);
830+
max-width: 400px;
831+
border: 1px solid rgba(0, 0, 0, 0.05);
820832
}
821833

834+
835+
822836
.login-title {
823-
color: #16183a;
837+
color: #2c2c2c;
824838
text-align: center;
825-
margin-bottom: 35px;
826-
font-size: 2.5rem;
827-
text-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
839+
margin-bottom: 30px;
840+
font-size: 2.8rem;
841+
font-weight: 900;
842+
font-family: 'Instrument Serif', serif;
843+
font-style: italic;
828844
}
829845

846+
830847
.login-form {
831848
width: 100%;
832849
margin: 0 auto;
@@ -846,15 +863,17 @@ body.login-page {
846863
}
847864

848865
.form-input {
849-
width: 50vh;
850-
padding: 15px 5px 15px 5px;
851-
border: none;
852-
border-radius: 10px;
853-
background: rgba(255, 255, 255, 0.95);
854-
font-size: 1.05rem;
855-
color: #1a0f00;
866+
width: 100%;
867+
padding: 12px 16px;
868+
border: 1px solid #ddd;
869+
border-radius: 8px;
870+
background: white;
871+
font-size: 1rem;
872+
color: #333;
873+
transition: all 0.2s ease;
856874
}
857875

876+
858877
.form-input:focus {
859878
outline: none;
860879
background: #fff;
@@ -863,23 +882,25 @@ body.login-page {
863882

864883
.login-button {
865884
width: 100%;
866-
padding: 16px;
867-
background: #d4af37;
868-
color: #16183a;
885+
padding: 14px;
886+
background: #B87333;
887+
color: white;
869888
border: none;
870-
border-radius: 10px;
871-
font-size: 1.15rem;
872-
font-weight: bold;
889+
border-radius: 8px;
890+
font-size: 1.1rem;
891+
font-weight: 700;
873892
cursor: pointer;
874893
transition: all 0.3s ease;
875-
margin-top: 8px;
894+
margin-top: 10px;
876895
}
877896

878897
.login-button:hover {
879-
background: #f0d06b;
880-
transform: translateY(-3px);
898+
background: #ff9800;
899+
transform: translateY(-2px);
900+
box-shadow: 0 4px 12px rgba(184, 115, 51, 0.3);
881901
}
882902

903+
883904
.beer-hero::before {
884905
content: '';
885906
position: absolute;

0 commit comments

Comments
 (0)