<commit_before>from tornado import auth
from tornado import web
from tornado import httpclient

from suds.client import Client

import re
import random
import string
import urllib
import urlparse
import logging
import json

import db
from helper import *


class ShowAuthPage(myRequestHandler):
    """
    Show Log in page.

    """
    def get(self):

        set_redirect(self)

        self.clear_cookie('session')
        self.render('auth/start.html',
            mobileid = True if self.settings['mobileid_service_name'] and self.settings['mobileid_url'] else False,
            google = True if self.settings['google_client_key'] and self.settings['google_client_secret'] else False,
            facebook = True if self.settings['facebook_api_key'] and self.settings['facebook_secret'] else False,
            twitter = True if self.settings['twitter_consumer_key'] and self.settings['twitter_consumer_secret'] else False,
            live = True if self.settings['live_client_key'] and self.settings['live_client_secret'] else False,
        )


class Exit(myRequestHandler):
    """
    Log out.

    """
    def get(self):
        redirect_url = ''
        if self.current_user:
            if self.current_user.provider == 'google':
                redirect_url = 'https://www.google.com/accounts/logout'
            elif self.current_user.provider == 'facebook':
                redirect_url = 'https://www.facebook.com/logout.php?access_token=%s&confirm=1&next=%s://%s/status' % (self.current_user.access_token, self.request.protocol, self.request.host)
            elif self.current_user.provider == 'live':
                redirect_url = 'https://login.live.com/oauth20_logout.srf?client_id=%s&redirect_uri=%s://%s/status' % (self.settings['live_client_key'], self.request.protocol, self.request.host)

            self.current_user.logout(self)

        self.redirect(redirect_url)


class AuthOAuth2(myRequestHandler, auth.OAuth2Mixin):
    """
    Google, Facebook and MSLive authentication.

    """
    @web.asynchronous
    def get(self, provider):
        set_redirect(self)
        self.oauth2_provider = None

        if provider == 'facebook' and 'facebook_api_key' in self.settings and 'facebook_secret' in self.settings:
            # https://developers.facebook.com/apps
            self.oauth2_provider = {
                'provider':     'facebook',
                'key':          self.settings['facebook_api_key'],<commit_msg>Fixed auth redirect loop bug<commit_after>from tornado import auth
from tornado import web
from tornado import httpclient

from suds.client import Client

import re
import random
import string
import urllib
import urlparse
import logging
import json

import db
from helper import *


class ShowAuthPage(myRequestHandler):
    """
    Show Log in page.

    """
    def get(self):

        set_redirect(self)

        self.clear_cookie('session')
        self.render('auth/start.html',
            mobileid = True if self.settings['mobileid_service_name'] and self.settings['mobileid_url'] else False,
            google = True if self.settings['google_client_key'] and self.settings['google_client_secret'] else False,
            facebook = True if self.settings['facebook_api_key'] and self.settings['facebook_secret'] else False,
            twitter = True if self.settings['twitter_consumer_key'] and self.settings['twitter_consumer_secret'] else False,
            live = True if self.settings['live_client_key'] and self.settings['live_client_secret'] else False,
        )


class Exit(myRequestHandler):
    """
    Log out.

    """
    def get(self):
        redirect_url = '/'
        if self.current_user:
            if self.current_user.provider == 'google':
                redirect_url = 'https://www.google.com/accounts/logout'
            elif self.current_user.provider == 'facebook':
                redirect_url = 'https://www.facebook.com/logout.php?access_token=%s&confirm=1&next=%s://%s/status' % (self.current_user.access_token, self.request.protocol, self.request.host)
            elif self.current_user.provider == 'live':
                redirect_url = 'https://login.live.com/oauth20_logout.srf?client_id=%s&redirect_uri=%s://%s/status' % (self.settings['live_client_key'], self.request.protocol, self.request.host)

            self.current_user.logout(self)

        self.redirect(redirect_url)


class AuthOAuth2(myRequestHandler, auth.OAuth2Mixin):
    """
    Google, Facebook and MSLive authentication.

    """
    @web.asynchronous
    def get(self, provider):
        set_redirect(self)
        self.oauth2_provider = None

        if provider == 'facebook' and 'facebook_api_key' in self.settings and 'facebook_secret' in self.settings:
            # https://developers.facebook.com/apps
            self.oauth2_provider = {
                'provider':     'facebook',
                'key':          self.settings['facebook_api_key'],
{'fraction_non_alphanumeric': 0.112484799351439, 'fraction_numerical': 0.002837454398054317, 'mean_word_length': 2.922893481717011, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4570106', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1385, 'n_words': 303}