mirror of
https://github.com/wolfswolke/DeathGarden_API_Rebirth.git
synced 2026-09-09 17:46:34 -05:00
Added mongodb_handler.py for User AUTH
This commit is contained in:
@@ -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
|
||||
29
src/logic/mongodb_handler.py
Normal file
29
src/logic/mongodb_handler.py
Normal 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
|
||||
|
||||
Reference in New Issue
Block a user