# Written by retoor@molodetz.nl

# This code defines an asynchronous view for handling a login form. It checks if the form is valid, sets session variables for a logged-in user, and provides a redirect URL if successful.

# Imports: LoginForm from snek.form.login and BaseFormView from snek.system.view

# MIT License


from snek.form.login import LoginForm
from snek.system.view import BaseFormView


class LoginFormView(BaseFormView):
    form = LoginForm

    async def submit(self, form):
        if await form.is_valid():
            self.session["logged_in"] = True
            self.session["username"] = form.username.value
            self.session["uid"] = form.uid.value
            return {"redirect_url": "/web.html"}
        return {"is_valid": False}
