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
14 changes: 14 additions & 0 deletions CodeChallenge/api/users.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import requests
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,
Expand All @@ -6,6 +7,7 @@
unset_jwt_cookies)
from flask_limiter.util import get_remote_address
from flask_mail import Message
from sqlalchemy import func

from .. import core
from ..auth import (Users, hash_password, password_reset_token,
Expand Down Expand Up @@ -162,6 +164,18 @@ def register():
mail.send(confirm_email)
mail.send(welcome_email)

if "SLACK_WEBHOOK" in current_app.config and not current_app.config.get("TESTING", False):
regcount = db.session.query(func.count(Users.id)).scalar()
webhook = current_app.config.get("SLACK_WEBHOOK")
requests.post(webhook, json=dict(
text="Event: New Registration\n\n"
f"*User*: {new_u.username}\n"
f"*Student*: {new_u.studentfirstname} {new_u.studentlastname}\n"
f"*Parent*: {new_u.parentfirstname} {new_u.parentlastname}\n"
f"*How'd you find us?* {new_u.found_us}\n"
f"\n*Total Registrations*: {regcount}"
))

return jsonify({"status": "success"})


Expand Down
1 change: 1 addition & 0 deletions CodeChallenge/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DefaultConfig:
MG_PRIVATE_KEY = os.getenv("MG_PRIVATE_KEY")
MG_LIST = "codechallenge@school.codewizardshq.com"
WORKER_PASSWORD = os.getenv("WORKER_PASSWORD")
SLACK_WEBHOOK = os.getenv("SLACK_WEBHOOK")

# no trailing /
EXTERNAL_URL = "https://challenge.codewizardshq.com"
Expand Down