Skip to content

Commit edf47af

Browse files
Merge pull request #35 from goncalopinto1/UI/admin-page
started implementing css on admin page
2 parents e902bea + 0a301d5 commit edf47af

File tree

11 files changed

+245
-59
lines changed

11 files changed

+245
-59
lines changed

backend/main.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,39 @@ def update_post(post_id: int, update: PostUpdate, user_credentials: str = Depend
110110
return update_posts(post_id, update)
111111

112112

113+
# ⚠️ ENDPOINT TEMPORÁRIO - REMOVER DEPOIS!
114+
@app.post("/secret-setup-admin-xyz123")
115+
async def setup_admin(secret_key: str):
116+
if secret_key != "meu-portfolio-2026-setup":
117+
raise HTTPException(status_code=403)
118+
119+
import bcrypt # ✅ Usa bcrypt direto
120+
from backend.models import Users
121+
from backend.database import SessionLocal
122+
123+
db = SessionLocal()
124+
125+
# Apaga se existir
126+
existing = db.query(Users).filter(Users.email == "goncalo.luis.pinto@gmail.com").first()
127+
if existing:
128+
db.delete(existing)
129+
db.commit()
130+
131+
# Hash com bcrypt direto (evita o bug do passlib)
132+
password = os.getenv("ADMIN_PASSWORD")
133+
salt = bcrypt.gensalt()
134+
hashed = bcrypt.hashpw(password.encode('utf-8'), salt).decode('utf-8')
135+
136+
admin = Users(
137+
email=os.getenv("ADMIN_EMAIL"),
138+
hashed_password=hashed
139+
)
140+
db.add(admin)
141+
db.commit()
142+
db.close()
143+
144+
return {"message": "✅ Admin criado!", "email": "goncalo.luis.pinto@gmail.com"}
145+
113146
@app.get("/{page_name}", include_in_schema=False)
114147
async def serve_page(page_name: str, request: Request):
115148
if request.method != "GET":

frontend/pages/add-post.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<script type="module" src="../scripts/add-post.js"></script>
1010
</head>
1111
<body class="admin">
12-
<h1>Create a Post</h1>
12+
<h1 class="admin title">Create a Post</h1>
1313

1414
<form id="add-post">
1515
<input id="title" "text" placeholder="title" required/>
@@ -20,10 +20,15 @@ <h1>Create a Post</h1>
2020
Publish this Post
2121
</label>
2222

23-
<button type="submit">Create Post</button>
23+
<button type="submit">
24+
<span class="button_top"> Create Post </span>
25+
</button>
26+
2427
</form>
2528

2629
<p id="status" class="status hidden"></p>
27-
<button id="home" type="button">Back to admin page</button>
30+
<button id="home" type="button">
31+
<span class="button_top"> Back to admin </span>
32+
</button>
2833
</body>
2934
</html>

frontend/pages/admin-login.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
<link rel="icon" href="../../docs/images/Logo.png" type="image/png">
99
<script type="module" defer src="../scripts/admin-login.js"></script>
1010
</head>
11-
<body>
11+
<body class="admin">
12+
<h1 class="admin title">Login</h1>
1213
<form id="admin-login">
1314
<input id="email" type="email" placeholder="Email" required />
1415
<input id="password" type="password" placeholder="Password" required />
15-
<button type="submit">Log in</button>
16+
<button>
17+
<span class="button_top"> Log In </span>
18+
</button>
19+
1620
</form>
1721
</body>
1822
</html>

frontend/pages/admin.html

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,45 @@
1515

1616
</head>
1717
<body class="admin">
18-
<h1>Admin Page</h1>
18+
<h1 class="admin title">Admin Page</h1>
1919

2020
<div >
21-
<h1>Contacts</h1>
21+
<h1 class="admin title">Contacts</h1>
22+
23+
<div class="search-bar">
24+
<input placeholder="Searth contacts..." type="search" id="search" name="text" class="input">
25+
26+
<button id="filter" type="button">
27+
<span class="button_top"> Filter </span>
28+
</button>
2229

23-
<div>
24-
<input type="search" id="search" placeholder="Search by name/email">
2530
</div>
2631

27-
<button type="button" id="filter">Filter</button>
2832

2933
<p id="status" class = "status hidden"></p>
3034

3135
<div id="contacts-admin"></div>
3236
</div>
3337

3438
<div>
35-
<h1>Posts</h1>
39+
<h1 class="admin title">Posts</h1>
40+
41+
42+
<button id="add-button" type="button">
43+
<span class="button_top"> Create Post </span>
44+
</button>
3645

37-
<button id="add-button" type="button" class="add-btn">Create Post</button>
3846
<div id="posts-admin"></div>
3947
</div>
4048

4149
<div class="charts">
42-
<h1>Messages per Week</h1>
50+
<h1 class="admin title">Messages per Week</h1>
4351
<canvas id="messages-week"></canvas>
4452

45-
<h1>Read vs Unread</h1>
53+
<h1 class="admin title">Read vs Unread</h1>
4654
<canvas id="read-unread"></canvas>
4755

48-
<h1>Messages per day of week</h1>
56+
<h1 class="admin title">Messages per day of week</h1>
4957
<canvas id="messages-day"></canvas>
5058
</div>
5159
</body>

frontend/pages/edit-post.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@
1515
<script type="module" src="../scripts/edit-post.js"></script>
1616
</head>
1717
<body class="admin">
18-
<h1>Edit Post</h1>
18+
<h1 class="admin title">Edit Post</h1>
1919

2020
<div id="atual-post"></div>
2121

22-
<form id="edit-post">
23-
<input id="title" type="text" placeholder="title" required/>
22+
<form id="edit-post">
23+
<input id="title" type="text" placeholder="title" required/>
2424
<textarea id="content" type="text" placeholder="content" required></textarea>
2525

2626
<label>
2727
<input type="checkbox" name="published" id="published" value="published" />
2828
Publish this Post
2929
</label>
3030

31-
<button id="edit" type="submit">Edit Post</button>
31+
<button id="edit" type="submit">
32+
<span class="button_top"> Edit Post </span>
33+
</button>
34+
3235
</form>
3336
</body>
3437
</html>

frontend/pages/filters.html

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,63 +10,68 @@
1010
<script type="module" src="../scripts/filters.js"></script>
1111
</head>
1212
<body class="admin">
13-
<h1>Filters</h1>
13+
<h1 class="admin title">Filters</h1>
1414

1515
<div class="status">
16-
<h2>Status:</h2>
17-
<label>
16+
<h2 class="admin subtitle"><strong>Status:</strong></h2>
17+
<label class="admin text">
1818
<input type="radio" id="read" name="status" value="read">
1919
Read
2020
</label>
2121

22-
<label>
22+
<label class="admin text">
2323
<input type="radio" id="unread" name="status" value="unread">
2424
Unread
2525
</label>
2626
</div>
2727

2828
<div class="order">
29-
<h2>Order:</h2>
30-
<label>
29+
<h2 class="admin subtitle"><strong>Order:</strong></h2>
30+
<label class="admin text">
3131
<input type="radio" id="recent-oldest" name="order" value="recent-oldest">
3232
Recent-Oldest
3333
</label>
3434

35-
<label>
35+
<label class="admin text">
3636
<input type="radio" id="oldest-recent" name="order" value="oldest-recent">
3737
Oldest-Recent
3838
</label>
3939
</div>
4040

4141
<div class="date-range">
42-
<h2>Date Range:</h2>
43-
<label>
42+
<h2 class="admin subtitle"><strong>Date Range:</strong></h2>
43+
<label class="admin text">
4444
<input type="date" id="date-from" name="date-from">
4545
From:
4646
</label>
4747

48-
<label>
48+
<label class="admin text">
4949
<input type="date" id="date-to" name="date-to">
5050
To:
5151
</label>
5252
</div>
5353

5454
<div class="Alphabetical">
55-
<h2>Alphabetical:</h2>
56-
<label>
55+
<h2 class="admin subtitle"><strong>Alphabetical:</strong></h2>
56+
<label class="admin text">
5757
<input type="radio" id="a-z" name="alphabetic" value="a-z">
5858
A-Z
5959
</label>
6060

61-
<label>
61+
<label class="admin text">
6262
<input type="radio" id="z-a" name="alphabetic" value="z-a">
6363
Z-A
6464
</label>
6565
</div>
6666

6767
<div class="filter-actions">
68-
<button type="button" id="apply-filters">Apply filters</button>
69-
<button type="button" id="clear-filters">Clear all</button>
68+
<button type="button" id="apply-filters">
69+
<span class="button_top"> Apply Filters </span>
70+
</button>
71+
72+
<button type="button" id="clear-filters">
73+
<span class="button_top"> Clear Filters </span>
74+
</button>
7075
</div>
7176
</body>
7277
</html>

frontend/pages/reply.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<script type="module" defer src="../scripts/reply.js"></script>
1111
</head>
1212
<body class="admin">
13-
<h1>Respond to contact</h1>
13+
<h1 class="admin title">Respond to contact</h1>
1414

1515
<div class="contact-info">
1616
<p id="from"></p>
@@ -19,7 +19,9 @@ <h1>Respond to contact</h1>
1919

2020
<form id="reply-form">
2121
<textarea id="reply-message" type="text" required></textarea>
22-
<button type="submit">Send reply</button>
22+
<button type="submit">
23+
<span class="button_top"> Send Reply </span>
24+
</button>
2325
</form>
2426

2527
<p id="status" class="status hidden"></p>

frontend/scripts/admin.js

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,32 @@ function renderContacts(cachedContacts) {
100100
else card.className = "contact-card read";
101101

102102
card.innerHTML = `
103-
<h3>${c.name}</h3>
104-
<p>${c.email}</p>
105-
<p>${c.message}</p>
103+
<h3 class="admin subtitle"><strong>Name: </strong>${c.name}</h3>
104+
<p class="admin text"><strong>Email: </strong>${c.email}</p>
105+
<p class="admin text"><strong>Message: </strong>${c.message}</p>
106106
`
107107
const deleteButton = document.createElement("button");
108-
deleteButton.classList.add("delete-btn");
108+
const delSpan = document.createElement("span");
109+
delSpan.className = "button_top";
110+
delSpan.textContent = "Delete Contact"
111+
109112
deleteButton.type = "button";
110-
deleteButton.textContent = "Delete";
113+
114+
deleteButton.appendChild(delSpan);
111115

112116
deleteButton.addEventListener("click", () => {
113117
deleteContact(c.id);
114118
});
115119

116120
if(c.is_read == 0){
117121
const markReadButton = document.createElement("button");
118-
markReadButton.classList.add("mark-read-btn");
119122
markReadButton.type = "button";
120-
markReadButton.textContent = "Mark as read"
123+
124+
const markSpan = document.createElement("span");
125+
markSpan.className = "button_top";
126+
markSpan.textContent = "Mark as read";
127+
128+
markReadButton.appendChild(markSpan);
121129

122130
markReadButton.addEventListener("click", () => {
123131
markAsRead(c.id);
@@ -127,9 +135,14 @@ function renderContacts(cachedContacts) {
127135
}
128136

129137
const responseButton = document.createElement("button");
130-
responseButton.classList.add("response-btn");
131138
responseButton.type = "button";
132-
responseButton.textContent = "Respond to message";
139+
140+
const respSpan = document.createElement("span");
141+
respSpan.className = "button_top";
142+
respSpan.textContent = "Respond to contact";
143+
144+
responseButton.appendChild(respSpan);
145+
133146

134147
responseButton.addEventListener("click", () => {
135148
window.location.href = `../pages/reply.html?contact_id=${c.id}`;
@@ -294,24 +307,32 @@ function renderPosts(posts){
294307
const safeHTML = DOMPurify.sanitize(marked.parse(rawContent));
295308

296309
card.innerHTML = `
297-
<h3><strong>Title: </strong>${p.title}</h3>
298-
<div class="post-content">${safeHTML}</div>
299-
<p><strong>Date: </strong>${date.toLocaleDateString()}</p>
300-
<p><strong>Is published?: </strong>${p.published}</p>
310+
<h3 class="admin subtitle"><strong>Title: </strong>${p.title}</h3>
311+
<div class="post-content admin text">${safeHTML}</div>
312+
<p class="admin text"><strong>Date: </strong>${date.toLocaleDateString()}</p>
313+
<p class="admin text"><strong>Published: </strong>${p.published}</p>
301314
`
302315
const deleteButton = document.createElement("button");
303-
deleteButton.classList.add("delete-btn");
304316
deleteButton.type = "button";
305-
deleteButton.textContent = "Delete Post";
317+
318+
const delSpan = document.createElement("span");
319+
delSpan.className = "button_top";
320+
delSpan.textContent = "Delete Post";
321+
322+
deleteButton.appendChild(delSpan);
306323

307324
deleteButton.addEventListener("click", () => {
308325
deletePost(p.id);
309326
});
310327

311328
const editButton = document.createElement("button");
312-
editButton.classList.add("edit-btn");
313329
editButton.type = "button";
314-
editButton.textContent = "Edit Post";
330+
331+
const editSpan = document.createElement("span");
332+
editSpan.className = "button_top";
333+
editSpan.textContent = "Edit Post";
334+
335+
editButton.appendChild(editSpan);
315336

316337
editButton.addEventListener("click", () => {
317338
window.location.href = `../pages/edit-post.html?post_id=${p.id}`;

frontend/scripts/edit-post.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ async function EditPost(id){
3737
const safeHTML = DOMPurify.sanitize(marked.parse(rawContent));
3838

3939
card.innerHTML = `
40-
<h3><strong>Title:</strong>${post.title}</h3>
41-
<div class="post-content">${safeHTML}</div>
40+
<h3 class="admin subtitle"><strong>Title:</strong>${post.title}</h3>
41+
<div class="post-content admin text">${safeHTML}</div>
4242
`
4343

4444
container.appendChild(card);

frontend/scripts/reply.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ document.addEventListener("DOMContentLoaded", async () => {
4040
return;
4141
}
4242

43-
document.getElementById("from").innerHTML =`<strong>From: </strong>${contact.name} (${contact.email})`;
44-
document.getElementById("message").innerHTML = `<strong>Message: </strong>${contact.message}`;
43+
document.getElementById("from").innerHTML =`<p class="admin text"><strong>From: </strong>${contact.name} (${contact.email})</p>`;
44+
document.getElementById("message").innerHTML = `<p class="admin text"><strong>Message: </strong>${contact.message}</p>`;
4545

4646
} catch (error){
4747
console.log("❌ Error:", error);

0 commit comments

Comments
 (0)