from fastapi import Request
from src.entity.{{ entity_file_name }} import {{ entity_class_name }}

from framefox.core.routing.decorator.route import Route
from framefox.core.orm.entity_manager import EntityManager
from framefox.core.security.password.password_hasher import PasswordHasher
from framefox.core.controller.abstract_controller import AbstractController

class RegisterController(AbstractController):

    def __init__(self):
        self.entity_manager = EntityManager()

    @Route("/register", "security.register", methods=["GET", "POST"])
    async def register(self, request: Request):
        provider = {{ entity_class_name }}()

        if request.method == "POST":
            form = await request.form()
            provider = {{ entity_class_name }}()
            provider.email = form.get("email")
            provider.password = PasswordHasher().hash(form.get("password"))

            self.entity_manager.persist(provider)
            self.entity_manager.commit()
            return self.redirect("/login")

        return self.render("security/register.html")
{% raw %}{% endraw %}