From dea11c081f286651ba608a3d3d07810ad957f52a Mon Sep 17 00:00:00 2001 From: Samuel Hoffman Date: Wed, 29 Jan 2020 16:30:57 -0500 Subject: [PATCH] send welcome email upon registration --- CodeChallenge/api/users.py | 12 +++++++++++- .../templates/challenge_account_confirm.html | 12 ++++++------ tests/test_auth.py | 9 ++++++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/CodeChallenge/api/users.py b/CodeChallenge/api/users.py index f450dfb..aa19746 100644 --- a/CodeChallenge/api/users.py +++ b/CodeChallenge/api/users.py @@ -1,4 +1,4 @@ -from flask import Blueprint, jsonify, request, current_app +from flask import Blueprint, jsonify, request, current_app, render_template from flask_jwt_extended import (create_access_token, create_refresh_token, get_current_user, get_jwt_identity, jwt_refresh_token_required, jwt_required, @@ -60,6 +60,7 @@ def logout(): return res, 200 + @bp.route("/register", methods=["POST"]) def register(): user_data = request.get_json() @@ -132,6 +133,15 @@ def register(): f"{new_u.studentfirstname} {new_u.studentlastname}", data=mg_vars) + msg = Message("Welcome Pilgrim! You have accepted the Code Challenge", + sender=current_app.config["MAIL_DEFAULT_SENDER"], + recipients=[new_u.parent_email]) + name = new_u.studentfirstname or new_u.parentfirstname + msg.html = render_template("challenge_account_confirm.html", + name=name) + msg.extra_headers = {"List-Unsubscribe": "%unsubscribe_email%"} + mail.send(msg) + return jsonify({"status": "success"}) diff --git a/CodeChallenge/templates/challenge_account_confirm.html b/CodeChallenge/templates/challenge_account_confirm.html index 6cd0fca..2dcffd7 100644 --- a/CodeChallenge/templates/challenge_account_confirm.html +++ b/CodeChallenge/templates/challenge_account_confirm.html @@ -286,22 +286,22 @@ -

{{NAME}}, you've accepted the CodeWizardsHQ Code Challenge!

+

{{name}}, you've accepted the CodeWizardsHQ Code Challenge!


SIGN IN - +
- +
-

Welcome {{NAME}},

+

Welcome {{name}},


Your mission is to defeat the evil dragon who has invaded CWHQ land. Only the bravest and brightest kid coders, like you, are prepared for this quest.

@@ -312,7 +312,7 @@

How to play The Dragon Quest?

To prove yourself worthy, you must log in every day between March 1 and March 21 to answer the Code Challenge question.

When you have answered the final question, you will take on the mighty dragon in the boss level by writing a piece of code in Python or JavaScript. If your answer unlocks the correct answer, you are worthy to be called Code Challenge champion and a chance to win a $100 cash prize!

- +

See the full FAQ for more answers.

Who will win the challenge?

@@ -344,7 +344,7 @@

Who will win the challenge?

diff --git a/tests/test_auth.py b/tests/test_auth.py index 8ec321e..b498ef1 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -12,9 +12,12 @@ def register(client, email, username, password, firstname, lastname): def test_registration_success(client): - retval = register(client, "sam@codewizardshq.com", "cwhqsam", - "supersecurepassword", "Sam", "Hoffman") - assert retval.get_json()["status"] == "success" + with CodeChallenge.mail.record_messages() as outbox: + retval = register(client, "sam@codewizardshq.com", "cwhqsam", + "supersecurepassword", "Sam", "Hoffman") + assert retval.get_json()["status"] == "success" + assert len(outbox) == 1 + assert "Sheldon, you've accepted" in outbox[0].html def test_registration_failure_invalid_password(client):