defmodule ComfycampWeb.UserEditorController do use ComfycampWeb, :controller alias Comfycamp.Accounts def index(conn, _params) do users = Accounts.list_users() conn |> put_layout(html: :admin) |> render(:index, page_title: "Пользователи", users: users, stylesheets: ["/assets/admin.css"] ) end def show(conn, %{"id" => id}) do user = Accounts.get_user!(id) conn |> put_layout(html: :admin) |> render(:show, page_title: user.email, user: user) end 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 end