mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 19:06:09 +00:00
Switch functions like do_activate_user to accept UserProfiles.
Only a few of them took a User as an argument anyway. This is preparatory work for merging the User and UserProfile models. (imported from commit 65b2bd2453597531bcf135ccf24d2a4615cd0d2a)
This commit is contained in:
@@ -53,6 +53,6 @@ class HomepageForm(forms.Form):
|
|||||||
|
|
||||||
class LoggingSetPasswordForm(SetPasswordForm):
|
class LoggingSetPasswordForm(SetPasswordForm):
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
do_change_password(self.user, self.cleaned_data['new_password1'],
|
do_change_password(self.user.userprofile, self.cleaned_data['new_password1'],
|
||||||
log=True, commit=commit)
|
log=True, commit=commit)
|
||||||
return self.user
|
return self.user
|
||||||
|
|||||||
@@ -77,10 +77,10 @@ def do_deactivate(user_profile):
|
|||||||
'user': user_profile.user.email,
|
'user': user_profile.user.email,
|
||||||
'domain': user_profile.realm.domain})
|
'domain': user_profile.realm.domain})
|
||||||
|
|
||||||
def do_change_user_email(user, new_email):
|
def do_change_user_email(user_profile, new_email):
|
||||||
old_email = user.email
|
old_email = user_profile.user.email
|
||||||
user.email = new_email
|
user_profile.user.email = new_email
|
||||||
user.save(update_fields=["email"])
|
user_profile.user.save(update_fields=["email"])
|
||||||
|
|
||||||
log_event({'type': 'user_email_changed',
|
log_event({'type': 'user_email_changed',
|
||||||
'old_email': old_email,
|
'old_email': old_email,
|
||||||
@@ -430,19 +430,21 @@ def log_subscription_property_change(user_email, property, property_dict):
|
|||||||
event.update(property_dict)
|
event.update(property_dict)
|
||||||
log_event(event)
|
log_event(event)
|
||||||
|
|
||||||
def do_activate_user(user, log=True, join_date=timezone.now()):
|
def do_activate_user(user_profile, log=True, join_date=timezone.now()):
|
||||||
|
user = user_profile.user
|
||||||
user.is_active = True
|
user.is_active = True
|
||||||
user.set_password(initial_password(user.email))
|
user.set_password(initial_password(user.email))
|
||||||
user.date_joined = join_date
|
user.date_joined = join_date
|
||||||
user.save(update_fields=["is_active", "date_joined", "password"])
|
user.save(update_fields=["is_active", "date_joined", "password"])
|
||||||
|
|
||||||
if log:
|
if log:
|
||||||
domain = UserProfile.objects.get(user=user).realm.domain
|
domain = user_profile.realm.domain
|
||||||
log_event({'type': 'user_activated',
|
log_event({'type': 'user_activated',
|
||||||
'user': user.email,
|
'user': user.email,
|
||||||
'domain': domain})
|
'domain': domain})
|
||||||
|
|
||||||
def do_change_password(user, password, log=True, commit=True):
|
def do_change_password(user_profile, password, log=True, commit=True):
|
||||||
|
user = user_profile.user
|
||||||
user.set_password(password)
|
user.set_password(password)
|
||||||
if commit:
|
if commit:
|
||||||
user.save(update_fields=["password"])
|
user.save(update_fields=["password"])
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
from zephyr.lib.actions import do_change_user_email
|
from zephyr.lib.actions import do_change_user_email
|
||||||
from zephyr.models import User
|
from zephyr.models import UserProfile
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = """Change the email address for a user.
|
help = """Change the email address for a user.
|
||||||
@@ -15,9 +15,9 @@ Usage: python manage.py change_user_email <old email> <new email>"""
|
|||||||
|
|
||||||
old_email, new_email = args
|
old_email, new_email = args
|
||||||
try:
|
try:
|
||||||
user = User.objects.get(email__iexact=old_email)
|
user_profile = UserProfile.objects.get(user__email__iexact=old_email)
|
||||||
except User.DoesNotExist:
|
except UserProfile.DoesNotExist:
|
||||||
print "Old e-mail doesn't exist in the system."
|
print "Old e-mail doesn't exist in the system."
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
do_change_user_email(user, new_email)
|
do_change_user_email(user_profile, new_email)
|
||||||
|
|||||||
@@ -523,15 +523,17 @@ def restore_saved_messages():
|
|||||||
continue
|
continue
|
||||||
elif message_type == "user_activated" or message_type == "user_created":
|
elif message_type == "user_activated" or message_type == "user_created":
|
||||||
# These are rare, so just handle them the slow way
|
# These are rare, so just handle them the slow way
|
||||||
user = User.objects.get(email=old_message["user"])
|
user_profile = users[old_message["user"]]
|
||||||
join_date = timestamp_to_datetime(old_message['timestamp'])
|
join_date = timestamp_to_datetime(old_message['timestamp'])
|
||||||
do_activate_user(user, log=False, join_date=join_date)
|
do_activate_user(user_profile, log=False, join_date=join_date)
|
||||||
# Update the cache of users to show this user as activated
|
# Update the cache of users to show this user as activated
|
||||||
users_by_id[user.userprofile.id] = UserProfile.objects.get(user=user)
|
users_by_id[user_profile.id] = user_profile
|
||||||
users[user.email] = user.userprofile
|
users[old_message["user"]] = user_profile
|
||||||
continue
|
continue
|
||||||
elif message_type == "user_change_password":
|
elif message_type == "user_change_password":
|
||||||
# Just handle these the slow way
|
# Just handle these the slow way
|
||||||
|
# We can't use do_change_password, since we have the
|
||||||
|
# password hash rather than the password itself
|
||||||
user = User.objects.get(email=old_message["user"])
|
user = User.objects.get(email=old_message["user"])
|
||||||
user.password = old_message["pwhash"]
|
user.password = old_message["pwhash"]
|
||||||
user.save()
|
user.save()
|
||||||
|
|||||||
@@ -207,9 +207,9 @@ def accounts_register(request):
|
|||||||
# FIXME: sanitize email addresses and fullname
|
# FIXME: sanitize email addresses and fullname
|
||||||
if mit_beta_user:
|
if mit_beta_user:
|
||||||
user = User.objects.get(email=email)
|
user = User.objects.get(email=email)
|
||||||
do_activate_user(user)
|
|
||||||
do_change_password(user, password)
|
|
||||||
user_profile = user.userprofile
|
user_profile = user.userprofile
|
||||||
|
do_activate_user(user_profile)
|
||||||
|
do_change_password(user_profile, password)
|
||||||
do_change_full_name(user_profile, full_name)
|
do_change_full_name(user_profile, full_name)
|
||||||
else:
|
else:
|
||||||
user_profile = do_create_user(email, password, realm, full_name, short_name)
|
user_profile = do_create_user(email, password, realm, full_name, short_name)
|
||||||
@@ -1039,7 +1039,7 @@ def json_change_settings(request, user_profile, full_name=POST,
|
|||||||
return json_error("New password must match confirmation password!")
|
return json_error("New password must match confirmation password!")
|
||||||
if not authenticate(username=user_profile.user.email, password=old_password):
|
if not authenticate(username=user_profile.user.email, password=old_password):
|
||||||
return json_error("Wrong password!")
|
return json_error("Wrong password!")
|
||||||
do_change_password(user_profile.user, new_password)
|
do_change_password(user_profile, new_password)
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
if user_profile.full_name != full_name and full_name.strip() != "":
|
if user_profile.full_name != full_name and full_name.strip() != "":
|
||||||
|
|||||||
Reference in New Issue
Block a user