feat: show user list in admin panel
This commit is contained in:
parent
818a7e4a31
commit
3f042d1d99
5 changed files with 73 additions and 13 deletions
|
@ -26,6 +26,13 @@ defmodule Comfycamp.Accounts do
|
||||||
Repo.get_by(User, email: email)
|
Repo.get_by(User, email: email)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Get all users.
|
||||||
|
"""
|
||||||
|
def list_users() do
|
||||||
|
Repo.all(User)
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Gets a user by email and password.
|
Gets a user by email and password.
|
||||||
|
|
||||||
|
|
|
@ -7,18 +7,6 @@ defmodule ComfycampWeb.AdminPageController do
|
||||||
|> render(:home, page_title: "Админка")
|
|> render(:home, page_title: "Админка")
|
||||||
end
|
end
|
||||||
|
|
||||||
def posts(conn, _params) do
|
|
||||||
conn
|
|
||||||
|> put_layout(html: :admin)
|
|
||||||
|> render(:home, page_title: "Админка")
|
|
||||||
end
|
|
||||||
|
|
||||||
def users(conn, _params) do
|
|
||||||
conn
|
|
||||||
|> put_layout(html: :admin)
|
|
||||||
|> render(:home, page_title: "Админка")
|
|
||||||
end
|
|
||||||
|
|
||||||
def services(conn, _params) do
|
def services(conn, _params) do
|
||||||
conn
|
conn
|
||||||
|> put_layout(html: :admin)
|
|> put_layout(html: :admin)
|
||||||
|
|
20
lib/comfycamp_web/controllers/user_editor_controller.ex
Normal file
20
lib/comfycamp_web/controllers/user_editor_controller.ex
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
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)
|
||||||
|
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
|
||||||
|
end
|
45
lib/comfycamp_web/controllers/user_editor_html.ex
Normal file
45
lib/comfycamp_web/controllers/user_editor_html.ex
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
defmodule ComfycampWeb.UserEditorHTML do
|
||||||
|
use ComfycampWeb, :html
|
||||||
|
|
||||||
|
def index(assigns) do
|
||||||
|
~H"""
|
||||||
|
<div>
|
||||||
|
<h3>Пользователи</h3>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Email</th>
|
||||||
|
<th>Одобрен?</th>
|
||||||
|
<th>Админ?</th>
|
||||||
|
</tr>
|
||||||
|
<%= for user <- @users do %>
|
||||||
|
<tr>
|
||||||
|
<td><%= user.id %></td>
|
||||||
|
<td>
|
||||||
|
<.link href={~p"/admin/users/#{user}"}><%= user.email %></.link>
|
||||||
|
</td>
|
||||||
|
<td><%= user.is_approved %></td>
|
||||||
|
<td><%= user.is_admin %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
|
||||||
|
def show(assigns) do
|
||||||
|
~H"""
|
||||||
|
<div>
|
||||||
|
<h3><%= @user.email %></h3>
|
||||||
|
<.back navigate={~p"/admin/users"}>Назад</.back>
|
||||||
|
<p>
|
||||||
|
<%= if @user.info do %>
|
||||||
|
<%= @user.info %>
|
||||||
|
<% else %>
|
||||||
|
Описания нет.
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
end
|
|
@ -92,8 +92,8 @@ defmodule ComfycampWeb.Router do
|
||||||
pipe_through [:browser, :require_authenticated_user, :ensure_admin]
|
pipe_through [:browser, :require_authenticated_user, :ensure_admin]
|
||||||
|
|
||||||
get "/", AdminPageController, :home
|
get "/", AdminPageController, :home
|
||||||
get "/users", AdminPageController, :users
|
|
||||||
get "/services", AdminPageController, :services
|
get "/services", AdminPageController, :services
|
||||||
resources "/notes", NotesEditorController
|
resources "/notes", NotesEditorController
|
||||||
|
resources "/users", UserEditorController, only: [:index, :show]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue