mirror of https://github.com/zulip/zulip.git
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:
parent
7fbee21584
commit
c65d6113ed
|
@ -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.")
|
||||
|
|
|
@ -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'))
|
||||
|
|
Loading…
Reference in New Issue