bones73k/lib/bones73k_web/controllers/user_registration_controller.ex

31 lines
843 B
Elixir
Raw Normal View History

2021-02-24 07:49:39 -05:00
defmodule Bones73kWeb.UserRegistrationController do
use Bones73kWeb, :controller
2021-02-24 07:49:39 -05:00
alias Bones73k.Accounts
alias Bones73k.Accounts.User
alias Bones73kWeb.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} ->
%Bamboo.Email{} =
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