magmaus3
44b79518a5
It took me too long to complete it, I hope this thing will work for more than 10 minutes. It also breaks when user rated a level that was already rated.
56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
from datetime import datetime
|
|
from pymongo import MongoClient
|
|
|
|
|
|
client = MongoClient("mongodb://root:catboys@mongo:27017")
|
|
|
|
|
|
db = client["IWM_CustomServer_DB"]
|
|
|
|
user_collection = db.users
|
|
maps_collection = db.maps
|
|
reports_collection = db.reports
|
|
|
|
general_collection = db.general
|
|
admin_log_collection = db.admin_log
|
|
|
|
|
|
def LogAdminAction(
|
|
action_type: str, action_data: dict, UserID: int = None, success: bool = True
|
|
):
|
|
"""Log administrator action."""
|
|
admin_log_collection.insert_one(
|
|
{
|
|
"date": datetime.utcnow(),
|
|
"action_type": action_type,
|
|
"action_data": action_data,
|
|
}
|
|
)
|
|
|
|
|
|
def auth_check(Authorization):
|
|
"""Checks credentials.
|
|
Returns a tuple with result (for example False, "nouser").
|
|
|
|
Results:
|
|
- nouser = user not found
|
|
- wrongpass = wrong password
|
|
- [dictionary] = query
|
|
"""
|
|
if Authorization is None:
|
|
return False, "noauth"
|
|
username, password = Authorization.split(":")
|
|
|
|
query = user_collection.find_one({"Username": username})
|
|
if not query:
|
|
return False, "nouser"
|
|
|
|
if query["Password"] != password:
|
|
return False, "wrongpass"
|
|
|
|
return True, query
|
|
|
|
|
|
|
|
def id_to_mapcode(id_):
|
|
return hex(id_).replace("0x", "").rjust(8, "0")[0:8].upper()
|