Skip to content

Commit 87ed824

Browse files
Merge pull request #32 from goncalopinto1/feature/admin-page
some changes
2 parents b85c893 + 3e8637a commit 87ed824

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

backend/main.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,26 +113,24 @@ def update_post(post_id: int, update: PostUpdate, user_credentials: str = Depend
113113
@app.post("/secret-setup-admin-xyz123")
114114
async def setup_admin(secret_key: str):
115115
if secret_key != "meu-portfolio-2026-setup":
116-
raise HTTPException(status_code=403, detail="Forbidden")
116+
raise HTTPException(status_code=403)
117117

118-
from passlib.context import CryptContext
118+
import bcrypt # ✅ Usa bcrypt direto
119119
from backend.models import Users
120120
from backend.database import SessionLocal
121121

122-
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
123-
124122
db = SessionLocal()
125123

126-
# Apaga se existir
124+
# Apaga se existir
127125
existing = db.query(Users).filter(Users.email == "goncalo.luis.pinto@gmail.com").first()
128126
if existing:
129-
print(f"⚠️ Admin já existe! Apagando...")
130127
db.delete(existing)
131128
db.commit()
132129

133-
# Cria novo
134-
password = "admin123" # ✅ Simples
135-
hashed = pwd_context.hash(password)
130+
# Hash com bcrypt direto (evita o bug do passlib)
131+
password = "admin123"
132+
salt = bcrypt.gensalt()
133+
hashed = bcrypt.hashpw(password.encode('utf-8'), salt).decode('utf-8')
136134

137135
admin = Users(
138136
email="goncalo.luis.pinto@gmail.com",
@@ -142,12 +140,7 @@ async def setup_admin(secret_key: str):
142140
db.commit()
143141
db.close()
144142

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-
}
143+
return {"message": "✅ Admin criado!", "email": "goncalo.luis.pinto@gmail.com"}
151144

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

backend/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ psycopg2-binary
1010
httpx
1111
pydantic-settings
1212
email-validator
13-
python-multipart
13+
python-multipart
14+
bcrypt==4.1.2

0 commit comments

Comments
 (0)