2021-08-11 06:57:23 +00:00
|
|
|
defmodule KetbinWeb.UserRegistrationController do
|
|
|
|
use KetbinWeb, :controller
|
|
|
|
|
|
|
|
alias Ketbin.Accounts
|
|
|
|
alias Ketbin.Accounts.User
|
|
|
|
alias KetbinWeb.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)
|
2021-08-14 21:49:03 +00:00
|
|
|
|> redirect(to: "/users/confirm")
|
2021-08-11 06:57:23 +00:00
|
|
|
|
|
|
|
{:error, %Ecto.Changeset{} = changeset} ->
|
|
|
|
render(conn, "new.html", changeset: changeset)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|