2013-04-23 18:51:17 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2012-10-29 19:08:18 +01:00
|
|
|
from optparse import make_option
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
from confirmation.models import Confirmation
|
2013-03-28 20:20:31 +01:00
|
|
|
from zephyr.models import UserProfile, MitUser, get_user_profile_by_email
|
2012-10-29 19:08:18 +01:00
|
|
|
|
|
|
|
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:
|
2013-03-28 20:20:31 +01:00
|
|
|
get_user_profile_by_email(email)
|
|
|
|
except UserProfile.DoesNotExist:
|
2012-10-29 19:08:18 +01:00
|
|
|
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."
|
|
|
|
|