Added mongodb_handler.py for User AUTH

This commit is contained in:
ZKWolf
2023-06-08 01:25:19 +02:00
parent f68cf2effe
commit 177e118fff
2 changed files with 34 additions and 1 deletions

View File

@@ -6,4 +6,8 @@ graylog:
host: host
use: false
steam:
api_key: XXXXXXXXXXXX
api_key: XXXXXXXXXXXX
mongodb:
host: mongodb://IP:27017/
db: db_name
collection: collection_name

View File

@@ -0,0 +1,29 @@
import pymongo
import uuid
def user_db_handler(steamid, server, db, collection):
client = pymongo.MongoClient(server)
db = client[db]
collection = db[collection]
existing_document = collection.find_one({'steamid': steamid})
if existing_document:
print(f"Document with steamid {steamid} already exists.")
userId = existing_document['userId']
token = existing_document['token']
return userId, token
else:
userId = str(uuid.uuid4())
token = str(uuid.uuid4())
new_document = {
'steamid': steamid,
'userId': userId,
'token': token
}
collection.insert_one(new_document)
return userId, token