mirror of
https://github.com/zulip/zulip.git
synced 2025-11-22 07:21:23 +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):
|
||||
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)
|
||||
return self.user
|
||||
|
||||
@@ -77,10 +77,10 @@ def do_deactivate(user_profile):
|
||||
'user': user_profile.user.email,
|
||||
'domain': user_profile.realm.domain})
|
||||
|
||||
def do_change_user_email(user, new_email):
|
||||
old_email = user.email
|
||||
user.email = new_email
|
||||
user.save(update_fields=["email"])
|
||||
def do_change_user_email(user_profile, new_email):
|
||||
old_email = user_profile.user.email
|
||||
user_profile.user.email = new_email
|
||||
user_profile.user.save(update_fields=["email"])
|
||||
|
||||
log_event({'type': 'user_email_changed',
|
||||
'old_email': old_email,
|
||||
@@ -430,19 +430,21 @@ def log_subscription_property_change(user_email, property, property_dict):
|
||||
event.update(property_dict)
|
||||
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.set_password(initial_password(user.email))
|
||||
user.date_joined = join_date
|
||||
user.save(update_fields=["is_active", "date_joined", "password"])
|
||||
|
||||
if log:
|
||||
domain = UserProfile.objects.get(user=user).realm.domain
|
||||
domain = user_profile.realm.domain
|
||||
log_event({'type': 'user_activated',
|
||||
'user': user.email,
|
||||
'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)
|
||||
if commit:
|
||||
user.save(update_fields=["password"])
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from zephyr.lib.actions import do_change_user_email
|
||||
from zephyr.models import User
|
||||
from zephyr.models import UserProfile
|
||||
|
||||
class Command(BaseCommand):
|
||||
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
|
||||
try:
|
||||
user = User.objects.get(email__iexact=old_email)
|
||||
except User.DoesNotExist:
|
||||
user_profile = UserProfile.objects.get(user__email__iexact=old_email)
|
||||
except UserProfile.DoesNotExist:
|
||||
print "Old e-mail doesn't exist in the system."
|
||||
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
|
||||
elif message_type == "user_activated" or message_type == "user_created":
|
||||
# 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'])
|
||||
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
|
||||
users_by_id[user.userprofile.id] = UserProfile.objects.get(user=user)
|
||||
users[user.email] = user.userprofile
|
||||
users_by_id[user_profile.id] = user_profile
|
||||
users[old_message["user"]] = user_profile
|
||||
continue
|
||||
elif message_type == "user_change_password":
|
||||
# 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.password = old_message["pwhash"]
|
||||
user.save()
|
||||
|
||||
@@ -207,9 +207,9 @@ def accounts_register(request):
|
||||
# FIXME: sanitize email addresses and fullname
|
||||
if mit_beta_user:
|
||||
user = User.objects.get(email=email)
|
||||
do_activate_user(user)
|
||||
do_change_password(user, password)
|
||||
user_profile = user.userprofile
|
||||
do_activate_user(user_profile)
|
||||
do_change_password(user_profile, password)
|
||||
do_change_full_name(user_profile, full_name)
|
||||
else:
|
||||
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!")
|
||||
if not authenticate(username=user_profile.user.email, password=old_password):
|
||||
return json_error("Wrong password!")
|
||||
do_change_password(user_profile.user, new_password)
|
||||
do_change_password(user_profile, new_password)
|
||||
|
||||
result = {}
|
||||
if user_profile.full_name != full_name and full_name.strip() != "":
|
||||
|
||||
Reference in New Issue
Block a user