philomena/lib/philomena_web/controllers/admin/user/activation_controller.ex

33 lines
892 B
Elixir
Raw Normal View History

2019-12-17 06:44:24 +01:00
defmodule PhilomenaWeb.Admin.User.ActivationController do
use PhilomenaWeb, :controller
alias Philomena.Users.User
alias Philomena.Users
plug :verify_authorized
plug :load_resource, model: User, id_name: "user_id", id_field: "slug", persisted: true
def create(conn, _params) do
{:ok, user} = Users.reactivate_user(conn.assigns.user)
conn
|> put_flash(:info, "User was reactivated.")
|> redirect(to: ~p"/profiles/#{user}")
2019-12-17 06:44:24 +01:00
end
def delete(conn, _params) do
{:ok, user} = Users.deactivate_user(conn.assigns.current_user, conn.assigns.user)
conn
|> put_flash(:info, "User was deactivated.")
|> redirect(to: ~p"/profiles/#{user}")
2019-12-17 06:44:24 +01:00
end
defp verify_authorized(conn, _opts) do
case Canada.Can.can?(conn.assigns.current_user, :index, User) do
2020-01-11 05:20:19 +01:00
true -> conn
2019-12-17 06:44:24 +01:00
_false -> PhilomenaWeb.NotAuthorizedPlug.call(conn)
end
end
end