Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -55,41 +55,6 @@ except Exception as e:
|
|
| 55 |
bucket = storage.bucket()
|
| 56 |
db_ref = db.reference()
|
| 57 |
|
| 58 |
-
# --- Create Dummy Admin Account on Startup ---
|
| 59 |
-
# This block ensures the specified admin user exists with the correct privileges.
|
| 60 |
-
# It's designed to run safely on every application start.
|
| 61 |
-
try:
|
| 62 |
-
ADMIN_EMAIL = "rairorr@gmail.com"
|
| 63 |
-
print(f"Checking for admin user: {ADMIN_EMAIL}")
|
| 64 |
-
try:
|
| 65 |
-
# 1. Check if the user exists in Firebase Auth by email. [4]
|
| 66 |
-
user = auth.get_user_by_email(ADMIN_EMAIL)
|
| 67 |
-
# 2. If user exists, ensure their DB record is correct
|
| 68 |
-
user_ref = db_ref.child(f'users/{user.uid}')
|
| 69 |
-
user_ref.update({
|
| 70 |
-
'is_admin': True,
|
| 71 |
-
'credits': 9999
|
| 72 |
-
})
|
| 73 |
-
print(f"Admin user '{ADMIN_EMAIL}' found and privileges verified.")
|
| 74 |
-
except auth.UserNotFoundError:
|
| 75 |
-
# 3. If user does not exist in Auth, create them. [8]
|
| 76 |
-
print(f"Admin user '{ADMIN_EMAIL}' not found, creating a new one.")
|
| 77 |
-
user = auth.create_user(
|
| 78 |
-
email=ADMIN_EMAIL,
|
| 79 |
-
password="neo2025"
|
| 80 |
-
)
|
| 81 |
-
# 4. Create their record in the Realtime Database
|
| 82 |
-
db_ref.child(f'users/{user.uid}').set({
|
| 83 |
-
'email': ADMIN_EMAIL,
|
| 84 |
-
'credits': 9999,
|
| 85 |
-
'is_admin': True,
|
| 86 |
-
'createdAt': datetime.utcnow().isoformat()
|
| 87 |
-
})
|
| 88 |
-
print(f"Successfully created admin user '{ADMIN_EMAIL}'.")
|
| 89 |
-
except Exception as e:
|
| 90 |
-
# Catch any other exceptions during the process
|
| 91 |
-
print(f"FATAL: An error occurred during admin account setup: {e}")
|
| 92 |
-
|
| 93 |
|
| 94 |
# --- Google GenAI Client Initialization (as per Streamlit app) ---
|
| 95 |
try:
|
|
|
|
| 55 |
bucket = storage.bucket()
|
| 56 |
db_ref = db.reference()
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
# --- Google GenAI Client Initialization (as per Streamlit app) ---
|
| 60 |
try:
|