zulip/zerver/management/commands/activate_mit.py

29 lines
1.2 KiB
Python

from __future__ import absolute_import
from optparse import make_option
from django.core.management.base import BaseCommand
from confirmation.models import Confirmation
from zerver.models import UserProfile, MitUser, get_user_profile_by_email
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option('--resend', '-r', dest='resend', action='store_true',
help='Send tokens even if tokens were previously sent for the user.'),)
help = "Generate an activation email to send to MIT users."
def handle(self, *args, **options):
for username in args:
email = username + "@mit.edu"
try:
get_user_profile_by_email(email)
except UserProfile.DoesNotExist:
print username + ": User does not exist in database"
continue
mit_user, created = MitUser.objects.get_or_create(email=email)
if not created and not options["resend"]:
print username + ": User already exists. Use -r to resend."
else:
Confirmation.objects.send_confirmation(mit_user, email)
print username + ": Mailed."