<commit_before>__all__ = [
    "get_apps"
    "do_deploy"
]

from flask import render_template, request, redirect, url_for, abort
from flask import session, current_app
import requests


def get_login():
    return render_template('login.html')


def do_login():
    # POST to the API/login with the username and password for validation
    # expect back an access token to be stored in a session for use in future API calls
    if "fakeauth" in session:
        return redirect(url_for('get_apps'))
    r = requests.post("{}login/".format(current_app.config["API_URI"]), request.form)
    session["username"] = request.form["username"]
    session["fakeauth"] = r.content
    return redirect(url_for('get_apps'))

def do_logout():
    session.clear()
    return redirect(url_for('get_apps'))


def get_apps():
    fake_auth_header = session.get("fakeauth", None)
    headers = {"fakeauth": fake_auth_header} if fake_auth_header else {}
    try:
        r = requests.get("{}apps/".format(current_app.config["API_URI"]), headers=headers)
        r.raise_for_status()
        apps = r.json()
        apps = [
            dict(a.items() + {"stages": {s["name"]: s for s in a["stages"]}}.items())
            for a in apps
        ]
    except requests.HTTPError as e:
        if e.response.status_code:
            return redirect(url_for('get_login'))
    return render_template(
        'index.html',
        apps=apps, username=session["username"])

def login():
    if request.method == "GET":
        return render_template('login.html')
    elif request.method == "POST":
        return redirect(url_for('login'))


def do_deploy():
    app = request.form["app"]
    version = request.form["version"]
    stage = request.form["stage"]
    apps[app]["stage"][stage]["version"] = version
    return redirect(url_for('get_apps'))
<commit_msg>login page fixes, clear sesion, etc<commit_after>__all__ = [
    "get_apps"
    "do_deploy"
]

from flask import render_template, request, redirect, url_for, abort
from flask import session, current_app
import requests


def get_login(error=None):
    return render_template('login.html', error=error)


def do_login():
    # POST to the API/login with the username and password for validation
    # expect back an access token to be stored in a session for use in future API calls
    if "fakeauth" in session:
        return redirect(url_for('get_apps'))
    session.clear()
    r = requests.post("{}login/".format(current_app.config["API_URI"]), request.form)
    try:
        r.raise_for_status()
    except requests.HTTPError as e:
        if e.response.status_code == 401:
            return redirect(url_for('get_login', error="bad username or password"))
    session["username"] = request.form["username"]
    session["fakeauth"] = r.content
    return redirect(url_for('get_apps'))

def do_logout():
    session.clear()
    return redirect(url_for('get_apps'))


def get_apps():
    fake_auth_header = session.get("fakeauth", None)
    headers = {"fakeauth": fake_auth_header} if fake_auth_header else {}
    try:
        r = requests.get("{}apps/".format(current_app.config["API_URI"]), headers=headers)
        r.raise_for_status()
        apps = r.json()
        apps = [
            dict(a.items() + {"stages": {s["name"]: s for s in a["stages"]}}.items())
            for a in apps
        ]
    except requests.HTTPError as e:
        if e.response.status_code == 401:
            return redirect(url_for('get_login'))
    return render_template(
        'index.html',
        apps=apps, username=session["username"])


def do_deploy():
    app = request.form["app"]
    version = request.form["version"]
    stage = request.form["stage"]
    apps[app]["stage"][stage]["version"] = version
    return redirect(url_for('get_apps'))

{'fraction_non_alphanumeric': 0.13542766631467792, 'fraction_numerical': 0.0015839493136219642, 'mean_word_length': 3.330285714285714, 'pattern_counts': {'":': 6, '<': 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': '2697532', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1146, 'n_words': 291}