Pranesh64 commited on
Commit
be3c306
·
verified ·
1 Parent(s): b497eb4

fix: correct subscription/unsubscription logic

Browse files
Files changed (1) hide show
  1. app.py +23 -3
app.py CHANGED
@@ -185,7 +185,7 @@ def subscribe(username, email, timezone):
185
 
186
  # ---- Duplicate / Rate limit ----
187
  cur.execute("""
188
- SELECT email_verified, verification_token
189
  FROM users
190
  WHERE email = %s
191
  """, (email,))
@@ -195,13 +195,33 @@ def subscribe(username, email, timezone):
195
  # ---- Existing user ----
196
  if row:
197
 
198
- verified, token = row
199
 
200
- if verified:
 
201
  cur.close()
202
  conn.close()
203
  return "⚠️ Already subscribed"
204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  # Resend verification
206
  link = f"{HF_URL}?verify={token}"
207
 
 
185
 
186
  # ---- Duplicate / Rate limit ----
187
  cur.execute("""
188
+ SELECT email_verified, verification_token, unsubscribed
189
  FROM users
190
  WHERE email = %s
191
  """, (email,))
 
195
  # ---- Existing user ----
196
  if row:
197
 
198
+ verified, token, unsubscribed = row
199
 
200
+ # Already active
201
+ if verified and not unsubscribed:
202
  cur.close()
203
  conn.close()
204
  return "⚠️ Already subscribed"
205
 
206
+ # Was unsubscribed → resubscribe
207
+ if verified and unsubscribed:
208
+
209
+ cur.execute("""
210
+ UPDATE users
211
+ SET unsubscribed = false,
212
+ leetcode_username = %s,
213
+ timezone = %s
214
+ WHERE email = %s
215
+ """, (username, timezone, email))
216
+
217
+
218
+ conn.commit()
219
+ cur.close()
220
+ conn.close()
221
+
222
+ return "✅ You have been re-subscribed!"
223
+
224
+
225
  # Resend verification
226
  link = f"{HF_URL}?verify={token}"
227