-
Notifications
You must be signed in to change notification settings - Fork 2
/
callbacks.py
54 lines (47 loc) · 1.82 KB
/
callbacks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Usage: import this from wherever you like, but be aware that
# this code is not part of the registration app, and not required to function.
# It is, rather, more like runserver.py - the user implementation of registration.
from registration import triggers, settings # I like to keep all my secrets in settings.py
from sparkpost import SparkPost # Import any other non-essential libraries here.
import subprocess
import requests
import json
sp = SparkPost(settings.SPARKPOST['secret_key'])
# Trigger example. When an new user is created, print them out to console.
@triggers.new_user
def say_hello(user):
"""
This is an example of a callback.
Decorate it with trigger.new_user to get called when new users are created.
:param user: An instance of models.User
:returns: None
"""
print('NEW USER: ' + user.first_name)
# Send email. When a new user is created, send them a friendly welcome email
@triggers.new_user
def send_welcome(user):
response = sp.transmission.send(
recipients=[ user.email ],
track_opens=True,
track_clicks=True,
template='signup-confirm',
substitution_data={
'name': user.first_name
}
)
print(response)
# Feed the new user into slack
@triggers.new_user
def send_slack(user):
data = {"text": user.first_name + " " + user.last_name + " (" + user.email + ") registered for HackNC.\n<https://my.hacknc.com/admin/user/" + str(user.user_id) + "| View Application>"}
r = requests.post(settings.SLACK['webhook_url'],data=json.dumps(data))
print("Slack Reply: " + r.text)
@triggers.update_user
def upload_resume(user):
if user.resume_location:
subprocess.Popen([
'/opt/dropbox/dropbox_uploader.sh',
'upload',
user.resume_location,
user.resume_location
])