<commit_before>"""Login and logout handlers."""

from aiohttp import web
from aiohttp_session import get_session
from urllib import parse
from .validators import validate
from .utils import cas_url, APP_KEY, SESSION_KEY
from .log import log


async def login_handler(request):
    """Handles login requests.

    We get the ticket ID from the user, the rest comes from info stored on
    the session.
    """
    ticket = request.GET.get('ticket')

    session = await get_session(request)
    redir = session[SESSION_KEY].get('redir')
    login_route = request.app[APP_KEY]['LOGIN_ROUTE']
    root_url = request.app[APP_KEY]['ROOT_URL']
    on_success = request.app[APP_KEY]['ON_SUCCESS']
    version = request.app[APP_KEY]['VERSION']

    # If we're missing neccessary data, return 400 Bad Request
    if not (request.scheme and request.host):
        log.warn("Invalid scheme ({}) or host ({})"
                 .format(request.scheme, request.host))
        return web.HTTPBadRequest()

    # Build the service URL.
    service = parse.urlunsplit(
            (request.scheme, request.host,
             login_route, None, None)<commit_msg>Error on accessing session key (#2)<commit_after>"""Login and logout handlers."""

from aiohttp import web
from aiohttp_session import get_session
from urllib import parse
from .validators import validate
from .utils import cas_url, APP_KEY, SESSION_KEY
from .log import log


async def login_handler(request):
    """Handles login requests.

    We get the ticket ID from the user, the rest comes from info stored on
    the session.
    """
    ticket = request.GET.get('ticket')

    session = await get_session(request)
    redir = session.get(SESSION_KEY, {}).get('redir', None)
    login_route = request.app[APP_KEY]['LOGIN_ROUTE']
    root_url = request.app[APP_KEY]['ROOT_URL']
    on_success = request.app[APP_KEY]['ON_SUCCESS']
    version = request.app[APP_KEY]['VERSION']

    # If we're missing neccessary data, return 400 Bad Request
    if not (request.scheme and request.host):
        log.warn("Invalid scheme ({}) or host ({})"
                 .format(request.scheme, request.host))
        return web.HTTPBadRequest()

    # Build the service URL.
    service = parse.urlunsplit(
            (request.scheme, request.host,
             login_route, None, None)
{'fraction_non_alphanumeric': 0.10671256454388985, 'fraction_numerical': 0.0030120481927710845, 'mean_word_length': 3.3621013133208257, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6851118', 'n_tokens_mistral': 698, 'n_tokens_neox': 671, 'n_words': 208}