Skip to content

Commit b85c893

Browse files
Merge pull request #31 from goncalopinto1/feature/admin-page
work
2 parents 3634e8b + a43c13d commit b85c893

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

backend/main.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ def update_post(post_id: int, update: PostUpdate, user_credentials: str = Depend
112112
# ⚠️ ENDPOINT TEMPORÁRIO - REMOVER DEPOIS!
113113
@app.post("/secret-setup-admin-xyz123")
114114
async def setup_admin(secret_key: str):
115-
# Proteção básica
116115
if secret_key != "meu-portfolio-2026-setup":
117116
raise HTTPException(status_code=403, detail="Forbidden")
118117

@@ -122,24 +121,33 @@ async def setup_admin(secret_key: str):
122121

123122
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
124123

125-
# Verifica se já existe admin
126124
db = SessionLocal()
127-
existing = db.query(Users).filter(Users.email == "goncalo.luis.pinto@gmail.com").first()
128125

126+
# ✅ Apaga se existir
127+
existing = db.query(Users).filter(Users.email == "goncalo.luis.pinto@gmail.com").first()
129128
if existing:
130-
db.close()
131-
return {"message": "Admin já existe!"}
129+
print(f"⚠️ Admin já existe! Apagando...")
130+
db.delete(existing)
131+
db.commit()
132+
133+
# Cria novo
134+
password = "admin123" # ✅ Simples
135+
hashed = pwd_context.hash(password)
132136

133-
# Cria admin
134137
admin = Users(
135138
email="goncalo.luis.pinto@gmail.com",
136-
hashed_password=pwd_context.hash("BestAdmin") # ← MUDA ISTO!
139+
hashed_password=hashed
137140
)
138141
db.add(admin)
139142
db.commit()
140143
db.close()
141144

142-
return {"message": "✅ Admin criado com sucesso!", "email": "goncalo.luis.pinto@gmail.com"}
145+
return {
146+
"message": "✅ Admin criado/recriado!",
147+
"email": "goncalo.luis.pinto@gmail.com",
148+
"password": password, # ⚠️ Só para debug - remove depois
149+
"hash_preview": hashed[:30] + "..."
150+
}
143151

144152
@app.get("/{page_name}", include_in_schema=False)
145153
async def serve_page(page_name: str, request: Request):

0 commit comments

Comments
 (0)