lunarflu HF staff commited on
Commit
02e376e
·
verified ·
1 Parent(s): 7d91736

delete all tokens when creating new link

Browse files
Files changed (1) hide show
  1. app.py +3 -1
app.py CHANGED
@@ -47,6 +47,7 @@ class DMButton(Button):
47
 
48
  async def callback(self, interaction: discord.Interaction):
49
  # await interaction.user.send(self.message) # this is for DMs, but users may have DMs disabled
 
50
  unique_string = generate_unique_string()
51
  user_tokens[self.user_id] = unique_string
52
  unique_link = f"{GRADIO_APP_URL}?user_id={self.user_id}&token={unique_string}"
@@ -74,7 +75,7 @@ def hello(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
74
 
75
  if user_id is None or token is None:
76
  return "# ❌ Invalid link. Generate a new link [here](https://discord.com/channels/879548962464493619/900125909984624713) !"
77
-
78
  if int(user_id) not in user_tokens or user_tokens[int(user_id)] != token:
79
  return "# ❌ Invalid or expired link. Generate a new link [here](https://discord.com/channels/879548962464493619/900125909984624713) !"
80
 
@@ -87,6 +88,7 @@ def hello(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
87
  # profile.username
88
  return f"# ✅ Verification successful! We have linked your Hugging Face and Discord accounts. You can now earn exp for activity on Hugging Face as well as on Discord!"
89
 
 
90
  with gr.Blocks() as demo:
91
  with gr.Row():
92
  gr.Markdown("# Discord Verification Space")
 
47
 
48
  async def callback(self, interaction: discord.Interaction):
49
  # await interaction.user.send(self.message) # this is for DMs, but users may have DMs disabled
50
+ del user_tokens[int(self.user_id)] # always delete all past tokens when creating new link
51
  unique_string = generate_unique_string()
52
  user_tokens[self.user_id] = unique_string
53
  unique_link = f"{GRADIO_APP_URL}?user_id={self.user_id}&token={unique_string}"
 
75
 
76
  if user_id is None or token is None:
77
  return "# ❌ Invalid link. Generate a new link [here](https://discord.com/channels/879548962464493619/900125909984624713) !"
78
+
79
  if int(user_id) not in user_tokens or user_tokens[int(user_id)] != token:
80
  return "# ❌ Invalid or expired link. Generate a new link [here](https://discord.com/channels/879548962464493619/900125909984624713) !"
81
 
 
88
  # profile.username
89
  return f"# ✅ Verification successful! We have linked your Hugging Face and Discord accounts. You can now earn exp for activity on Hugging Face as well as on Discord!"
90
 
91
+
92
  with gr.Blocks() as demo:
93
  with gr.Row():
94
  gr.Markdown("# Discord Verification Space")