From b9e9938197050bd767807dcad60437415f595390 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Wed, 17 Oct 2012 21:08:59 -0400 Subject: [PATCH] create_user_if_needed: Use proper initial passwords (imported from commit 009208ac64548dd6f8773ccc7738ab0c391d816a) --- zephyr/management/commands/populate_db.py | 8 +++----- zephyr/models.py | 6 +++--- zephyr/views.py | 6 +++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/zephyr/management/commands/populate_db.py b/zephyr/management/commands/populate_db.py index 957d0faca3..f64fa22fcb 100644 --- a/zephyr/management/commands/populate_db.py +++ b/zephyr/management/commands/populate_db.py @@ -232,7 +232,7 @@ def restore_saved_messages(): if not realm: realm = Realm.objects.get(domain='mit.edu') - create_user_if_needed(realm, sender_email, sender_email.split('@')[0], + create_user_if_needed(realm, sender_email, old_message["sender_full_name"], old_message["sender_short_name"]) message.sender = UserProfile.objects.get(user__email=old_message["sender_email"]) @@ -244,8 +244,7 @@ def restore_saved_messages(): if message.type == Recipient.PERSONAL: u = old_message["recipient"][0] - create_user_if_needed(realm, u["email"], u["email"].split('@')[0], - u["full_name"], u["short_name"]) + create_user_if_needed(realm, u["email"], u["full_name"], u["short_name"]) user_profile = UserProfile.objects.get(user__email=u["email"]) message.recipient = Recipient.objects.get(type=Recipient.PERSONAL, type_id=user_profile.id) @@ -255,8 +254,7 @@ def restore_saved_messages(): type_id=stream.id) elif message.type == Recipient.HUDDLE: for u in old_message["recipient"]: - create_user_if_needed(realm, u["email"], u["email"].split('@')[0], - u["full_name"], u["short_name"]) + create_user_if_needed(realm, u["email"], u["full_name"], u["short_name"]) target_huddle = get_huddle([UserProfile.objects.get(user__email=u["email"]).id for u in old_message["recipient"]]) message.recipient = Recipient.objects.get(type=Recipient.HUDDLE, diff --git a/zephyr/models.py b/zephyr/models.py index 8d2bc08f63..a639cd4f86 100644 --- a/zephyr/models.py +++ b/zephyr/models.py @@ -5,7 +5,7 @@ import hashlib import base64 import calendar from zephyr.lib.cache import cache_with_key -from zephyr.lib.initial_password import initial_api_key +from zephyr.lib.initial_password import initial_password, initial_api_key import fcntl import os import simplejson @@ -122,12 +122,12 @@ def create_user(email, password, realm, full_name, short_name): user.save() UserProfile.create(user, realm, full_name, short_name) -def create_user_if_needed(realm, email, password, full_name, short_name): +def create_user_if_needed(realm, email, full_name, short_name): try: return User.objects.get(email=email) except User.DoesNotExist: # forge a user for this person - create_user(email, password, realm, + create_user(email, initial_password(email), realm, full_name, short_name) user = User.objects.get(email=email) return user diff --git a/zephyr/views.py b/zephyr/views.py index 6bb2352af3..de481638d0 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -338,7 +338,7 @@ def already_sent_forged_message(request): def create_forged_message_users(request, user_profile): # Create a user for the sender, if needed email = request.POST['sender'].lower() - user = create_user_if_needed(user_profile.realm, email, "test", + user = create_user_if_needed(user_profile.realm, email, request.POST['fullname'], request.POST['shortname']) @@ -347,12 +347,12 @@ def create_forged_message_users(request, user_profile): if ',' in request.POST['recipient']: # Huddle message for user_email in [e.strip() for e in request.POST["recipient"].split(",")]: - create_user_if_needed(user_profile.realm, user_email, "test", + create_user_if_needed(user_profile.realm, user_email, user_email.split('@')[0], user_email.split('@')[0]) else: user_email = request.POST["recipient"].strip() - create_user_if_needed(user_profile.realm, user_email, "test", + create_user_if_needed(user_profile.realm, user_email, user_email.split('@')[0], user_email.split('@')[0]) return user