mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 17:36:27 +00:00
Add hashed_password argument to do_change_password.
This way we're not directly manipulating user.password() in random management commands. (imported from commit e6e32ae422015ab55184d5d8111148793a8aca36)
This commit is contained in:
@@ -443,9 +443,14 @@ def do_activate_user(user_profile, log=True, join_date=timezone.now()):
|
|||||||
'user': user.email,
|
'user': user.email,
|
||||||
'domain': domain})
|
'domain': domain})
|
||||||
|
|
||||||
def do_change_password(user_profile, password, log=True, commit=True):
|
def do_change_password(user_profile, password, log=True, commit=True,
|
||||||
|
hashed_password=False):
|
||||||
user = user_profile.user
|
user = user_profile.user
|
||||||
user.set_password(password)
|
if hashed_password:
|
||||||
|
# This is a hashed password, not the password itself.
|
||||||
|
user.password = password
|
||||||
|
else:
|
||||||
|
user.set_password(password)
|
||||||
if commit:
|
if commit:
|
||||||
user.save(update_fields=["password"])
|
user.save(update_fields=["password"])
|
||||||
if log:
|
if log:
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from optparse import make_option
|
from optparse import make_option
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from zephyr.models import UserProfile, get_user_profile_by_email
|
from zephyr.models import UserProfile, get_user_profile_by_email
|
||||||
|
from zephyr.lib.actions import do_change_password
|
||||||
import simplejson
|
import simplejson
|
||||||
|
|
||||||
def dump():
|
def dump():
|
||||||
@@ -17,8 +18,8 @@ def restore(change):
|
|||||||
print "Skipping...", email
|
print "Skipping...", email
|
||||||
continue
|
continue
|
||||||
if change:
|
if change:
|
||||||
user_profile.user.password = password
|
do_change_password(user_profile, password, log=False,
|
||||||
user_profile.user.save()
|
hashed_password=True)
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
option_list = BaseCommand.option_list + (
|
option_list = BaseCommand.option_list + (
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ from django.contrib.sites.models import Site
|
|||||||
from zephyr.models import Message, UserProfile, Stream, Recipient, Client, \
|
from zephyr.models import Message, UserProfile, Stream, Recipient, Client, \
|
||||||
Subscription, Huddle, get_huddle, Realm, UserMessage, StreamColor, \
|
Subscription, Huddle, get_huddle, Realm, UserMessage, StreamColor, \
|
||||||
get_huddle_hash, clear_database, get_client, get_user_profile_by_id
|
get_huddle_hash, clear_database, get_client, get_user_profile_by_id
|
||||||
from zephyr.lib.actions import do_send_message, set_default_streams, do_activate_user
|
from zephyr.lib.actions import do_send_message, set_default_streams, \
|
||||||
|
do_activate_user, do_change_password
|
||||||
from zephyr.lib.parallel import run_parallel
|
from zephyr.lib.parallel import run_parallel
|
||||||
from django.db import transaction, connection
|
from django.db import transaction, connection
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -532,11 +533,9 @@ def restore_saved_messages():
|
|||||||
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
|
user_profile = users[old_message["user"]]
|
||||||
# password hash rather than the password itself
|
do_change_password(user_profile, old_message["pshash"], log=False,
|
||||||
user = User.objects.get(email=old_message["user"])
|
hashed_password=True)
|
||||||
user.password = old_message["pwhash"]
|
|
||||||
user.save()
|
|
||||||
continue
|
continue
|
||||||
elif message_type == "user_change_full_name":
|
elif message_type == "user_change_full_name":
|
||||||
# Just handle these the slow way
|
# Just handle these the slow way
|
||||||
|
|||||||
Reference in New Issue
Block a user