comfycamp/lib/comfycamp_web/controllers/user_editor_controller.ex

57 lines
1.4 KiB
Elixir
Raw Normal View History

2024-08-26 21:05:11 +05:00
defmodule ComfycampWeb.UserEditorController do
use ComfycampWeb, :controller
alias Comfycamp.Accounts
def index(conn, _params) do
users = Accounts.list_users()
conn
|> put_layout(html: :admin)
2024-08-26 22:10:51 +05:00
|> render(:index,
page_title: "Пользователи",
users: users,
stylesheets: ["/assets/admin.css"]
)
2024-08-26 21:05:11 +05:00
end
def show(conn, %{"id" => id}) do
user = Accounts.get_user!(id)
conn
|> put_layout(html: :admin)
2024-08-31 17:02:54 +05:00
|> render(:show, page_title: user.email, user: user)
2024-08-26 21:05:11 +05:00
end
2024-08-28 00:58:20 +05:00
def approve(conn, %{"id" => id}) do
user = Accounts.get_user!(id)
case Accounts.update_approval_status(user, true) do
{:ok, user} ->
conn
|> put_flash(:info, "Пользователь одобрен")
|> redirect(to: ~p"/admin/users/#{user}")
{:error, _changeset} ->
conn
|> put_flash(:error, "Ошибка при одобрении")
|> redirect(to: ~p"/admin/users/#{user}")
end
end
def disapprove(conn, %{"id" => id}) do
user = Accounts.get_user!(id)
case Accounts.update_approval_status(user, false) do
{:ok, user} ->
conn
|> put_flash(:info, "Одобрение отменено")
|> redirect(to: ~p"/admin/users/#{user}")
{:error, _changeset} ->
conn
|> put_flash(:error, "Ошибка при отмене одобрения")
|> redirect(to: ~p"/admin/users/#{user}")
end
end
2024-08-26 21:05:11 +05:00
end