Exemplo n.º 1
0
async def login() -> Any:
    if await current_user.is_authenticated:
        return redirect(url_for("ux.index"))

    if request.method == "GET":
        fluent = get_injector(["login"])
        return await render_template("login.html", **{"_": fluent.format_value})
    else:
        resources = [
            "login"
        ]
        fluent = get_injector(resources)

        form = await request.form

        username = form.get("username")
        password = form.get("password")
        if username is None or password is None:
            await flash(fluent._("form-missing-data"))
            return redirect(url_for("ux.login"))

        async with app.acquire_db() as con:
            await con.execute("""
                SELECT
                    id,
                    password_hash
                FROM
                    users
                WHERE LOWER(username) = ?;
            """, username.lower())
            user_data = await con.fetchone()

        if not user_data:
            await flash(fluent._("invalid-credentials"))
            return redirect(url_for("ux.login"))

        try:
            hasher.verify(user_data["password_hash"], password)
        except VerifyMismatchError:
            await flash(fluent._("invalid-credentials"))
            return redirect(url_for("ux.login"))

        if hasher.check_needs_rehash(user_data["password_hash"]):
            async with app.acquire_db() as con:
                await con.execute("""
                    UPDATE
                        users
                    SET
                        password_hash=?
                    WHERE username=?;
                """, hasher.hash(password), username)

        remember = form.get("remember", False)

        login_user(User(user_data["id"]), remember=remember)

        return redirect(url_for("ux.index"))
Exemplo n.º 2
0
async def nyaa_search() -> str:
    ctx = {}

    resources = [
        "base"
    ]

    fluent = get_injector(resources)
    ctx["_"] = fluent.format_value

    async with app.acquire_db() as con:
        await con.execute("""
            SELECT
                id,
                title
            FROM
                shows
            ORDER BY title;
        """)
        shows = await con.fetchall()
        ctx["shows"] = [dict(s) for s in shows]

    ctx["seen_titles"] = list(app.seen_titles)

    return await render_template("nyaa_search.html", **ctx)
Exemplo n.º 3
0
async def config() -> str:
    ctx = {}

    resources = [
        "base"
    ]

    fluent = get_injector(resources)
    ctx["_"] = fluent.format_value

    return await render_template("config.html", **ctx)
Exemplo n.º 4
0
async def webhooks() -> str:
    ctx = {}

    resources = [
        "base",
        "webhooks"
    ]

    fluent = get_injector(resources)
    ctx["_"] = fluent.format_value

    all_bases = await WebhookBase.all(app)
    ctx["bases"] = [b.to_dict() for b in all_bases]

    return await render_template("webhooks.html", **ctx)
Exemplo n.º 5
0
async def logs() -> Union[str, Response]:
    if request.args.get("dl"):
        return await send_file(
            "tsundoku.log",
            as_attachment=True
        )

    ctx = {}

    resources = [
        "base"
    ]

    fluent = get_injector(resources)
    ctx["_"] = fluent.format_value

    return await render_template("logs.html", **ctx)
Exemplo n.º 6
0
async def index() -> str:
    ctx = {}

    resources = [
        "base",
        "errors",
        "index"
    ]

    fluent = get_injector(resources)
    ctx["_"] = fluent.format_value

    if not len(app.rss_parsers):
        await flash(fluent._("no-rss-parsers"))
    elif not len(app.seen_titles):
        await flash(fluent._("no-shows-found"))

    return await render_template("index.html", **ctx)
Exemplo n.º 7
0
if sys.version_info < (3, 7):
    print("Please update Python to use version 3.7+")
    exit(1)

import argparse
import asyncio
import getpass
from pathlib import Path

from fluent.runtime import FluentBundle, FluentResource

from tsundoku import app, database
from tsundoku.fluent import get_injector

fluent = get_injector(["cmdline"])


def compare_locales(from_lang: str, to_lang: str) -> None:
    """
    Compares two whole languages in the Tsundoku
    translation files. Will point out any missing
    files or keys that do not exist in `to_lang` from
    `from_lang`.

    Parameters
    ----------
    from_lang: str
        Origin locale.
    to_lang: str
        Destination locale.