Add auth templates

This commit is contained in:
Mirai Kumiko 2025-06-21 10:23:49 +02:00
parent 4a79081fc8
commit f88c247a5c
Signed by: miraikumiko
GPG key ID: 3F178B1B5E0CB278
3 changed files with 49 additions and 3 deletions

View file

@ -0,0 +1,9 @@
<main class="flex min-h-screen items-center justify-center">
<form class="flex flex-col gap-2" action="/auth/sign_in" method="post">
<label for="email">E-mail address *</label>
<input id="email" name="email" type="email" maxlength="50" required />
<label for="password">Password *</label>
<input id="password" name="password" type="password" minlength="8" maxlength="50" required />
<button class="text-white bg-black py-2 border" type="submit">Log in</button>
</form>
</main>

View file

@ -0,0 +1,12 @@
<main class="flex min-h-screen items-center justify-center">
<form class="flex flex-col gap-2" action="/auth" method="post">
<label for="username">Username *</label>
<input id="username" name="username" type="text" maxlength="30" required />
<label for="email">E-mail address *</label>
<input id="email" name="email" type="email" maxlength="50" required />
<label for="password">Password *</label>
<input id="password" name="password" type="password" minlength="8" maxlength="50" required />
<input id="password_confirm" name="password_confirm" type="password" minlength="8" maxlength="50" placeholder="Confirm password" />
<button class="text-white bg-black py-2 border" type="submit">Sign up</button>
</form>
</main>

View file

@ -1,12 +1,37 @@
defmodule NullaWeb.AuthController do defmodule NullaWeb.AuthController do
use NullaWeb, :controller use NullaWeb, :controller
alias Nulla.Models.User
def sign_in do def sign_in_view(conn, _params) do
render(conn, :sign_in, layout: false)
end end
def sign_out do def sign_in(conn, _params) do
conn
|> redirect(to: "/")
end end
def sign_up do def sign_out(conn, _params) do
conn
|> configure_session(drop: true)
|> put_flash(:info, "You have been logged out.")
|> redirect(to: "/")
end
def sign_up_view(conn, _params) do
render(conn, :sign_up, layout: false)
end
def sign_up(conn, params) do
case User.create_user(params) do
{:ok, user} ->
conn
|> put_session(:user_id, user.id)
|> put_flash(:info, "You're registred!")
|> redirect(to: "/")
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "sign_up.html", changeset: changeset)
end
end end
end end