shift73k/lib/real_estate_web/controllers/user_registration_controller.ex
2020-09-12 21:07:02 -03:00

30 lines
846 B
Elixir

defmodule RealEstateWeb.UserRegistrationController do
use RealEstateWeb, :controller
alias RealEstate.Accounts
alias RealEstate.Accounts.User
alias RealEstateWeb.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