2020-07-28 22:56:26 +02:00
|
|
|
defmodule PhilomenaWeb.Registration.PasswordController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
|
|
|
alias Philomena.Users
|
|
|
|
alias PhilomenaWeb.UserAuth
|
|
|
|
|
|
|
|
plug PhilomenaWeb.CompromisedPasswordCheckPlug when action in [:update]
|
|
|
|
|
|
|
|
def update(conn, %{"current_password" => password, "user" => user_params}) do
|
|
|
|
user = conn.assigns.current_user
|
|
|
|
|
|
|
|
case Users.update_user_password(user, password, user_params) do
|
|
|
|
{:ok, user} ->
|
|
|
|
conn
|
|
|
|
|> put_flash(:info, "Password updated successfully.")
|
2024-06-06 22:28:35 +02:00
|
|
|
|> put_session(:user_return_to, ~p"/registrations/edit")
|
2020-07-28 22:56:26 +02:00
|
|
|
|> UserAuth.log_in_user(user)
|
|
|
|
|
|
|
|
{:error, _changeset} ->
|
|
|
|
conn
|
|
|
|
|> put_flash(:error, "Failed to update password.")
|
2024-06-06 22:28:35 +02:00
|
|
|
|> redirect(to: ~p"/registrations/edit")
|
2020-07-28 22:56:26 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|