forked from krishsharma0413/reverse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
76 lines (60 loc) · 1.79 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import jwt
from dotenv import dotenv_values
import motor.motor_asyncio
from fastapi.templating import Jinja2Templates
import pytz
from datetime import datetime
IST = pytz.timezone("Asia/Kolkata")
env_data = dotenv_values("./creds.env")
mongo_url = env_data["mongo_url"]
client = motor.motor_asyncio.AsyncIOMotorClient(mongo_url)
turingdb = client["reverse-turing"]
usersdb = turingdb["users"]
chatsdb = turingdb["chats"]
reportsdb = turingdb["reports"]
adminlogsdb = turingdb["adminlogs"]
jwt_secret = env_data["jwt_secret"]
APIKEY = env_data["APIKEY"]
APIKEY1 = env_data["APIKEY1"]
templates = Jinja2Templates(directory="templates")
def verify_jwt(token: str):
try:
return jwt.decode(token, jwt_secret, algorithms=["HS256"])
except:
return False
def generate_jwt(username: str, type: str) -> str:
data = {
"username": username,
"type": type
}
return jwt.encode(data, jwt_secret, algorithm="HS256")
async def no_username_conflict(username: str) -> bool:
user = await usersdb.find_one({"_id": username})
if user == None:
return True
return False
async def create_admin(username: str, password: str):
await usersdb.insert_one({
"_id": username,
"password": password,
"token": generate_jwt(username, "admin"),
"matchmaking": False,
"score": 0,
"type": "admin",
"lastpoint": datetime.now(IST).timestamp(),
"banned": False,
})
if __name__ == "__main__":
import asyncio
print("""
-----------
config menu
-----------
1. Create Admin.
5. List Admins.
Enter your choice: """, end="")
choice = int(input())
if choice == 1:
username = input("Enter username: ")
password = input("Enter password: ")
asyncio.run(create_admin(username, password))