2013-04-23 18:51:17 +02:00
|
|
|
from __future__ import absolute_import
|
2015-11-01 17:11:06 +01:00
|
|
|
from __future__ import print_function
|
2013-04-23 18:51:17 +02:00
|
|
|
|
2017-05-25 00:29:59 +02:00
|
|
|
import sys
|
2013-02-10 22:45:25 +01:00
|
|
|
|
2016-06-04 16:52:18 +02:00
|
|
|
from argparse import ArgumentParser
|
|
|
|
from django.core.management.base import BaseCommand
|
2017-05-25 00:29:59 +02:00
|
|
|
from typing import Any
|
|
|
|
|
2013-07-29 23:03:31 +02:00
|
|
|
from zerver.lib.actions import do_change_user_email
|
2017-05-25 00:29:59 +02:00
|
|
|
from zerver.models import UserProfile, get_user_for_mgmt
|
2013-02-10 22:45:25 +01:00
|
|
|
|
|
|
|
class Command(BaseCommand):
|
2015-08-21 02:10:41 +02:00
|
|
|
help = """Change the email address for a user."""
|
2013-02-10 22:45:25 +01:00
|
|
|
|
2015-08-21 02:10:41 +02:00
|
|
|
def add_arguments(self, parser):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (ArgumentParser) -> None
|
2015-08-21 02:10:41 +02:00
|
|
|
parser.add_argument('old_email', metavar='<old email>', type=str,
|
|
|
|
help='email address to change')
|
|
|
|
parser.add_argument('new_email', metavar='<new email>', type=str,
|
|
|
|
help='new email address')
|
2013-02-10 22:45:25 +01:00
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (*Any, **str) -> None
|
2015-08-21 02:10:41 +02:00
|
|
|
old_email = options['old_email']
|
|
|
|
new_email = options['new_email']
|
2013-02-10 22:45:25 +01:00
|
|
|
try:
|
2017-05-25 00:29:59 +02:00
|
|
|
user_profile = get_user_for_mgmt(old_email)
|
2013-03-08 19:58:18 +01:00
|
|
|
except UserProfile.DoesNotExist:
|
2015-11-01 17:11:06 +01:00
|
|
|
print("Old e-mail doesn't exist in the system.")
|
2017-05-25 00:29:59 +02:00
|
|
|
sys.exit(1)
|
2013-02-10 22:45:25 +01:00
|
|
|
|
2013-03-08 19:58:18 +01:00
|
|
|
do_change_user_email(user_profile, new_email)
|