@@ -72,7 +72,7 @@ async def register_user(
7272 except DuplicateKeyError :
7373 raise HTTPException (
7474 status_code = status .HTTP_400_BAD_REQUEST ,
75- detail = "User with this email already exists " ,
75+ detail = "Esiste già un utente con questa email " ,
7676 )
7777 except Exception as e :
7878 raise HTTPException (
@@ -86,16 +86,12 @@ async def register_user(
8686 subject = f"[Suppl-AI] Registrazione utente" ,
8787 body = f"Benvenuto in Suppl-AI!\n Ecco la tua password temporanea\n \n { password } \n \n Accedi e cambiala subito!" ,
8888 )
89- except Exception :
90- # raise HTTPException(
91- # status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
92- # detail=f"Failed to send email to user: {e}",
93- # )
94- print (" Error: Failed to send to user the password" )
95- print (f" To: { user_data .email } " )
96- print (f" Subject: [Suppl-AI] Registrazione utente" )
97- print (f" Body: Benvenuto in Suppl-AI!\n Ecco la tua password temporanea\n \n { password } \n \n Accedi e cambiala subito!" )
98- print (" Error: Failed to send email to user" )
89+ except Exception as e :
90+ raise HTTPException (
91+ status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
92+ detail = f"Failed to send email to user: { e } " ,
93+ )
94+ # print(f" Error: Failed to send to user the password: {e}")
9995
10096 return {"message" : "User registered successfully" , "password" : password }
10197
@@ -178,9 +174,17 @@ async def update_user(
178174 * **HTTPException.HTTP_500_INTERNAL_SERVER_ERROR**: Se si verifica un errore durante l'aggiornamento dell'utente.
179175 * **HTTPException.HTTP_304_NOT_MODIFIED**: Se i dati forniti corrispondono a quelli esistenti.
180176 """
181- # Rimove il campo password (usa /password per cambiarla)
182177 user_new_data .password = None
183-
178+ # Verifica che l'admin esista e che la password sia corretta
179+ valid_user = await authenticate_user (
180+ current_user .get ("sub" ), user_new_data .admin_password , user_repo
181+ )
182+ if not valid_user :
183+ raise HTTPException (
184+ status_code = status .HTTP_401_UNAUTHORIZED ,
185+ detail = "Invalid admin password" ,
186+ )
187+
184188 # Aggiorna i dati dell'utente nel database
185189 result = await user_repo .update_user (
186190 user_id = user_new_data .id ,
@@ -360,16 +364,13 @@ async def reset_password(
360364 subject = "[Suppl-AI] Password Reset" ,
361365 body = f"Ciao { user .get ('name' )} ,\n \n Ecco la tua nuova password temporanea:\n \n { password } \n \n Accedi e cambiala subito!" ,
362366 )
363- except Exception :
367+ except Exception as e :
364368 # raise HTTPException(
365369 # status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
366370 # detail=f"Failed to send email to user: {e}",
367371 # )
368372 print (" Error: Failed to send to user the password" )
369- print (f" To: { user_data .email } " )
370- print (f" Subject: [Suppl-AI] Password Reset" )
371- print (f" Body: Ciao { user .get ('name' )} ,\n \n Ecco la tua nuova password temporanea:\n \n { password } \n \n Accedi e cambiala subito!" )
372- print (" Error: Failed to send email to user" )
373+
373374 except Exception as e :
374375 raise HTTPException (
375376 status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
0 commit comments