Fix the fact that new auto-created MIT users are active.

(imported from commit 577f1a0165a56fc3cc1ed6f0a54f6c5f31345cc7)
This commit is contained in:
Tim Abbott 2012-10-29 15:56:02 -04:00
parent ee31a1b1a6
commit 44b332693e
2 changed files with 11 additions and 6 deletions

View File

@ -196,20 +196,23 @@ def create_user_base(email, password, active=True):
username = base64.b32encode(email_hash)[:30]
return create_user_hack(username, password, email, active)
def create_user(email, password, realm, full_name, short_name):
user = create_user_base(email=email, password=password)
def create_user(email, password, realm, full_name, short_name,
active=True):
user = create_user_base(email=email, password=password,
active=active)
user.save()
return UserProfile.create(user, realm, full_name, short_name)
# TODO: This has a race where a user could be created twice. Need to
# add transactions.
def create_user_if_needed(realm, email, full_name, short_name):
def create_user_if_needed(realm, email, full_name, short_name,
active=True):
try:
return UserProfile.objects.get(user__email=email)
except UserProfile.DoesNotExist:
# forge a user for this person
return create_user(email, initial_password(email), realm,
full_name, short_name)
full_name, short_name, active=active)
def bulk_create_users(realms, users_raw):
"""

View File

@ -556,7 +556,8 @@ def create_mirrored_message_users(request, user_profile):
# Create a user for the sender, if needed
if 'email' in sender_data:
sender = create_user_if_needed(user_profile.realm, sender_data['email'],
sender_data['full_name'], sender_data['short_name'])
sender_data['full_name'], sender_data['short_name'],
active=False)
else:
sender = user_profile
@ -564,7 +565,8 @@ def create_mirrored_message_users(request, user_profile):
for recipient in huddle_recipients:
create_user_if_needed(user_profile.realm, recipient,
recipient.split('@')[0],
recipient.split('@')[0])
recipient.split('@')[0],
active=False)
return (True, sender)