Add users

This commit is contained in:
Mirai Kumiko 2025-06-02 17:30:35 +02:00
parent 956f2625fd
commit 162aa095d3
Signed by: miraikumiko
GPG key ID: 3F178B1B5E0CB278
15 changed files with 489 additions and 99 deletions

View file

@ -1,10 +1,41 @@
defmodule NullaWeb.UserHTML do
@moduledoc """
This module contains pages rendered by UserController.
See the `user_html` directory for all templates available.
"""
use NullaWeb, :html
embed_templates "user_html/*"
@doc """
Renders a user form.
"""
attr :changeset, Ecto.Changeset, required: true
attr :action, :string, required: true
def user_form(assigns)
def format_birthdate(date) do
formatted = Date.to_string(date) |> String.replace("-", "/")
age = Timex.diff(Timex.today(), date, :years)
"#{formatted} (#{age} years old)"
end
def format_registration_date(date) do
now = Timex.now()
formatted = Date.to_string(date) |> String.replace("-", "/")
diff = Timex.diff(now, date, :days)
relative =
cond do
diff == 0 -> "today"
diff == 1 -> "1 day ago"
diff < 30 -> "#{diff} days ago"
diff < 365 ->
months = Timex.diff(now, date, :months)
if months == 1, do: "1 month ago", else: "#{months} months ago"
true ->
years = Timex.diff(now, date, :years)
if years == 1, do: "1 year ago", else: "#{years} years ago"
end
"#{formatted} (#{relative})"
end
end