<commit_before>import urllib

from django_authopenid.forms import OpenidDissociateForm, AssociateOpenID
from django_authopenid.forms import OpenidSigninForm
from django_authopenid import DjangoOpenIDStore
from django_authopenid.models import UserAssociation
from django_authopenid.utils import *
from django_authopenid.views import associate_failure, complete
from django_authopenid.views import _build_context, signin_success, signin_failure, not_authenticated
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.auth import logout as auth_logout
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.shortcuts import render_to_response as render
from django.template import RequestContext
from django.utils.encoding import smart_unicode
from django.views.decorators.csrf import csrf_exempt, csrf_protect
from django.views.generic.simple import redirect_to
from openid.consumer.consumer import Consumer, SUCCESS, CANCEL, FAILURE, SETUP_NEEDED
from openid.consumer.discover import DiscoveryFailure
from openid.yadis import xri
import signals

import authentic.saml.common
import authentic.authsaml2.utils

OPENID_PROVIDER = ['https://me.yahoo.com//','http://openid.aol.com/','http://.myopenid.com/',
                    'http://.livejournal.com/','http://www.flickr.com/photos//','http://.wordpress.com/'
                    'http://.blogspot.com/','http://.pip.verisignlabs.com/','http://.myvidoop.com/'
                    'http://.pip.verisignlabs.com/','http://claimid.com/']

def accumulate_from_backends(request, method_name):
    from authentic.idp import get_backends
    list = []
    for backend in get_backends():
        method = getattr(backend, method_name, None)
        if callable(method):
            list += method(request)
    return list

def service_list(request):
    '''Compute the service list to show on user homepage'''
    return accumulate_from_backends(request, 'service_list')

def homepage(request):
    '''Homepage of the IdP'''
    import authentic.saml.common
    import authentic.authsaml2.utils
    tpl_parameters = {}
    tpl_parameters['authorized_services'] = service_list(request)
    if authentic.authsaml2.utils.is_sp_configured():
        tpl_parameters['provider_active_session'] = authentic.saml.common.get_provider_of_active_session(request)
        tpl_parameters['provider_name'] = authentic.saml.common.get_provider_of_active_session_name(request)
    if settings.IDP_OPENID:
        tpl_parameters['openid'] = request.user.openid_set
        tpl_parameters['IDP_OPENID'] = settings.IDP_OPENID
    return render_to_response('index.html', tpl_parameters, RequestContext(request))

def authsaml2_login_page(request):
    if not authentic.authsaml2.utils.is_sp_configured():
        return {}
    return {'providers_list': authentic.saml.common.get_idp_list()}

def logout_list(request):
    '''Return logout links from idp backends'''
    return accumulate_from_backends(request, 'logout_list')

def logout(request, next_page='/', redirect_field_name=REDIRECT_FIELD_NAME,
        template = 'idp/logout.html'):
    "Logs out the user and displays 'You are logged out' message."
    signals.auth_logout.send(sender = None, user = request.user)
    do_local = request.REQUEST.has_key('local')
    l = logout_list(request)
    context = RequestContext(request)
    context['redir_timeout'] = 600
    if l and not do_local:
        # Full logout
        next_page = '?local&next=%s' % urllib.quote(next_page)
        context['logout_list'] = l
        context['next_page'] = next_page
        return render_to_response(template, context_instance = context)
    else:
        # Local logout
        auth_logout(request)
        redirect_to = request.REQUEST.get(redirect_field_name, None)
        if redirect_to:
            next_page = redirect_to
        context['next_page'] = next_page
        context['message'] = 'You are logged out'
        return render_to_response(template, context_instance = context)


@csrf_exempt
def mycomplete(request, on_success=None, on_failure=None, return_to=None, 
    **kwargs):
    on_success = on_success or default_on_success
    on_failure = on_failure or default_on_failure
    consumer = Consumer(request.session, DjangoOpenIDStore())
    # make sure params are encoded in utf8
    params = dict((k,smart_unicode(v)) for k, v in request.GET.items())
    openid_response = consumer.complete(params, return_to)

    if not hasattr(request.GET,'openid.identity'):
        _openid_url = 'None'
    else:<commit_msg>[idp views] add method to redirect to logout page<commit_after>import urllib

from django_authopenid.forms import OpenidDissociateForm, AssociateOpenID
from django_authopenid.forms import OpenidSigninForm
from django_authopenid import DjangoOpenIDStore
from django_authopenid.models import UserAssociation
from django_authopenid.utils import *
from django_authopenid.views import associate_failure, complete
from django_authopenid.views import _build_context, signin_success, signin_failure, not_authenticated
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.auth import logout as auth_logout
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.shortcuts import render_to_response as render
from django.template import RequestContext
from django.utils.encoding import smart_unicode
from django.views.decorators.csrf import csrf_exempt, csrf_protect
from django.views.generic.simple import redirect_to
from openid.consumer.consumer import Consumer, SUCCESS, CANCEL, FAILURE, SETUP_NEEDED
from openid.consumer.discover import DiscoveryFailure
from openid.yadis import xri
import signals

import authentic.saml.common
import authentic.authsaml2.utils

OPENID_PROVIDER = ['https://me.yahoo.com//','http://openid.aol.com/','http://.myopenid.com/',
                    'http://.livejournal.com/','http://www.flickr.com/photos//','http://.wordpress.com/'
                    'http://.blogspot.com/','http://.pip.verisignlabs.com/','http://.myvidoop.com/'
                    'http://.pip.verisignlabs.com/','http://claimid.com/']

def accumulate_from_backends(request, method_name):
    from authentic.idp import get_backends
    list = []
    for backend in get_backends():
        method = getattr(backend, method_name, None)
        if callable(method):
            list += method(request)
    return list

def service_list(request):
    '''Compute the service list to show on user homepage'''
    return accumulate_from_backends(request, 'service_list')

def homepage(request):
    '''Homepage of the IdP'''
    import authentic.saml.common
    import authentic.authsaml2.utils
    tpl_parameters = {}
    tpl_parameters['authorized_services'] = service_list(request)
    if authentic.authsaml2.utils.is_sp_configured():
        tpl_parameters['provider_active_session'] = authentic.saml.common.get_provider_of_active_session(request)
        tpl_parameters['provider_name'] = authentic.saml.common.get_provider_of_active_session_name(request)
    if settings.IDP_OPENID:
        tpl_parameters['openid'] = request.user.openid_set
        tpl_parameters['IDP_OPENID'] = settings.IDP_OPENID
    return render_to_response('index.html', tpl_parameters, RequestContext(request))

def authsaml2_login_page(request):
    if not authentic.authsaml2.utils.is_sp_configured():
        return {}
    return {'providers_list': authentic.saml.common.get_idp_list()}

def logout_list(request):
    '''Return logout links from idp backends'''
    return accumulate_from_backends(request, 'logout_list')

def logout(request, next_page='/', redirect_field_name=REDIRECT_FIELD_NAME,
        template = 'idp/logout.html'):
    "Logs out the user and displays 'You are logged out' message."
    signals.auth_logout.send(sender = None, user = request.user)
    do_local = request.REQUEST.has_key('local')
    l = logout_list(request)
    context = RequestContext(request)
    context['redir_timeout'] = 600
    if l and not do_local:
        # Full logout
        next_page = '?local&next=%s' % urllib.quote(next_page)
        context['logout_list'] = l
        context['next_page'] = next_page
        return render_to_response(template, context_instance = context)
    else:
        # Local logout
        auth_logout(request)
        redirect_to = request.REQUEST.get(redirect_field_name, None)
        if redirect_to:
            next_page = redirect_to
        context['next_page'] = next_page
        context['message'] = 'You are logged out'
        return render_to_response(template, context_instance = context)

def redirect_to_logout(request, next_page='/'):
    return HttpResponseRedirect('%s?next=%s' % (reverse(logout), urllib.quote(next_page)))

@csrf_exempt
def mycomplete(request, on_success=None, on_failure=None, return_to=None,
    **kwargs):
    on_success = on_success or default_on_success
    on_failure = on_failure or default_on_failure
    consumer = Consumer(request.session, DjangoOpenIDStore())
    # make sure params are encoded in utf8
    params = dict((k,smart_unicode(v)) for k, v in request.GET.items())
    openid_response = consumer.complete(params, return_to)

    if not hasattr(request.GET,'openid.identity'):
        _openid_url = 'None'
    else:
{'fraction_non_alphanumeric': 0.0965144720750102, 'fraction_numerical': 0.0018344883815735833, 'mean_word_length': 4.3505997818974915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2037971', 'n_tokens_mistral': 2982, 'n_tokens_neox': 2914, 'n_words': 648}