FEAT: Improved backend for unsubscribing for newsletter
This commit is contained in:
@@ -204,13 +204,16 @@ def user_reset_password(token, new_password):
|
|||||||
return jsonify({"message": "Password reset successful"}), 200
|
return jsonify({"message": "Password reset successful"}), 200
|
||||||
return jsonify({"error": "Invalid token"}), 400
|
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):
|
def unsubscribe(token):
|
||||||
salt = r.get(token)
|
salt = r.get(token)
|
||||||
if salt:
|
if salt:
|
||||||
r.delete(token)
|
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:
|
if email:
|
||||||
remove_from_newsletter(email)
|
remove_from_newsletter(email)
|
||||||
return jsonify({"message": "unsubscribed from newsletter"}), 200
|
return jsonify({"message": "unsubscribed from newsletter"}), 200
|
||||||
|
|||||||
@@ -127,11 +127,17 @@ def confirm_account_creation_body(email) -> str:
|
|||||||
|
|
||||||
return content, "Gander - Confirm Account Creation"
|
return content, "Gander - Confirm Account Creation"
|
||||||
|
|
||||||
|
|
||||||
def newsletter_conf(email):
|
def newsletter_conf(email):
|
||||||
"""
|
"""
|
||||||
Handles sending a confirmation email that a user has joined a newsletter
|
Handles sending a confirmation email that a user has joined a newsletter
|
||||||
"""
|
"""
|
||||||
|
salt = token_hex(32)
|
||||||
|
|
||||||
|
token = generate_token(email, salt)
|
||||||
|
token += "DaNeWs"
|
||||||
|
r.setex(token, 3600, salt)
|
||||||
|
|
||||||
|
full_url = url + "/user/unsubscribe/" + token
|
||||||
|
|
||||||
content = f"""
|
content = f"""
|
||||||
<html>
|
<html>
|
||||||
@@ -152,7 +158,7 @@ def newsletter_conf(email):
|
|||||||
<h2>Welcome to the Official Gander Newsletter!</h2>
|
<h2>Welcome to the Official Gander Newsletter!</h2>
|
||||||
<p>If you are receiving this email, it means that you have been officially added to the Monthly Gander newsletter.</p>
|
<p>If you are receiving this email, it means that you have been officially added to the Monthly Gander newsletter.</p>
|
||||||
<p>In this newsletter, you will receive updates about: your favourite streamers; important Gander updates; and more!</p>
|
<p>In this newsletter, you will receive updates about: your favourite streamers; important Gander updates; and more!</p>
|
||||||
<small><a href="{url}">Unsubscribe?</a></small>
|
<small><a href="{full_url}">Unsubscribe?</a></small>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user