'Flow is activated upon a user logging in to where an AuthIdentity is
not present.
The flow will attempt to answer the following:
- Is there an existing user with the same email address? Should they be
merged?
- Is there an existing user (via authentication) that shoudl be merged?
- Should I create a new user based on this identity?'

def _handle_unknown_identity(self, identity):

    request = self.request
    op = request.POST.get('op')
    if (not request.user.is_authenticated()):
        try:
            existing_user = self._find_existing_user(identity['email'])
        except IndexError:
            existing_user = None
        if (existing_user and existing_user.is_managed):
            has_membership = OrganizationMember.objects.filter(user=existing_user, organization=self.organization).exists()
            if has_membership:
                if (not auth.login(request, existing_user, after_2fa=request.build_absolute_uri(), organization_id=self.organization.id)):
                    return HttpResponseRedirect(auth.get_login_redirect(self.request))
                op = 'confirm'
            else:
                existing_user = None
        login_form = self._get_login_form(existing_user)
    elif request.user.is_managed:
        has_membership = OrganizationMember.objects.filter(user=request.user, organization=self.organization).exists()
        if has_membership:
            op = 'confirm'
    if ((op == 'confirm') and request.user.is_authenticated()):
        auth_identity = self._handle_attach_identity(identity)
    elif (op == 'newuser'):
        auth_identity = self._handle_new_user(identity)
    elif ((op == 'login') and (not request.user.is_authenticated())):
        op = None
        if login_form.is_valid():
            if (not auth.login(request, login_form.get_user(), after_2fa=request.build_absolute_uri(), organization_id=self.organization.id)):
                return HttpResponseRedirect(auth.get_login_redirect(self.request))
        else:
            auth.log_auth_failure(request, request.POST.get('username'))
    else:
        op = None
    if (not op):
        if request.user.is_authenticated():
            return self.respond('sentry/auth-confirm-link.html', {'identity': identity, 'existing_user': request.user, 'identity_display_name': self._get_display_name(identity), 'identity_identifier': self._get_identifier(identity)})
        return self.respond('sentry/auth-confirm-identity.html', {'existing_user': existing_user, 'identity': identity, 'login_form': login_form, 'identity_display_name': self._get_display_name(identity), 'identity_identifier': self._get_identifier(identity)})
    user = auth_identity.user
    user.backend = settings.AUTHENTICATION_BACKENDS[0]
    if (not auth.login(request, user, after_2fa=request.build_absolute_uri(), organization_id=self.organization.id)):
        return HttpResponseRedirect(auth.get_login_redirect(self.request))
    self.clear_session()
    return HttpResponseRedirect(auth.get_login_redirect(self.request))
