Skip to content

Commit 5fa8055

Browse files
Merge pull request #25 from goncalopinto1/feature/admin-page
Add temporary admin setup endpoint
2 parents d03220c + dcff93d commit 5fa8055

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

backend/main.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,38 @@ def delete_post(post_id: int, user_credentials: str = Depends(verify_token)):
108108
def update_post(post_id: int, update: PostUpdate, user_credentials: str = Depends(verify_token)):
109109
return update_posts(post_id, update)
110110

111+
# ⚠️ ENDPOINT TEMPORÁRIO - REMOVER DEPOIS!
112+
@app.post("/secret-setup-admin-xyz123")
113+
async def setup_admin(secret_key: str):
114+
# Proteção básica
115+
if secret_key != "meu-portfolio-2026-setup":
116+
raise HTTPException(status_code=403, detail="Forbidden")
117+
118+
from passlib.context import CryptContext
119+
from backend.models import User
120+
from backend.database import SessionLocal
121+
122+
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
123+
124+
# Verifica se já existe admin
125+
db = SessionLocal()
126+
existing = db.query(User).filter(User.email == "goncalo.luis.pinto@gmail.com").first()
127+
128+
if existing:
129+
db.close()
130+
return {"message": "Admin já existe!"}
131+
132+
# Cria admin
133+
admin = User(
134+
email="goncalo.luis.pinto@gmail.com",
135+
password=pwd_context.hash("BestAdmin") # ← MUDA ISTO!
136+
)
137+
db.add(admin)
138+
db.commit()
139+
db.close()
140+
141+
return {"message": "✅ Admin criado com sucesso!", "email": "goncalo.luis.pinto@gmail.com"}
142+
111143
@app.get("/{page_name}", include_in_schema=False)
112144
async def serve_page(page_name: str, request: Request):
113145
if request.method != "GET":

0 commit comments

Comments
 (0)