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
|
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-07-07 20:35:31 +02:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
2013-02-10 22:45:25 +01:00
|
|
|
|
2017-07-07 20:35:31 +02:00
|
|
|
class Command(ZulipBaseCommand):
|
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
|
2017-07-07 20:35:31 +02:00
|
|
|
self.add_realm_args(parser)
|
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']
|
2017-07-07 20:35:31 +02:00
|
|
|
|
|
|
|
realm = self.get_realm(options)
|
|
|
|
user_profile = self.get_user(old_email, realm)
|
2013-02-10 22:45:25 +01:00
|
|
|
|
2013-03-08 19:58:18 +01:00
|
|
|
do_change_user_email(user_profile, new_email)
|