mirror of
https://github.com/wolfswolke/DeathGarden_API_Rebirth.git
synced 2026-07-19 17:33:11 -05:00
Implemented EULA
This commit is contained in:
parent
3f337882e7
commit
23d7242e07
|
|
@ -4,6 +4,8 @@ import flask_definitions
|
|||
from flask_definitions import *
|
||||
import os
|
||||
|
||||
from logic.mongodb_handler import mongo
|
||||
|
||||
|
||||
@app.route("/gamenews/messages", methods=["GET"])
|
||||
def gamenews():
|
||||
|
|
@ -209,24 +211,27 @@ def content_version1():
|
|||
@app.route("/api/v1/consent/eula2", methods=["PUT", "GET"])
|
||||
def consent_eula():
|
||||
get_remote_ip()
|
||||
if request.method == "PUT":
|
||||
try:
|
||||
print("Responded to consent eula api call PUT")
|
||||
return jsonify({"status": "success"})
|
||||
except TimeoutError:
|
||||
print("Timeout error")
|
||||
return jsonify({"status": "error"})
|
||||
except Exception as e:
|
||||
logger.graylog_logger(level="error", handler="general-consent-eula", message=f"Error in consent_eula: {e}")
|
||||
elif request.method == "GET":
|
||||
try:
|
||||
print("Responded to consent eula api call GET")
|
||||
return jsonify({"isGiven": True})
|
||||
except TimeoutError:
|
||||
print("Timeout error")
|
||||
return jsonify({"status": "error"})
|
||||
except Exception as e:
|
||||
logger.graylog_logger(level="error", handler="general-consent-eula", message=f"Error in consent_eula: {e}")
|
||||
try:
|
||||
if request.method == "PUT":
|
||||
userid = request.cookies.get('bhvrSession')
|
||||
try:
|
||||
mongo.eula(userId=userid, get_eula=False, server=mongo_host, db=mongo_db, collection=mongo_collection)
|
||||
print("Responded to consent eula api call PUT")
|
||||
return jsonify({"isGiven": True})
|
||||
except TimeoutError:
|
||||
print("Timeout error")
|
||||
return jsonify({"status": "error"})
|
||||
except Exception as e:
|
||||
logger.graylog_logger(level="error", handler="general-consent-eula", message=f"Error in consent_eula: {e}")
|
||||
elif request.method == "GET":
|
||||
userid = request.cookies.get('bhvrSession')
|
||||
is_given = mongo.eula(userId=userid, get_eula=True, server=mongo_host, db=mongo_db, collection=mongo_collection)
|
||||
if is_given:
|
||||
return jsonify({"isGiven": True})
|
||||
else:
|
||||
return jsonify({"isGiven": False})
|
||||
except Exception as e:
|
||||
logger.graylog_logger(level="error", handler="general-consent-eula", message=f"Error in consent_eula: {e}")
|
||||
|
||||
|
||||
@app.route("/api/v1/consent/eula", methods=["GET"])
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ class Mongo:
|
|||
new_document = {
|
||||
'steamid': steamid,
|
||||
'userId': userId,
|
||||
'token': token
|
||||
'token': token,
|
||||
'eula': False
|
||||
}
|
||||
|
||||
self.dyn_collection.insert_one(new_document)
|
||||
|
|
@ -63,5 +64,28 @@ class Mongo:
|
|||
print(e)
|
||||
return None, None
|
||||
|
||||
def eula(self, userId, get_eula, server, db, collection):
|
||||
try:
|
||||
self.dyn_server = server
|
||||
self.dyn_db = db
|
||||
self.dyn_collection = collection
|
||||
client = pymongo.MongoClient(self.dyn_server)
|
||||
self.dyn_db = client[self.dyn_db]
|
||||
self.dyn_collection = self.dyn_db[self.dyn_collection]
|
||||
existing_document = self.dyn_collection.find_one({'userId': userId})
|
||||
if existing_document:
|
||||
if get_eula:
|
||||
eula = existing_document['eula']
|
||||
return eula
|
||||
else:
|
||||
self.dyn_collection.update_one({'userId': userId}, {'$set': {'eula': True}})
|
||||
return True
|
||||
else:
|
||||
print(f"No user found with userId: {userId}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return None, None
|
||||
|
||||
|
||||
mongo = Mongo()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user