<commit_before>import paste
import webob
import time
import logging
from fedora.client import ProxyClient, FedoraServiceError, AuthError
import urllib2
import tg
import uuid

from tg import flash

from paste.httpexceptions import HTTPUnauthorized

from repoze.who.middleware import PluggableAuthenticationMiddleware

from repoze.who.plugins.form import RedirectingFormPlugin
from repoze.who.classifiers import default_request_classifier
from repoze.who.classifiers import default_challenge_decider

from repoze.what.adapters import BaseSourceAdapter

from beaker.cache import Cache

from repoze.who.interfaces import IChallenger, IIdentifier

from Cookie import SimpleCookie

from moksha.middleware.csrf import CSRFMetadataProvider
from moksha.api.errorcodes import login_err
import beaker

import pkg_resources

import os
import sys
import pylons

log = logging.getLogger(__name__)

FAS_CACHE_TIMEOUT=20 #in seconds

fasurl = tg.config.get('fedoracommunity.fas.baseurl')
fas_cache = Cache('fas_repozewho_cache', type="memory")

def fas_make_who_middleware(app, log_stream):
    faswho = FASWhoPlugin(fasurl)

    form = RedirectingFormPlugin('/login', '/login_handler', '/logout',
                                 rememberer_name='fasident',
                                 reason_param='ec')
    form.classifications = { IIdentifier:['browser'],
                             IChallenger:['browser'] } # only for browser

    identifiers = [('form', form),('fasident', faswho)]
    authenticators = [('fasauth', faswho)]
    challengers = [('form',form)]
    mdproviders = [('fasmd', faswho), ('csrfmd', CSRFMetadataProvider())]
<commit_msg>Add a custom login_handler to our CSRFMetadataProvider.<commit_after>import paste
import webob
import time
import logging
from fedora.client import ProxyClient, FedoraServiceError, AuthError
import urllib2
import tg
import uuid

from tg import flash

from paste.httpexceptions import HTTPUnauthorized

from repoze.who.middleware import PluggableAuthenticationMiddleware

from repoze.who.plugins.form import RedirectingFormPlugin
from repoze.who.classifiers import default_request_classifier
from repoze.who.classifiers import default_challenge_decider

from repoze.what.adapters import BaseSourceAdapter

from beaker.cache import Cache

from repoze.who.interfaces import IChallenger, IIdentifier

from Cookie import SimpleCookie

from moksha.middleware.csrf import CSRFMetadataProvider
from moksha.api.errorcodes import login_err
import beaker

import pkg_resources

import os
import sys
import pylons

log = logging.getLogger(__name__)

FAS_CACHE_TIMEOUT=20 #in seconds

fasurl = tg.config.get('fedoracommunity.fas.baseurl')
fas_cache = Cache('fas_repozewho_cache', type="memory")

def fas_make_who_middleware(app, log_stream):
    faswho = FASWhoPlugin(fasurl)
    csrf_mdprovider = CSRFMetadataProvider(
            login_handler=tg.config.get('moksha.csrf.login_handler', '/login_handler'))

    form = RedirectingFormPlugin('/login', '/login_handler', '/logout',
                                 rememberer_name='fasident',
                                 reason_param='ec')
    form.classifications = { IIdentifier:['browser'],
                             IChallenger:['browser'] } # only for browser

    identifiers = [('form', form),('fasident', faswho)]
    authenticators = [('fasauth', faswho)]
    challengers = [('form',form)]
    mdproviders = [('fasmd', faswho), ('csrfmd', csrf_mdprovider)]

{'fraction_non_alphanumeric': 0.08601216333622937, 'fraction_numerical': 0.0017376194613379669, 'mean_word_length': 4.413793103448276, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1549202', 'n_tokens_mistral': 1032, 'n_tokens_neox': 1044, 'n_words': 250}