register: Activate existing mirror dummy only if on same realm.

The one thing this bit of logic is used for is to decide whether
there's an existing user which is a mirror dummy that we should
activate.  This change causes us to ignore such an existing user if
it's on some other realm, and go straight into `do_create_user`.
This commit is contained in:
Greg Price 2017-11-27 18:01:44 -08:00
parent eb8b05b2b5
commit 5f38b374b6
1 changed files with 7 additions and 4 deletions

View File

@ -14,7 +14,7 @@ from django.core import validators
from zerver.context_processors import get_realm_from_request
from zerver.models import UserProfile, Realm, Stream, MultiuseInvite, \
name_changes_disabled, email_to_username, email_allowed_for_realm, \
get_realm, get_user_profile_by_email, get_default_stream_groups
get_realm, get_user, get_default_stream_groups
from zerver.lib.send_email import send_email, FromAddress
from zerver.lib.events import do_events_register
from zerver.lib.actions import do_change_password, do_change_full_name, do_change_is_admin, \
@ -168,9 +168,12 @@ def accounts_register(request: HttpRequest) -> HttpResponse:
if 'timezone' in request.POST and request.POST['timezone'] in get_all_timezones():
timezone = request.POST['timezone']
try:
existing_user_profile = get_user_profile_by_email(email)
except UserProfile.DoesNotExist:
if not realm_creation:
try:
existing_user_profile = get_user(email, realm)
except UserProfile.DoesNotExist:
existing_user_profile = None
else:
existing_user_profile = None
return_data = {} # type: Dict[str, bool]