diff --git a/src/config/example_config.yaml b/src/config/example_config.yaml index cf58c78..f33eeff 100644 --- a/src/config/example_config.yaml +++ b/src/config/example_config.yaml @@ -6,4 +6,8 @@ graylog: host: host use: false steam: - api_key: XXXXXXXXXXXX \ No newline at end of file + api_key: XXXXXXXXXXXX +mongodb: + host: mongodb://IP:27017/ + db: db_name + collection: collection_name \ No newline at end of file diff --git a/src/logic/mongodb_handler.py b/src/logic/mongodb_handler.py new file mode 100644 index 0000000..d90d49b --- /dev/null +++ b/src/logic/mongodb_handler.py @@ -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 +