Update modules/database.py
Browse files- modules/database.py +13 -0
modules/database.py
CHANGED
|
@@ -71,6 +71,19 @@ def initialize_mongodb_connection():
|
|
| 71 |
logger.error(f"Error al conectar con Cosmos DB MongoDB API: {str(e)}", exc_info=True)
|
| 72 |
return False
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
#######################################################################################################
|
| 75 |
# Funciones para Cosmos DB SQL API (manejo de usuarios)
|
| 76 |
def get_user(username):
|
|
|
|
| 71 |
logger.error(f"Error al conectar con Cosmos DB MongoDB API: {str(e)}", exc_info=True)
|
| 72 |
return False
|
| 73 |
|
| 74 |
+
#######################################################################################################
|
| 75 |
+
|
| 76 |
+
def create_admin_user(username, password):
|
| 77 |
+
hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
|
| 78 |
+
user_data = {
|
| 79 |
+
'id': username,
|
| 80 |
+
'password': hashed_password,
|
| 81 |
+
'is_invited': False,
|
| 82 |
+
'role': 'admin',
|
| 83 |
+
'created_at': datetime.utcnow().isoformat()
|
| 84 |
+
}
|
| 85 |
+
user_container.create_item(body=user_data)
|
| 86 |
+
|
| 87 |
#######################################################################################################
|
| 88 |
# Funciones para Cosmos DB SQL API (manejo de usuarios)
|
| 89 |
def get_user(username):
|