2020-09-06 04:53:55 +02:00
|
|
|
defmodule PhilomenaWeb.Admin.User.UnlockController 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.unlock_user(conn.assigns.user)
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> put_flash(:info, "User was unlocked.")
|
2024-04-29 02:55:27 +02:00
|
|
|
|> redirect(to: ~p"/profiles/#{user}")
|
2020-09-06 04:53:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
defp verify_authorized(conn, _opts) do
|
|
|
|
case Canada.Can.can?(conn.assigns.current_user, :index, User) do
|
|
|
|
true -> conn
|
|
|
|
_false -> PhilomenaWeb.NotAuthorizedPlug.call(conn)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|