2020-07-28 22:56:26 +02:00
|
|
|
defmodule PhilomenaWeb.RegistrationController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
|
|
|
alias Philomena.Users
|
|
|
|
alias Philomena.Users.User
|
|
|
|
|
2020-09-12 19:43:16 +02:00
|
|
|
plug PhilomenaWeb.CaptchaPlug when action in [:new, :create]
|
|
|
|
plug PhilomenaWeb.CheckCaptchaPlug when action in [:create]
|
2020-07-28 22:56:26 +02:00
|
|
|
plug PhilomenaWeb.CompromisedPasswordCheckPlug when action in [:create]
|
|
|
|
plug :assign_email_and_password_changesets when action in [:edit]
|
|
|
|
|
|
|
|
def new(conn, _params) do
|
|
|
|
changeset = Users.change_user_registration(%User{})
|
|
|
|
render(conn, "new.html", changeset: changeset)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create(conn, %{"user" => user_params}) do
|
|
|
|
case Users.register_user(user_params) do
|
|
|
|
{:ok, user} ->
|
|
|
|
{:ok, _} =
|
|
|
|
Users.deliver_user_confirmation_instructions(
|
|
|
|
user,
|
2024-04-29 02:55:27 +02:00
|
|
|
&url(~p"/confirmations/#{&1}")
|
2020-07-28 22:56:26 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> put_flash(
|
|
|
|
:info,
|
|
|
|
"Account created successfully. Check your email for confirmation instructions."
|
|
|
|
)
|
|
|
|
|> redirect(to: "/")
|
|
|
|
|
|
|
|
{:error, %Ecto.Changeset{} = changeset} ->
|
|
|
|
render(conn, "new.html", changeset: changeset)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit(conn, _params) do
|
2021-02-26 06:47:45 +01:00
|
|
|
render(conn, "edit.html", title: "Account Settings")
|
2020-07-28 22:56:26 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
defp assign_email_and_password_changesets(conn, _opts) do
|
|
|
|
user = conn.assigns.current_user
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> assign(:email_changeset, Users.change_user_email(user))
|
|
|
|
|> assign(:password_changeset, Users.change_user_password(user))
|
|
|
|
end
|
|
|
|
end
|