Factor out notifying of a new user into a separate function, notify on manage.py create_user.

(imported from commit 1a6aa0536dbfea8035b6bbd76528e70d90aa8b60)
This commit is contained in:
Luke Faraone 2012-12-06 18:02:53 -05:00
parent 7fbee21584
commit c65d6113ed
2 changed files with 22 additions and 11 deletions

View File

@ -7,7 +7,7 @@ from django.utils.timezone import now
from django.core import validators
from zephyr.models import Realm, do_create_user
from zephyr.views import do_send_message
from zephyr.views import do_send_message, notify_new_user
from zephyr.lib.initial_password import initial_password
class Command(BaseCommand):
@ -42,7 +42,8 @@ class Command(BaseCommand):
raise CommandError("Realm does not exist.")
try:
do_create_user(email, initial_password(email), realm, full_name,
email.split('@')[0])
notify_new_user(do_create_user(email, initial_password(email),
realm, full_name, email.split('@')[0]),
internal=True)
except IntegrityError:
raise CommandError("User already exists.")

View File

@ -56,6 +56,23 @@ def get_stream(stream_name, realm):
except Stream.DoesNotExist:
return None
def notify_new_user(user, internal=False):
if internal:
# When this is done using manage.py vs. the web interface
internal_blurb = " **INTERNAL SIGNUP** "
else:
internal_blurb = " "
internal_send_message("humbug+signups@humbughq.com",
Recipient.STREAM, "signups", user.realm.domain,
"%s <`%s`> just signed up for Humbug!%s(total: **%i**)" % (
user.full_name,
user.user.email,
internal_blurb,
UserProfile.objects.filter(realm=user.realm, user__is_active=True).count(),
)
)
@require_post
def accounts_register(request):
key = request.POST['key']
@ -96,14 +113,7 @@ def accounts_register(request):
user = do_create_user(email, password, realm, full_name, short_name)
add_default_subs(user)
internal_send_message("humbug+signups@humbughq.com",
Recipient.STREAM, "signups", realm.domain,
"%s <`%s`> just signed up for Humbug! (total: **%i**)" % (
full_name,
email,
UserProfile.objects.filter(realm=realm, user__is_active=True).count(),
)
)
notify_new_user(user)
login(request, authenticate(username=email, password=password))
return HttpResponseRedirect(reverse('zephyr.views.home'))