Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,7 @@ bot = commands.Bot(command_prefix="!", intents=intents)
|
|
| 12 |
GRADIO_APP_URL = "https://huggingface.co/spaces/lunarflu/gradio-oauth2"
|
| 13 |
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
| 14 |
|
|
|
|
| 15 |
# Dictionary to store user IDs and their corresponding unique strings
|
| 16 |
user_tokens = {}
|
| 17 |
|
|
@@ -41,17 +42,23 @@ def hello(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
|
|
| 41 |
query_params = parse_qs(urlparse(url_str).query)
|
| 42 |
user_id = query_params.get('user_id', [None])[0]
|
| 43 |
token = query_params.get('token', [None])[0]
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
return "# ❌ Invalid link. Generate a new one [here](https://discord.com/channels/879548962464493619/900125909984624713) !."
|
| 47 |
|
| 48 |
-
if
|
| 49 |
-
return "# ❌ Invalid
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
if profile is None:
|
| 52 |
-
return f"# ❌
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
return f"# ✅ Successfully logged in as {profile.username}.
|
| 55 |
|
| 56 |
with gr.Blocks() as demo:
|
| 57 |
with gr.Row():
|
|
|
|
| 12 |
GRADIO_APP_URL = "https://huggingface.co/spaces/lunarflu/gradio-oauth2"
|
| 13 |
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
| 14 |
|
| 15 |
+
|
| 16 |
# Dictionary to store user IDs and their corresponding unique strings
|
| 17 |
user_tokens = {}
|
| 18 |
|
|
|
|
| 42 |
query_params = parse_qs(urlparse(url_str).query)
|
| 43 |
user_id = query_params.get('user_id', [None])[0]
|
| 44 |
token = query_params.get('token', [None])[0]
|
| 45 |
+
user = await bot.fetch_user(user_id)
|
| 46 |
|
| 47 |
+
print(f"token:{token}\n user_id:{user_id}\n profile:{profile}\n user_tokens:{user_tokens}")
|
|
|
|
| 48 |
|
| 49 |
+
if token is None:
|
| 50 |
+
return "# ❌ Invalid link, unique code is missing. Generate a new link [here](https://discord.com/channels/879548962464493619/900125909984624713) !."
|
| 51 |
+
|
| 52 |
+
if user_id is None:
|
| 53 |
+
return "# ❌ Invalid link, discord user_id is missing. Generate a new link [here](https://discord.com/channels/879548962464493619/900125909984624713) !."
|
| 54 |
|
| 55 |
if profile is None:
|
| 56 |
+
return f"# ❌ Log in with Hugging Face to verify!"
|
| 57 |
+
|
| 58 |
+
if int(user_id) not in user_tokens or user_tokens[int(user_id)] != token:
|
| 59 |
+
return "# ❌ Invalid or expired link. Generate a new link [here](https://discord.com/channels/879548962464493619/900125909984624713) ! "
|
| 60 |
|
| 61 |
+
return f"# ✅ Successfully logged in as {profile.username}. Discord username: {user.name}"
|
| 62 |
|
| 63 |
with gr.Blocks() as demo:
|
| 64 |
with gr.Row():
|