Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit fe8dd71

Browse files
authored
Merge pull request #53 from codewizardshq/confirmation-email
Confirmation email
2 parents 9556f4f + 2c78d02 commit fe8dd71

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

CodeChallenge/api/users.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from flask import Blueprint, jsonify, request, current_app
1+
from flask import Blueprint, jsonify, request, current_app, render_template
22
from flask_jwt_extended import (create_access_token, create_refresh_token,
33
get_current_user, get_jwt_identity,
44
jwt_refresh_token_required, jwt_required,
@@ -60,6 +60,7 @@ def logout():
6060

6161
return res, 200
6262

63+
6364
@bp.route("/register", methods=["POST"])
6465
def register():
6566
user_data = request.get_json()
@@ -132,6 +133,15 @@ def register():
132133
f"{new_u.studentfirstname} {new_u.studentlastname}",
133134
data=mg_vars)
134135

136+
msg = Message("Welcome Pilgrim! You have accepted the Code Challenge",
137+
sender=current_app.config["MAIL_DEFAULT_SENDER"],
138+
recipients=[new_u.parent_email])
139+
name = new_u.studentfirstname or new_u.parentfirstname
140+
msg.html = render_template("challenge_account_confirm.html",
141+
name=name)
142+
msg.extra_headers = {"List-Unsubscribe": "%unsubscribe_email%"}
143+
mail.send(msg)
144+
135145
return jsonify({"status": "success"})
136146

137147

CodeChallenge/templates/challenge_account_confirm.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,22 +286,22 @@
286286
<tr>
287287
<td class="header aligncenter">
288288
<img src="https://challenge.codewizardshq.com/images/logo-small.png">
289-
<h3>{{NAME}}, you've accepted the CodeWizardsHQ Code Challenge! </h3>
289+
<h3>{{name}}, you've accepted the CodeWizardsHQ Code Challenge! </h3>
290290
<br>
291291
<a href="https://challenge.codewizardshq.com/login" class="btn-primary">SIGN IN</a>
292292
</td>
293-
</tr>
293+
</tr>
294294
<tr>
295295
<td class="content-wrap">
296296
<table width="100%" cellpadding="0" cellspacing="0">
297297
<tr>
298298
<td class="content-block">
299-
299+
300300
</td>
301301
</tr>
302302
<tr>
303303
<td class="content-block">
304-
<p>Welcome {{NAME}},</p>
304+
<p>Welcome {{name}},</p>
305305
<br/>
306306

307307
<p>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. </p>
@@ -312,7 +312,7 @@ <h3>How to play The Dragon Quest? </h3>
312312
<p>To prove yourself worthy, you must log in every day between March 1 and March 21 to answer the Code Challenge question. </p>
313313

314314
<p>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!</p>
315-
315+
316316
<p>See the <a href="http://codewizardshq.com/challenge">full FAQ</a> for more answers.</p>
317317

318318
<h3>Who will win the challenge?</h3>
@@ -344,7 +344,7 @@ <h3>Who will win the challenge?</h3>
344344
<div class="footer">
345345
<table width="100%">
346346
<tr>
347-
<td class="aligncenter content-block"><a href="">Unsubscribe</a> from code challenge updates.</td>
347+
<td class="aligncenter content-block"><a href="%unsubscribe_url%">Unsubscribe</a> from code challenge updates.</td>
348348
</tr>
349349
</table>
350350
</div></div>

tests/test_auth.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ def register(client, email, username, password, firstname, lastname):
1212

1313

1414
def test_registration_success(client):
15-
retval = register(client, "sam@codewizardshq.com", "cwhqsam",
16-
"supersecurepassword", "Sam", "Hoffman")
17-
assert retval.get_json()["status"] == "success"
15+
with CodeChallenge.mail.record_messages() as outbox:
16+
retval = register(client, "sam@codewizardshq.com", "cwhqsam",
17+
"supersecurepassword", "Sam", "Hoffman")
18+
assert retval.get_json()["status"] == "success"
19+
assert len(outbox) == 1
20+
assert "Sheldon, you've accepted" in outbox[0].html
1821

1922

2023
def test_registration_failure_invalid_password(client):

0 commit comments

Comments
 (0)