Hash :
c5b35fe0
Author :
Thomas de Grivel
Date :
2022-06-19T11:38:30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
defmodule KmxgitWeb.UserRegistrationController do
use KmxgitWeb, :controller
alias Kmxgit.Repo
alias Kmxgit.SlugManager
alias Kmxgit.UserManager
alias Kmxgit.UserManager.User
alias KmxgitWeb.UserAuth
def new(conn, _params) do
changeset = UserManager.change_user_registration(%User{})
render(conn, "new.html", changeset: changeset)
end
def create(conn, %{"user" => user_params}) do
case Repo.transaction(fn ->
case UserManager.register_user(user_params) do
{:ok, user} ->
case SlugManager.create_slug(user) do
{:ok, _slug} ->
{:ok, _} =
UserManager.deliver_user_confirmation_instructions(
user,
&Routes.user_confirmation_url(conn, :edit, &1))
user
{:error, changeset} ->
Repo.rollback(changeset)
end
{:error, changeset} ->
Repo.rollback(changeset)
end
end) do
{:ok, user} ->
conn
|> put_flash(:info, "User created successfully.")
|> UserAuth.log_in_user(user)
{:error, changeset} ->
IO.inspect(changeset)
render(conn, "new.html", changeset: changeset)
end
end
end