def link(request, link_ref):
    link = None
    try:
        link = TempLink.objects.get(link_ref=link_ref)
    except:
        raise Http404("Temp Link Does not Exist")

    token = _check_callback(request)
    if token:
        return link_sso(request, token, link)

    if app_settings.MUMBLE_TEMPS_FORCE_SSO:  #default always SSO
        # prompt the user to login for a new token
        return sso_redirect(request, scopes=['publicData'])

    if request.method == 'POST':  # ok so maybe we want to let some other people in too.
        if request.POST.get('sso', False) == "False":  # they picked user
            name = request.POST.get('name', False)
            association = request.POST.get('association', False)
            return link_username(request, name, association, link)
        elif request.POST.get('sso', False) == "True":  # they picked SSO
            # prompt the user to login for a new token
            return sso_redirect(request, scopes=['publicData'])

    context = {
        'link': link,
    }
    return render(request, 'mumbletemps/login.html', context)
Example #2
0
        def _wrapped_view(request, *args, **kwargs):

            # if we're coming back from SSO for a new token, return it
            token = _check_callback(request)
            if token and new:
                logger.debug(
                    "Got new token from %s session %s. Returning to view.",
                    request.user, request.session.session_key[:5])
                return view_func(request, token, *args, **kwargs)

            # if we're selecting a token, return it
            if request.method == 'POST':
                if request.POST.get("_add", False):
                    logger.debug(
                        "%s has selected to add new token. Redirecting to SSO.",
                        request.user)
                    # user has selected to add a new token
                    from esi.views import sso_redirect
                    return sso_redirect(request, scopes=scopes)

                token_pk = request.POST.get('_token', None)
                if token_pk:
                    logger.debug("%s has selected token %s", request.user,
                                 token_pk)
                    try:
                        token = Token.objects.get(pk=token_pk)
                        # ensure token belongs to this user and has required scopes
                        if (((token.user and token.user == request.user)
                             or not token.user) and Token.objects.filter(
                                 pk=token_pk).require_scopes(
                                     scopes).require_valid().exists()):
                            logger.debug(
                                "Selected token fulfills requirements of view. "
                                "Returning.")
                            return view_func(request, token, *args, **kwargs)

                    except Token.DoesNotExist:
                        logger.debug("Token %s not found.", token_pk)

            if not new:
                # present the user with token choices
                tokens = (Token.objects.filter(user__pk=request.user.pk).
                          require_scopes(scopes).require_valid())
                if tokens.exists():
                    logger.debug("Returning list of available tokens for %s.",
                                 request.user)
                    from esi.views import select_token
                    return select_token(request, scopes=scopes, new=new)
                else:
                    logger.debug(
                        "No tokens found for %s session %s with scopes %s",
                        request.user, request.session.session_key[:5], scopes)

            # prompt the user to add a new token
            logger.debug("Redirecting %s session %s to SSO.", request.user,
                         request.session.session_key[:5])
            from esi.views import sso_redirect
            return sso_redirect(request, scopes=scopes)
Example #3
0
        def _wrapped_view(request, *args, **kwargs):

            # if we're coming back from SSO for a new token, return it
            token = _check_callback(request)
            if token and new:
                tokens = Token.objects.filter(pk=token.pk)
                logger.debug("Returning new token.")
                return view_func(request, tokens, *args, **kwargs)

            if not new:
                # ensure user logged in to check existing tokens
                if not request.user.is_authenticated:
                    logger.debug(
                        "Session {0} is not logged in. Redirecting to login.".format(request.session.session_key[:5]))
                    from django.contrib.auth.views import redirect_to_login
                    return redirect_to_login(request.get_full_path())

                # collect tokens in db, check if still valid, return if any
                tokens = Token.objects.filter(user__pk=request.user.pk).require_scopes(scopes).require_valid()
                if tokens.exists():
                    logger.debug("Retrieved {0} tokens for {1} session {2}".format(tokens.count(), request.user,
                                                                                   request.session.session_key[:5]))
                    return view_func(request, tokens, *args, **kwargs)

            # trigger creation of new token via sso
            logger.debug("No tokens identified for {0} session {1}. Redirecting to SSO.".format(request.user, request.session.session_key[:5]))
            from esi.views import sso_redirect
            return sso_redirect(request, scopes=scopes)
Example #4
0
 def get(self, request, *args, **kwargs):
     link_ref = kwargs.get("link_ref", "")
     link = get_object_or_404(TempLink, link_ref=link_ref)
     token = _check_callback(request)
     sso = request.GET.get("sso", "False") == "True"
     if token:
         return self.link_sso(token, link)
     if app_settings.MUMBLE_TEMPS_FORCE_SSO or sso:
         return sso_redirect(request, scopes=["publicData"])
     ctx = self.get_context_data(link=link)
     return self.render_to_response(ctx)
Example #5
0
        def _wrapped_view(request, *args, **kwargs):

            # if we're coming back from SSO for a new token, return it
            token = _check_callback(request)
            if token:
                logger.debug(
                    "Got new token from session %s. Returning to view.",
                    request.session.session_key[:5])
                return view_func(request, token, *args, **kwargs)

            # prompt the user to login for a new token
            logger.debug("Redirecting session %s to SSO.",
                         request.session.session_key[:5])
            from esi.views import sso_redirect
            return sso_redirect(request, scopes=scopes)
        def _wrapped_view(request, *args, **kwargs):
            scopes = ''
            if request.user.profile.state is not None:
                scopes = ' '.join(
                    StandingsManager.get_required_scopes_for_state(
                        request.user.profile.state.name))

            # if we're coming back from SSO for a new token, return it
            token = _check_callback(request)
            if token and new:
                logger.debug(
                    "Got new token from {0} session {1}. Returning to view.".
                    format(request.user, request.session.session_key[:5]))
                return view_func(request, token, *args, **kwargs)

            # if we're selecting a token, return it
            if request.method == 'POST':
                if request.POST.get("_add", False):
                    logger.debug(
                        "{0} has selected to add new token. Redirecting to SSO."
                        .format(request.user))
                    # user has selected to add a new token
                    from esi.views import sso_redirect
                    return sso_redirect(request, scopes=scopes)

                token_pk = request.POST.get('_token', None)
                if token_pk:
                    logger.debug("{0} has selected token {1}".format(
                        request.user, token_pk))
                    try:
                        token = Token.objects.get(pk=token_pk)
                        # ensure token belongs to this user and has required scopes
                        if ((token.user and token.user == request.user)
                                or not token.user) and Token.objects.filter(
                                    pk=token_pk).require_scopes(
                                        scopes).require_valid().exists():
                            logger.debug(
                                "Selected token fulfills requirements of view. Returning."
                            )
                            return view_func(request, token, *args, **kwargs)
                    except Token.DoesNotExist:
                        logger.debug("Token {0} not found.".format(token_pk))
                        pass

            if not new:
                # present the user with token choices
                tokens = Token.objects.filter(
                    user__pk=request.user.pk).require_scopes(
                        scopes).require_valid()
                if tokens.exists():
                    logger.debug(
                        "Returning list of available tokens for {0}.".format(
                            request.user))
                    from esi.views import select_token
                    return select_token(request, scopes=scopes, new=new)
                else:
                    logger.debug(
                        "No tokens found for {0} session {1} with scopes {2}".
                        format(request.user, request.session.session_key[:5],
                               scopes))

            # prompt the user to add a new token
            logger.debug("Redirecting {0} session {1} to SSO.".format(
                request.user, request.session.session_key[:5]))
            from esi.views import sso_redirect
            return sso_redirect(request, scopes=scopes)