mirror of
https://github.com/sigmasternchen/MyTube
synced 2025-03-15 21:08:55 +00:00
basic user list for admins
This commit is contained in:
parent
417e60b296
commit
afec700b7e
8 changed files with 136 additions and 13 deletions
10
public/css/admin.css
Normal file
10
public/css/admin.css
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
.customChip {
|
||||||
|
display: inline-block;
|
||||||
|
background-color: darkred;
|
||||||
|
font-size: 1vw;
|
||||||
|
padding: 0 5% 0 5%;
|
||||||
|
height: 1.5vw;
|
||||||
|
border-radius: 0.75vw;
|
||||||
|
font-weight: bold;
|
||||||
|
color: lightgrey;
|
||||||
|
}
|
39
src/Controller/UserController.php
Normal file
39
src/Controller/UserController.php
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Service\UserService;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
|
class UserController extends AbstractController
|
||||||
|
{
|
||||||
|
|
||||||
|
private $userService;
|
||||||
|
|
||||||
|
public function __construct(UserService $userService)
|
||||||
|
{
|
||||||
|
$this->userService = $userService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/admin/users", name="app_user_list")
|
||||||
|
*/
|
||||||
|
public function userList(): Response
|
||||||
|
{
|
||||||
|
if (!$this->isGranted("ROLE_ADMIN")) {
|
||||||
|
// not logged in
|
||||||
|
throw new AccessDeniedHttpException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$users = $this->userService->getUsers();
|
||||||
|
|
||||||
|
return $this->render("user/users.html.twig", [
|
||||||
|
"users" => $users
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,6 +24,7 @@ class UserFixtures extends Fixture
|
||||||
$admin = new User();
|
$admin = new User();
|
||||||
$admin->setName("admin");
|
$admin->setName("admin");
|
||||||
$admin->setPassword($this->passwordEncoder->encodePassword($admin, "password"));
|
$admin->setPassword($this->passwordEncoder->encodePassword($admin, "password"));
|
||||||
|
$admin->setRoles(["ROLE_ADMIN"]);
|
||||||
$manager->persist($admin);
|
$manager->persist($admin);
|
||||||
|
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
|
|
|
@ -156,4 +156,16 @@ class User implements UserInterface
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getReadableRoles(): array
|
||||||
|
{
|
||||||
|
return array_map(function ($role) {
|
||||||
|
$i = strrpos($role, "_");
|
||||||
|
if ($i) {
|
||||||
|
// $i === false it's probably a custom name
|
||||||
|
return substr($role, $i + 1);
|
||||||
|
}
|
||||||
|
return $role;
|
||||||
|
}, $this->getRoles());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,4 +31,9 @@ class UserService
|
||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUsers(): array
|
||||||
|
{
|
||||||
|
return $this->userRepository->findAll();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -33,18 +33,29 @@
|
||||||
|
|
||||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||||
<li class="nav-item">
|
{% if is_granted('ROLE_USER') %}
|
||||||
<a class="nav-link {% if route_name == "app_dashboard" %} active {% endif %}"
|
<li class="nav-item">
|
||||||
aria-current="page" href="{{ path("app_dashboard") }}">Dashboard</a>
|
<a class="nav-link {% if route_name == "app_dashboard" %} active {% endif %}"
|
||||||
</li>
|
aria-current="page" href="{{ path("app_dashboard") }}">Dashboard</a>
|
||||||
<li class="nav-item">
|
</li>
|
||||||
<a class="nav-link {% if route_name == "app_upload" %} active {% endif %}" aria-current="page"
|
<li class="nav-item">
|
||||||
href="{{ path("app_upload") }}">Upload</a>
|
<a class="nav-link {% if route_name == "app_upload" %} active {% endif %}"
|
||||||
</li>
|
aria-current="page"
|
||||||
<li class="nav-item">
|
href="{{ path("app_upload") }}">Upload</a>
|
||||||
<a class="nav-link {% if route_name == "app_links" %} active {% endif %}" aria-current="page"
|
</li>
|
||||||
href="{{ path("app_links") }}">Links</a>
|
<li class="nav-item">
|
||||||
</li>
|
<a class="nav-link {% if route_name == "app_links" %} active {% endif %}"
|
||||||
|
aria-current="page"
|
||||||
|
href="{{ path("app_links") }}">Links</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% if is_granted('ROLE_ADMIN') %}
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link {% if route_name == "app_user_list" %} active {% endif %}"
|
||||||
|
aria-current="page"
|
||||||
|
href="{{ path("app_user_list") }}">Users</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
<form class="d-flex input-group w-auto">
|
<form class="d-flex input-group w-auto">
|
||||||
<input
|
<input
|
||||||
|
|
|
@ -79,7 +79,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if link.viewableFor %}
|
{% if link.viewableFor %}
|
||||||
{{ link.viewableForLeft != null ? link.viewableForLeft : "-" }} / {{ link.viewableFor }}
|
{{ link.viewableForLeft != null ? link.viewableForLeft : "-" }} / {{ link.viewableFor }} h
|
||||||
{% else %}
|
{% else %}
|
||||||
-
|
-
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
45
templates/user/users.html.twig
Normal file
45
templates/user/users.html.twig
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Links{% endblock %}
|
||||||
|
{% block stylesheets %}
|
||||||
|
<link rel="stylesheet" href="{{ asset("css/admin.css") }}">
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<div class="links bg-light shadow-5">
|
||||||
|
<table class="table">
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
<input type="checkbox">
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Username
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Email
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Roles
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
{% for user in users %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<input type="checkbox">
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ user.name }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
[not yet implemented]
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% for role in user.getReadableRoles() %}
|
||||||
|
<div class="customChip">{{ role }}</div>
|
||||||
|
{% endfor %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Loading…
Reference in a new issue