diff --git a/CodeChallenge/api/users.py b/CodeChallenge/api/users.py index cb7f754..271ff78 100644 --- a/CodeChallenge/api/users.py +++ b/CodeChallenge/api/users.py @@ -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, @@ -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, @@ -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"}) diff --git a/CodeChallenge/config.py b/CodeChallenge/config.py index 1434492..651a0f5 100644 --- a/CodeChallenge/config.py +++ b/CodeChallenge/config.py @@ -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"