示例#1
0
def login_complete(request, redirect_field_name=REDIRECT_FIELD_NAME,
                   render_failure=default_render_failure):
    redirect_to = request.REQUEST.get(redirect_field_name, '')

    openid_response = parse_openid_response(request)
    if not openid_response:
        return render_failure(
            request, 'This is an OpenID relying party endpoint.')

    if openid_response.status == SUCCESS:
        user = authenticate(openid_response=openid_response)
        if user is not None:
            if user.is_active:
                auth_login(request, user)
                response = HttpResponseRedirect(sanitise_redirect_url(redirect_to))

                # Notify any listeners that we successfully logged in.
                openid_login_complete.send(sender=UserOpenID, request=request,
                    openid_response=openid_response)

                return response
            else:
                return render_failure(request, 'Disabled account')
        else:
            return render_failure(request, 'Unknown user')
    elif openid_response.status == FAILURE:
        return render_failure(
            request, 'OpenID authentication failed: %s' %
            openid_response.message)
    elif openid_response.status == CANCEL:
        return render_failure(request, 'Authentication cancelled')
    else:
        assert False, (
            "Unknown OpenID response type: %r" % openid_response.status)
def login_complete(request, redirect_field_name=REDIRECT_FIELD_NAME,
                   render_failure=None):
    redirect_to = get_query_dict(request).get(redirect_field_name, '')
    render_failure = (
        render_failure or getattr(settings, 'OPENID_RENDER_FAILURE', None) or
        default_render_failure)

    openid_response = parse_openid_response(request)
    if not openid_response:
        return render_failure(
            request, 'This is an OpenID relying party endpoint.')

    if openid_response.status == SUCCESS:
        try:
            user = authenticate(openid_response=openid_response)
        except DjangoOpenIDException, e:
            return render_failure(request, e.message, exception=e)

        if user is not None:
            if user.is_active:
                auth_login(request, user)
                response = HttpResponseRedirect(
                    sanitise_redirect_url(redirect_to))

                # Notify any listeners that we successfully logged in.
                openid_login_complete.send(
                    sender=UserOpenID, request=request,
                    openid_response=openid_response)

                return response
            else:
                return render_failure(request, 'Disabled account')
        else:
            return render_failure(request, 'Unknown user')
示例#3
0
def login_complete(request,
                   redirect_field_name=REDIRECT_FIELD_NAME,
                   render_failure=None):
    redirect_to = request.REQUEST.get(redirect_field_name, '')
    render_failure = render_failure or \
                     getattr(settings, 'OPENID_RENDER_FAILURE', None) or \
                     default_render_failure

    openid_response = parse_openid_response(request)
    if not openid_response:
        return HttpResponseRedirect(sanitise_redirect_url(redirect_to))

    if openid_response.status == SUCCESS:
        try:
            user = authenticate(openid_response=openid_response)
        except DjangoOpenIDException, e:
            return HttpResponseRedirect(sanitise_redirect_url(redirect_to))

        if user is not None:
            if user.is_active:
                auth_login(request, user)
                response = HttpResponseRedirect(
                    sanitise_redirect_url(redirect_to))

                # Notify any listeners that we successfully logged in.
                openid_login_complete.send(sender=UserOpenID,
                                           request=request,
                                           user=user,
                                           openid_response=openid_response)

                return response
示例#4
0
def login_complete(request, redirect_field_name=REDIRECT_FIELD_NAME,
                   render_failure=None):
    redirect_to = request.REQUEST.get(redirect_field_name, '')
    render_failure = render_failure or \
                     getattr(settings, 'OPENID_RENDER_FAILURE', None) or \
                     default_render_failure

    openid_response = parse_openid_response(request)
    if not openid_response:
        return HttpResponseRedirect(sanitise_redirect_url(redirect_to))

    if openid_response.status == SUCCESS:
        try:
            user = authenticate(openid_response=openid_response)
        except DjangoOpenIDException, e:
            return HttpResponseRedirect(sanitise_redirect_url(redirect_to))

        if user is not None:
            if user.is_active:
                auth_login(request, user)
                response = HttpResponseRedirect(sanitise_redirect_url(redirect_to))

                # Notify any listeners that we successfully logged in.
                openid_login_complete.send(sender=UserOpenID, request=request,
                    user=user,
                    openid_response=openid_response)

                return response
示例#5
0
def login_complete(request,
                   redirect_field_name=REDIRECT_FIELD_NAME,
                   render_failure=None):
    redirect_to = get_query_dict(request).get(redirect_field_name, '')
    render_failure = (render_failure
                      or getattr(settings, 'OPENID_RENDER_FAILURE', None)
                      or default_render_failure)

    openid_response = parse_openid_response(request)
    if not openid_response:
        return render_failure(request,
                              'This is an OpenID relying party endpoint.')

    if openid_response.status == SUCCESS:
        try:
            user = authenticate(openid_response=openid_response)
        except DjangoOpenIDException, e:
            return render_failure(request, e.message, exception=e)

        if user is not None:
            if user.is_active:
                auth_login(request, user)
                response = HttpResponseRedirect(
                    sanitise_redirect_url(redirect_to))

                # Notify any listeners that we successfully logged in.
                openid_login_complete.send(sender=UserOpenID,
                                           request=request,
                                           openid_response=openid_response)

                return response
            else:
                return render_failure(request, 'Disabled account')
        else:
            return render_failure(request, 'Unknown user')
示例#6
0
def login_complete(request,
                   redirect_field_name=REDIRECT_FIELD_NAME,
                   render_failure=None):
    data = get_request_data(request)
    redirect_to = data.get(redirect_field_name, '')
    render_failure = (render_failure
                      or getattr(settings, 'OPENID_RENDER_FAILURE', None)
                      or default_render_failure)

    openid_response = parse_openid_response(request)
    if not openid_response:
        return render_failure(request,
                              'This is an OpenID relying party endpoint.')

    if openid_response.status == SUCCESS:
        try:
            user = authenticate(openid_response=openid_response)
        except DjangoOpenIDException as e:
            return render_failure(request,
                                  getattr(e, 'message', str(e)),
                                  exception=e)

        if user is not None:
            if user.is_active:
                auth_login(request, user)
                response = HttpResponseRedirect(
                    sanitise_redirect_url(redirect_to))

                # Notify any listeners that we successfully logged in.
                openid_login_complete.send(sender=UserOpenID,
                                           request=request,
                                           openid_response=openid_response)

                return response
            else:
                return render_failure(request, 'Disabled account')
        else:
            return render_failure(request, 'Unknown user')
    elif openid_response.status == FAILURE:
        return render_failure(
            request,
            'OpenID authentication failed: %s' % openid_response.message)
    elif openid_response.status == CANCEL:
        return render_failure(request, 'Authentication cancelled')
    else:
        assert False, ("Unknown OpenID response type: %r" %
                       openid_response.status)
示例#7
0
def login_complete(request,
                   redirect_field_name=REDIRECT_FIELD_NAME,
                   render_failure=None):
    redirect_to = request.REQUEST.get(redirect_field_name, '')
    render_failure = render_failure or \
                     getattr(settings, 'OPENID_RENDER_FAILURE', None) or \
                     default_render_failure

    openid_response = parse_openid_response(request)
    if not openid_response:
        return HttpResponseRedirect(sanitise_redirect_url(redirect_to))

    if openid_response.status == SUCCESS:
        try:
            user = authenticate(openid_response=openid_response)
        except DjangoOpenIDException:
            return HttpResponseRedirect(sanitise_redirect_url(redirect_to))

        if user is not None:
            if user.is_active:
                auth_login(request, user)
                response = HttpResponseRedirect(
                    sanitise_redirect_url(redirect_to))

                # Notify any listeners that we successfully logged in.
                openid_login_complete.send(sender=UserOpenID,
                                           request=request,
                                           user=user,
                                           openid_response=openid_response)

                return response
            else:
                if "next" in request.POST:
                    return HttpResponseRedirect(
                        "/Shibboleth.sso/Login?%s" % urlencode({
                            "entityID":
                            request.POST.get("entityid", ""),
                            "target":
                            request.POST.get("next", default="/project/")
                        }))

                from tukey.webforms.views import osdc_apply
                return osdc_apply(request, user)

    return HttpResponseRedirect(sanitise_redirect_url(redirect_to))
示例#8
0
def login_complete(request, redirect_field_name=REDIRECT_FIELD_NAME,
                   render_failure=None):
    data = get_request_data(request)
    redirect_to = data.get(redirect_field_name, '')
    render_failure = (
        render_failure or getattr(settings, 'OPENID_RENDER_FAILURE', None) or
        default_render_failure)

    openid_response = parse_openid_response(request)
    if not openid_response:
        return render_failure(
            request, 'This is an OpenID relying party endpoint.')

    if openid_response.status == SUCCESS:
        try:
            user = authenticate(openid_response=openid_response)
        except DjangoOpenIDException as e:
            return render_failure(
                request, getattr(e, 'message', str(e)), exception=e)

        if user is not None:
            if user.is_active:
                auth_login(request, user)
                response = HttpResponseRedirect(
                    sanitise_redirect_url(redirect_to))

                # Notify any listeners that we successfully logged in.
                openid_login_complete.send(
                    sender=UserOpenID, request=request,
                    openid_response=openid_response)

                return response
            else:
                return render_failure(request, 'Disabled account')
        else:
            return render_failure(request, 'Unknown user')
    elif openid_response.status == FAILURE:
        return render_failure(
            request, 'OpenID authentication failed: %s' %
            openid_response.message)
    elif openid_response.status == CANCEL:
        return render_failure(request, 'Authentication cancelled')
    else:
        assert False, (
            "Unknown OpenID response type: %r" % openid_response.status)
示例#9
0
def login_complete(request, redirect_field_name=REDIRECT_FIELD_NAME,
                   render_failure=None):
    redirect_to = request.REQUEST.get(redirect_field_name, '')
    render_failure = render_failure or \
                     getattr(settings, 'OPENID_RENDER_FAILURE', None) or \
                     default_render_failure

    openid_response = parse_openid_response(request)
    if not openid_response:
        return HttpResponseRedirect(sanitise_redirect_url(redirect_to))

    if openid_response.status == SUCCESS:
        try:
            user = authenticate(openid_response=openid_response)
        except DjangoOpenIDException:
            return HttpResponseRedirect(sanitise_redirect_url(redirect_to))

        if user is not None:
            if user.is_active:
                auth_login(request, user)
                response = HttpResponseRedirect(sanitise_redirect_url(redirect_to))

                # Notify any listeners that we successfully logged in.
                openid_login_complete.send(sender=UserOpenID, request=request,
                    user=user, openid_response=openid_response)

                return response
            else:
                if "next" in request.POST:
                    return HttpResponseRedirect(
                        "/Shibboleth.sso/Login?%s" % urlencode(
                                {"entityID": request.POST.get("entityid", ""),
                        "target": request.POST.get("next", default="/project/")}
                        )
                    )

                from tukey.webforms.views import osdc_apply
                return osdc_apply(request, user)

    return HttpResponseRedirect(sanitise_redirect_url(redirect_to))
示例#10
0
def login_complete(request, redirect_field_name=REDIRECT_FIELD_NAME,
                   render_failure=None):
    data = get_request_data(request)
    redirect_to = data.get(redirect_field_name, '')
    render_failure = (
        render_failure or getattr(settings, 'OPENID_RENDER_FAILURE', None) or
        default_render_failure)

    openid_response = parse_openid_response(request)
    if not openid_response:
        return render_failure(
            request, 'This is an OpenID relying party endpoint.')

    if openid_response.status == SUCCESS:
        # Try to find the user with different OpenID variants
        # Build up the base ID - http w/ trailing slash
        openid = openid_response.identity_url.replace('https://', 'http://')
        if openid[-1] != '/':
            openid = openid + '/'

        found = False

        # First try - http w/ trailing slash
        if UserOpenID.objects.filter(claimed_id = openid):
            openid_response.identity_url = openid
            found = True

        # Second try - http w/o trailing slash
        if not found:
            openid = openid[0:-1]
            if UserOpenID.objects.filter(claimed_id = openid):
                openid_response.identity_url = openid
                found = True

        # Third try - https w/o trailing slash
        if not found:
            openid = openid.replace('http://', 'https://')
            if UserOpenID.objects.filter(claimed_id = openid):
                openid_response.identity_url = openid
                found = True

        # Forth try / last resort - https w/ trailing slash
        if not found:
            openid = openid + '/'
            if UserOpenID.objects.filter(claimed_id = openid):
                openid_response.identity_url = openid
                found = True

        # if found = False?!

        try:
            user = authenticate(openid_response=openid_response)
        except DjangoOpenIDException as e:
            return render_failure(
                request, getattr(e, 'message', str(e)), exception=e)

        if user is not None:
            if user.is_active:
                auth_login(request, user)
                response = HttpResponseRedirect(
                    sanitise_redirect_url(redirect_to))

                # Notify any listeners that we successfully logged in.
                openid_login_complete.send(
                    sender=UserOpenID, request=request,
                    openid_response=openid_response)

                return response
            else:
                return render_failure(request, 'Disabled account')
        else:
            return render_failure(request, 'Unknown user')
    elif openid_response.status == FAILURE:
        return render_failure(
            request, 'OpenID authentication failed: %s' %
            openid_response.message)
    elif openid_response.status == CANCEL:
        return render_failure(request, 'Authentication cancelled')
    else:
        assert False, (
            "Unknown OpenID response type: %r" % openid_response.status)