meta/lib/recycledcloud_web/controllers/user_registration_controller.ex
Timothée Floure 56d2d5bccf
Run mix phx.gen.auth Accounts User users
Uses phx_gen_auth as a scaffold to build our own logic.
2020-12-15 14:24:14 +01:00

30 lines
861 B
Elixir

defmodule RecycledCloudWeb.UserRegistrationController do
use RecycledCloudWeb, :controller
alias RecycledCloud.Accounts
alias RecycledCloud.Accounts.User
alias RecycledCloudWeb.UserAuth
def new(conn, _params) do
changeset = Accounts.change_user_registration(%User{})
render(conn, "new.html", changeset: changeset)
end
def create(conn, %{"user" => user_params}) do
case Accounts.register_user(user_params) do
{:ok, user} ->
{:ok, _} =
Accounts.deliver_user_confirmation_instructions(
user,
&Routes.user_confirmation_url(conn, :confirm, &1)
)
conn
|> put_flash(:info, "User created successfully.")
|> UserAuth.log_in_user(user)
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
end