Update main.py
Browse files
main.py
CHANGED
|
@@ -43,58 +43,7 @@ except Exception as e:
|
|
| 43 |
exit(1)
|
| 44 |
|
| 45 |
|
| 46 |
-
### ======================================================================= ###
|
| 47 |
-
### ONE-TIME ADMIN ACCOUNT CREATION SCRIPT ###
|
| 48 |
-
### ###
|
| 49 |
-
### This block will run automatically when the server starts. ###
|
| 50 |
-
### After confirming the accounts are created, DELETE this entire block. ###
|
| 51 |
-
### ======================================================================= ###
|
| 52 |
-
try:
|
| 53 |
-
logging.info("--- [RUN-ONCE SCRIPT] Checking/Creating Admin Accounts ---")
|
| 54 |
-
|
| 55 |
-
admins_to_create = [
|
| 56 |
-
{'email': 'rairorr@gmail.com', 'password': 'sqx2025!', 'displayName': 'Rai'},
|
| 57 |
-
{'email': 'helperzhou@gmail.com', 'password': 'sqx2025!', 'displayName': 'Helper Zhou'}
|
| 58 |
-
]
|
| 59 |
-
|
| 60 |
-
for admin_data in admins_to_create:
|
| 61 |
-
email = admin_data['email']
|
| 62 |
-
try:
|
| 63 |
-
# 1. Check if the user already exists in Firebase Auth
|
| 64 |
-
user = auth.get_user_by_email(email)
|
| 65 |
-
logging.info(f"Admin user '{email}' already exists. Ensuring admin status in Firestore.")
|
| 66 |
-
# 2. If they exist, just ensure their Firestore profile is set to admin
|
| 67 |
-
db.collection('users').document(user.uid).set({'isAdmin': True}, merge=True)
|
| 68 |
-
|
| 69 |
-
except auth.UserNotFoundError:
|
| 70 |
-
# 3. If the user does not exist, create them
|
| 71 |
-
logging.info(f"Admin user '{email}' not found. Creating new account.")
|
| 72 |
-
new_user = auth.create_user(
|
| 73 |
-
email=admin_data['email'],
|
| 74 |
-
password=admin_data['password'],
|
| 75 |
-
display_name=admin_data['displayName']
|
| 76 |
-
)
|
| 77 |
-
|
| 78 |
-
# 4. Create their profile in Firestore and set them as an admin
|
| 79 |
-
user_profile = {
|
| 80 |
-
'uid': new_user.uid,
|
| 81 |
-
'email': new_user.email,
|
| 82 |
-
'displayName': new_user.display_name,
|
| 83 |
-
'isAdmin': True, # <<< CRITICAL: Set as admin
|
| 84 |
-
'phone': None,
|
| 85 |
-
'phoneStatus': 'unsubmitted',
|
| 86 |
-
'createdAt': firestore.SERVER_TIMESTAMP
|
| 87 |
-
}
|
| 88 |
-
db.collection('users').document(new_user.uid).set(user_profile)
|
| 89 |
-
logging.info(f"Successfully created admin account for '{email}'.")
|
| 90 |
-
|
| 91 |
-
logging.info("--- [RUN-ONCE SCRIPT] Admin setup complete. You can now delete this script block. ---")
|
| 92 |
|
| 93 |
-
except Exception as e:
|
| 94 |
-
logging.error(f"--- [RUN-ONCE SCRIPT] An error occurred during admin setup: {e} ---")
|
| 95 |
-
### ======================================================================= ###
|
| 96 |
-
### END OF ONE-TIME SCRIPT ###
|
| 97 |
-
### ======================================================================= ###
|
| 98 |
|
| 99 |
|
| 100 |
|
|
|
|
| 43 |
exit(1)
|
| 44 |
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
|
| 49 |
|