-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth_check.py
More file actions
38 lines (30 loc) · 1.04 KB
/
auth_check.py
File metadata and controls
38 lines (30 loc) · 1.04 KB
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
import json
from typing import Dict
# File path for storing invite code status
FILE_PATH = "memory/invite_codes.json"
def load_data() -> dict:
"""Load invite code data."""
try:
with open(FILE_PATH, "r") as file:
return json.load(file)
except FileNotFoundError:
return {"users": {}, "used_codes": []}
def save_data(data: Dict):
"""Save invite code data."""
with open(FILE_PATH, "w") as file:
json.dump(data, file, indent=2)
def verify_user(openid: str, code: str) -> str:
"""Verify user against invite code system."""
data = load_data()
# Check if user already verified
if openid in data["users"]:
return "ALREADY_VERIFIED"
# Check if code is valid
if code not in data["used_codes"]:
return "INVALID_CODE"
# Bind user to code if it's valid and not already linked
if code in data["used_codes"] and openid not in data["users"]:
data["users"][openid] = code
save_data(data)
return "VERIFICATION_SUCCESS"
return "CODE_ALREADY_USED"