@@ -113,26 +113,24 @@ def update_post(post_id: int, update: PostUpdate, user_credentials: str = Depend
113113@app .post ("/secret-setup-admin-xyz123" )
114114async 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 )
153146async def serve_page (page_name : str , request : Request ):
0 commit comments