mirror of https://github.com/zulip/zulip.git
Add a management command to change and log user emails.
(imported from commit 0bf25433a371f7e46ade96019f4a9ceebe395fe5)
This commit is contained in:
parent
c94f561eda
commit
53f0b00785
|
@ -84,6 +84,15 @@ def do_create_user(email, password, realm, full_name, short_name,
|
|||
'domain': realm.domain})
|
||||
return create_user(email, password, realm, full_name, short_name, active)
|
||||
|
||||
def do_change_user_email(user, new_email):
|
||||
old_email = user.email
|
||||
user.email = new_email
|
||||
user.save()
|
||||
|
||||
log_event({'type': 'user_email_changed',
|
||||
'old_email': old_email,
|
||||
'new_email': new_email})
|
||||
|
||||
def compute_mit_user_fullname(email):
|
||||
try:
|
||||
# Input is either e.g. starnine@mit.edu or user|CROSSREALM.INVALID@mit.edu
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
|
||||
from zephyr.lib.actions import do_change_user_email
|
||||
from zephyr.models import User
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = """Change the email address for a user.
|
||||
|
||||
Usage: python manage.py change_user_email <old email> <new email>"""
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if len(args) != 2:
|
||||
print "Please provide both the old and new address."
|
||||
exit(1)
|
||||
|
||||
old_email, new_email = args
|
||||
try:
|
||||
user = User.objects.get(email__iexact=old_email)
|
||||
except User.DoesNotExist:
|
||||
print "Old e-mail doesn't exist in the system."
|
||||
exit(1)
|
||||
|
||||
do_change_user_email(user, new_email)
|
Loading…
Reference in New Issue