Ejemplo n.º 1
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
Ejemplo n.º 2
0
def associate_steam(request):
    """Associate a Steam account with a Lutris account"""
    LOGGER.info("Associating Steam user with Lutris account")
    if not request.user.is_authenticated:
        LOGGER.info("User is authenticated, completing login")
        return login_complete(request)
    else:
        openid_response = parse_openid_response(request)
        account_url = reverse('user_account', args=(request.user.username, ))
        if openid_response.status == 'failure':
            messages.warning(request, "Failed to associate Steam account")
            REQUEST_LOGGER.error("Failed to associate Steam account for %s", request.user.username,
                                 extra={
                                     'status_code': 400,
                                     'request': request
                                 })
            return redirect(account_url)
        openid_backend = OpenIDBackend()
        try:
            openid_backend.associate_openid(request.user, openid_response)
        except IdentityAlreadyClaimed:
            messages.warning(
                request,
                "This Steam account is already claimed by another Lutris "
                "account.\nPlease contact an administrator if you want "
                "to reattribute your Steam account to this current account."
            )
            return redirect(account_url)

        request.user.set_steamid()
        request.user.save()
        return redirect(reverse("library_steam_sync"))
Ejemplo n.º 3
0
def openid_login_complete(request,
                          redirect_field_name=REDIRECT_FIELD_NAME,
                          render_failure=None):
    """Complete the openid login process"""

    render_failure = (render_failure or default_render_failure)

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

    if openid_response.status == SUCCESS:
        external_id = openid_response.identity_url
        oid_backend = openid_auth.OpenIDBackend()
        details = oid_backend._extract_user_details(openid_response)

        log.debug('openid success, details=%s', details)

        url = getattr(settings, 'OPENID_SSO_SERVER_URL', None)
        external_domain = "{0}{1}".format(OPENID_DOMAIN_PREFIX, url)
        fullname = '%s %s' % (details.get('first_name', ''),
                              details.get('last_name', ''))

        return _external_login_or_signup(
            request,
            external_id,
            external_domain,
            details,
            details.get('email', ''),
            fullname,
            retfun=functools.partial(redirect, get_next_url_for_login_page(request)),
        )

    return render_failure(request, 'Openid failure')
Ejemplo n.º 4
0
def profile_edit_openids_complete(request):
    openid_response = openid_views.parse_openid_response(request)
    yours_msg = _('The identity %s has already been claimed by you.')
    theirs_msg = _('The identity %s has already been claimed by another user.')
    if openid_response:
        if openid_response.status == openid_views.SUCCESS:
            url = openid_response.identity_url
            try:
                user_openid = UserOpenID.objects.get(
                    claimed_id__exact=url)
            except UserOpenID.DoesNotExist:
                user_openid = UserOpenID(user=request.user,
                claimed_id=openid_response.identity_url,
                display_id=openid_response.endpoint.getDisplayIdentifier())
                user_openid.save()
                messages.info(request,
                    _('The identity %s has been saved.') % url)
            else:
                if user_openid.user == request.user:
                    messages.error(request, yours_msg % url)
                else:
                    messages.error(request, theirs_msg % url)
        elif openid_response.status == openid_views.FAILURE:
            messages.error(request, _('OpenID authentication failed: %s') %
                openid_response.message)
        elif openid_response.status == openid_views.CANCEL:
            return messages.error(request, _('Authentication cancelled.'))
        else:
            return messages.error(
                _('Unknown OpenID response type: %r') % openid_response.status)
    else:
        return messages.error(_('This is an OpenID relying party endpoint.'))
    return http.HttpResponseRedirect(reverse('users_profile_edit_openids'))
Ejemplo n.º 5
0
def profile_edit_openids_complete(request):
    openid_response = openid_views.parse_openid_response(request)
    yours_msg = _('The identity %s has already been claimed by you.')
    theirs_msg = _('The identity %s has already been claimed by another user.')
    if openid_response:
        if openid_response.status == openid_views.SUCCESS:
            url = openid_response.identity_url
            try:
                user_openid = UserOpenID.objects.get(
                    claimed_id__exact=url)
            except UserOpenID.DoesNotExist:
                user_openid = UserOpenID(user=request.user,
                claimed_id=openid_response.identity_url,
                display_id=openid_response.endpoint.getDisplayIdentifier())
                user_openid.save()
                messages.info(request,
                    _('The identity %s has been saved.') % url)
            else:
                if user_openid.user == request.user:
                    messages.error(request, yours_msg % url)
                else:
                    messages.error(request, theirs_msg % url)
        elif openid_response.status == openid_views.FAILURE:
            messages.error(request, _('OpenID authentication failed: %s') %
                openid_response.message)
        elif openid_response.status == openid_views.CANCEL:
            return messages.error(request, _('Authentication cancelled.'))
        else:
            return messages.error(
                _('Unknown OpenID response type: %r') % openid_response.status)
    else:
        return messages.error(_('This is an OpenID relying party endpoint.'))
    return http.HttpResponseRedirect(reverse('users_profile_edit_openids'))
Ejemplo n.º 6
0
def openid_login_complete(request, redirect_field_name=REDIRECT_FIELD_NAME, render_failure=None):
    """Complete the openid login process"""

    render_failure = render_failure or default_render_failure

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

    if openid_response.status == SUCCESS:
        external_id = openid_response.identity_url
        oid_backend = openid_auth.OpenIDBackend()
        details = oid_backend._extract_user_details(openid_response)

        log.debug("openid success, details=%s", details)

        url = getattr(settings, "OPENID_SSO_SERVER_URL", None)
        external_domain = "{0}{1}".format(OPENID_DOMAIN_PREFIX, url)
        fullname = "%s %s" % (details.get("first_name", ""), details.get("last_name", ""))

        return _external_login_or_signup(
            request, external_id, external_domain, details, details.get("email", ""), fullname
        )

    return render_failure(request, "Openid failure")
Ejemplo n.º 7
0
def openid_login_complete(request,
                          redirect_field_name=REDIRECT_FIELD_NAME,  # pylint: disable=unused-argument
                          render_failure=None):
    """Complete the openid login process"""

    render_failure = (render_failure or default_render_failure)

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

    if openid_response.status == SUCCESS:
        external_id = openid_response.identity_url
        oid_backend = openid_auth.OpenIDBackend()
        details = oid_backend._extract_user_details(openid_response)  # pylint: disable=protected-access

        log.debug('openid success, details=%s', details)

        url = getattr(settings, 'OPENID_SSO_SERVER_URL', None)
        external_domain = "{0}{1}".format(OPENID_DOMAIN_PREFIX, url)
        fullname = '%s %s' % (details.get('first_name', ''),
                              details.get('last_name', ''))

        return _external_login_or_signup(
            request,
            external_id,
            external_domain,
            details,
            details.get('email', ''),
            fullname,
            retfun=functools.partial(redirect, get_next_url_for_login_page(request)),
        )

    return render_failure(request, 'Openid failure')
Ejemplo n.º 8
0
def associate_steam(request):
    """Associate a Steam account with a Lutris account"""
    LOGGER.info("Associating Steam user with Lutris account")
    if not request.user.is_authenticated:
        LOGGER.info("User is authenticated, completing login")
        return login_complete(request)
    else:
        openid_response = parse_openid_response(request)
        account_url = reverse('user_account', args=(request.user.username, ))
        if openid_response.status == 'failure':
            messages.warning(request, "Failed to associate Steam account")
            REQUEST_LOGGER.error("Failed to associate Steam account for %s",
                                 request.user.username,
                                 extra={
                                     'status_code': 400,
                                     'request': request
                                 })
            return redirect(account_url)
        openid_backend = OpenIDBackend()
        try:
            openid_backend.associate_openid(request.user, openid_response)
        except IdentityAlreadyClaimed:
            messages.warning(
                request,
                "This Steam account is already claimed by another Lutris "
                "account.\nPlease contact an administrator if you want "
                "to reattribute your Steam account to this current account.")
            return redirect(account_url)

        request.user.set_steamid()
        request.user.save()
        return redirect(reverse("library_steam_sync"))
Ejemplo n.º 9
0
def openid_login_complete(request,
                          redirect_field_name=REDIRECT_FIELD_NAME,
                          render_failure=None):
    """Complete the openid login process"""

    render_failure = (render_failure or default_render_failure)

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

    if openid_response.status == SUCCESS:
        external_id = openid_response.identity_url
        oid_backend = openid_auth.OpenIDBackend()
        details = oid_backend._extract_user_details(openid_response)

        log.debug('openid success, details=%s' % details)

        url = getattr(settings, 'OPENID_SSO_SERVER_URL', None)
        external_domain = "openid:%s" % url
        fullname = '%s %s' % (details.get('first_name',
                                          ''), details.get('last_name', ''))

        return external_login_or_signup(request, external_id,
                                        external_domain, details,
                                        details.get('email', ''), fullname)

    return render_failure(request, 'Openid failure')
Ejemplo n.º 10
0
def associate_steam(request):
    """Associate a Steam account with a Lutris account"""
    LOGGER.info("Associating Steam user with Lutris account")
    if not request.user.is_authenticated:
        return login_complete(request)

    account_url = reverse('user_account', args=(request.user.username, ))
    try:
        openid_response = parse_openid_response(request)
    except HTTPFetchingError:
        messages.warning(
            request,
            "Steam server is unreachable, please try again in a few moments")
        return redirect(account_url)

    if openid_response.status == 'failure':
        messages.warning(request, "Failed to associate Steam account")
        LOGGER.warning("Failed to associate Steam account for %s",
                       request.user.username)
        return redirect(account_url)
    openid_backend = OpenIDBackend()
    try:
        openid_backend.associate_openid(request.user, openid_response)
    except IdentityAlreadyClaimed:
        messages.warning(
            request, "This Steam account is already claimed by another Lutris "
            "account.\nPlease contact an administrator if you want "
            "to reattribute your Steam account to this current account.")
        return redirect(account_url)

    request.user.set_steamid()
    request.user.save()
    return redirect(reverse("library_steam_sync"))
Ejemplo n.º 11
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
Ejemplo n.º 12
0
def associate_steam(request):
    if not request.user.is_authenticated():
        return login_complete(request)
    else:
        openid_response = parse_openid_response(request)
        if openid_response.status == "failure":
            messages.error(request, "Failed to associate Steam account")
            return redirect(reverse("user_account", args=(request.user.username,)))
        openid_backend = OpenIDBackend()
        openid_backend.associate_openid(request.user, openid_response)
        request.user.set_steamid()
        request.user.save()
        return redirect(reverse("library_steam_sync"))
Ejemplo n.º 13
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))
Ejemplo n.º 14
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))
Ejemplo n.º 15
0
def associate_steam(request):
    if not request.user.is_authenticated():
        return login_complete(request)
    else:
        openid_response = parse_openid_response(request)
        account_url = reverse('user_account', args=(request.user.username, ))
        if openid_response.status == 'failure':
            messages.warning(request, "Failed to associate Steam account")
            return redirect(account_url)
        openid_backend = OpenIDBackend()
        try:
            openid_backend.associate_openid(request.user, openid_response)
        except IdentityAlreadyClaimed:
            messages.warning(
                request,
                "This Steam account is already claimed by another Lutris "
                "account.\nPlease contact an administrator if you want "
                "to reattribute your Steam account to this current account.")
            return redirect(account_url)

        request.user.set_steamid()
        request.user.save()
        return redirect(reverse("library_steam_sync"))
Ejemplo n.º 16
0
def associate_steam(request):
    if not request.user.is_authenticated():
        return login_complete(request)
    else:
        openid_response = parse_openid_response(request)
        account_url = reverse('user_account', args=(request.user.username, ))
        if openid_response.status == 'failure':
            messages.warning(request, "Failed to associate Steam account")
            return redirect(account_url)
        openid_backend = OpenIDBackend()
        try:
            openid_backend.associate_openid(request.user, openid_response)
        except IdentityAlreadyClaimed:
            messages.warning(
                request,
                "This Steam account is already claimed by another Lutris "
                "account.\nPlease contact an administrator if you want "
                "to reattribute your Steam account to this current account."
            )
            return redirect(account_url)

        request.user.set_steamid()
        request.user.save()
        return redirect(reverse("library_steam_sync"))
Ejemplo n.º 17
0
def login(request):
    data = {}
    data['response'] = request.GET["openid.claimed_id"]
    data['id'] = request.GET["openid.claimed_id"][36:]
    data['url'] = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key="+settings.STEAM_API_KEY+"&steamids="+data['id']

    claim = data['response']

    # Get public info
    data['info'] = json.loads(urllib.urlopen(data["url"]).read())["response"]["players"][0]

    handle = data['info']['personaname']
    steamid = data['info']['steamid']
    url = data['info']['profileurl']
    avatar = data['info']['avatar']
    avatarM = data['info']['avatarmedium']
    avatarL = data['info']['avatarfull']
    try:
        primarygroup = data['info']['primaryclanid']
    except KeyError:
        primarygroup = ""
    try:
        realname = data['info']['realname']
    except KeyError:
        realname = ""

    # Find the user
    try:
        useroid = UserOpenID.objects.get(claimed_id=claim)

        # Get them by steamid, then get the User instance associated with this
        # profile.
        userP = UserProfile.objects.get(steamid=steamid)
        user = User.objects.get(id=userP.user_id)

    # New user
    except UserOpenID.DoesNotExist:
        # Slugify their current display name, this will be used for internal control panels only.
        slugName = "{0}-{1}".format(slugify(handle), steamid[len(steamid)-3:len(steamid)])
        user = User.objects.create_user(username=slugName, email='', password='******')
        user.save()
        useroid = UserOpenID(user=user, claimed_id=claim, display_id=claim)
        useroid.save()
    try:
        up = UserProfile.objects.get(user_id=user.id)
    except UserProfile.DoesNotExist:
        up = UserProfile(user_id=user.id)
        up.save()

    # User exists, fill out profile, which is auto-filled with blanks atm.
    up.handle=handle
    up.steamid=steamid
    up.url=url
    up.avatar=avatar
    up.avatarM=avatarM
    up.avatarL=avatarL
    up.primarygroup=primarygroup
    up.realname=realname

    up.save()

    # Stole these lines from inside the openid_auth files. idk why now
    # PROB. IMPORTANT THO
    openid_response = parse_openid_response(request)
    user = authenticate(openid_response=openid_response)

    auth_login(request, user)

    return HttpResponseRedirect('/')