FEAT: Improved backend for unsubscribing for newsletter

This commit is contained in:
white
2025-03-03 15:30:52 +00:00
parent e8521a6661
commit fd95b1b3bb
2 changed files with 13 additions and 4 deletions

View File

@@ -204,13 +204,16 @@ def user_reset_password(token, new_password):
return jsonify({"message": "Password reset successful"}), 200
return jsonify({"error": "Invalid token"}), 400
@user_bp.route("/unsubscribe/<string:token>", methods=["POST"])
@user_bp.route("/user/unsubscribe/<string:token>", methods=["POST"])
def unsubscribe(token):
salt = r.get(token)
if salt:
r.delete(token)
email = verify_token(token[:-5], salt)
# Derive the email from the given token
email = verify_token(token[:-6], salt)
# If email does exist, remove it from the newsletter database
if email:
remove_from_newsletter(email)
return jsonify({"message": "unsubscribed from newsletter"}), 200