Spaces:
Sleeping
Sleeping
Update database.py
Browse files- database.py +17 -7
database.py
CHANGED
|
@@ -269,11 +269,19 @@ def create_user(email, password):
|
|
| 269 |
password_hash, salt = hash_password(password)
|
| 270 |
confirmation_token = generate_token()
|
| 271 |
|
| 272 |
-
# For HF Spaces demo mode, auto-confirm emails
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
|
| 278 |
# Insert user
|
| 279 |
cursor = db.execute(
|
|
@@ -292,15 +300,17 @@ def create_user(email, password):
|
|
| 292 |
db.commit()
|
| 293 |
|
| 294 |
if auto_confirm:
|
| 295 |
-
logger.info(f"User created and auto-confirmed: {email} (demo mode)")
|
|
|
|
| 296 |
else:
|
| 297 |
logger.info(f"User created: {email}")
|
|
|
|
| 298 |
|
| 299 |
return {
|
| 300 |
'success': True,
|
| 301 |
'user_id': user_id,
|
| 302 |
'confirmation_token': confirmation_token,
|
| 303 |
-
'message':
|
| 304 |
'auto_confirmed': auto_confirm
|
| 305 |
}
|
| 306 |
|
|
|
|
| 269 |
password_hash, salt = hash_password(password)
|
| 270 |
confirmation_token = generate_token()
|
| 271 |
|
| 272 |
+
# For HF Spaces demo mode, auto-confirm emails
|
| 273 |
+
is_hf_spaces = os.environ.get('SPACE_ID') is not None
|
| 274 |
+
has_smtp_username = os.environ.get('SMTP_USERNAME') is not None
|
| 275 |
+
has_smtp_password = os.environ.get('SMTP_PASSWORD') is not None
|
| 276 |
+
has_smtp = has_smtp_username and has_smtp_password
|
| 277 |
+
|
| 278 |
+
# Sempre auto-confirmar no HF Spaces ou quando SMTP não está configurado
|
| 279 |
+
auto_confirm = is_hf_spaces or not has_smtp
|
| 280 |
+
|
| 281 |
+
# Debug logging
|
| 282 |
+
logger.info(f"Registration debug - SPACE_ID: {os.environ.get('SPACE_ID')}")
|
| 283 |
+
logger.info(f"HF_Spaces: {is_hf_spaces}, SMTP_USER: {has_smtp_username}, SMTP_PASS: {has_smtp_password}")
|
| 284 |
+
logger.info(f"SMTP configured: {has_smtp}, Auto-confirm: {auto_confirm}")
|
| 285 |
|
| 286 |
# Insert user
|
| 287 |
cursor = db.execute(
|
|
|
|
| 300 |
db.commit()
|
| 301 |
|
| 302 |
if auto_confirm:
|
| 303 |
+
logger.info(f"User created and auto-confirmed: {email} (HF Spaces demo mode)")
|
| 304 |
+
message = 'Account created and ready to use! (Demo mode - no email confirmation needed)'
|
| 305 |
else:
|
| 306 |
logger.info(f"User created: {email}")
|
| 307 |
+
message = 'User created successfully. Please check your email for confirmation.'
|
| 308 |
|
| 309 |
return {
|
| 310 |
'success': True,
|
| 311 |
'user_id': user_id,
|
| 312 |
'confirmation_token': confirmation_token,
|
| 313 |
+
'message': message,
|
| 314 |
'auto_confirmed': auto_confirm
|
| 315 |
}
|
| 316 |
|