Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CodeChallenge/api/users.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -60,6 +60,7 @@ def logout():

return res, 200


@bp.route("/register", methods=["POST"])
def register():
user_data = request.get_json()
Expand Down Expand Up @@ -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"})


Expand Down
12 changes: 6 additions & 6 deletions CodeChallenge/templates/challenge_account_confirm.html
Original file line number Diff line number Diff line change
Expand Up @@ -286,22 +286,22 @@
<tr>
<td class="header aligncenter">
<img src="https://challenge.codewizardshq.com/images/logo-small.png">
<h3>{{NAME}}, you've accepted the CodeWizardsHQ Code Challenge! </h3>
<h3>{{name}}, you've accepted the CodeWizardsHQ Code Challenge! </h3>
<br>
<a href="https://challenge.codewizardshq.com/login" class="btn-primary">SIGN IN</a>
</td>
</tr>
</tr>
<tr>
<td class="content-wrap">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="content-block">

</td>
</tr>
<tr>
<td class="content-block">
<p>Welcome {{NAME}},</p>
<p>Welcome {{name}},</p>
<br/>

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

<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>

<p>See the <a href="http://codewizardshq.com/challenge">full FAQ</a> for more answers.</p>

<h3>Who will win the challenge?</h3>
Expand Down Expand Up @@ -344,7 +344,7 @@ <h3>Who will win the challenge?</h3>
<div class="footer">
<table width="100%">
<tr>
<td class="aligncenter content-block"><a href="">Unsubscribe</a> from code challenge updates.</td>
<td class="aligncenter content-block"><a href="%unsubscribe_url%">Unsubscribe</a> from code challenge updates.</td>
</tr>
</table>
</div></div>
Expand Down
9 changes: 6 additions & 3 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down