This commit is contained in:
Gnieark 2020-01-02 21:18:47 +01:00
parent 115c7c256e
commit 4e4ae007c4
2 changed files with 65 additions and 2 deletions

View File

@ -8,11 +8,14 @@ use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType; use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use App\Entity\User; use App\Entity\User;
use App\Service\Menus;
use Doctrine\ORM\EntityManagerInterface;
class SecurityController extends AbstractController class SecurityController extends AbstractController
@ -92,10 +95,34 @@ class SecurityController extends AbstractController
} }
} }
private function getformCreateUser()
{
return $this->createFormBuilder()
->add('email', EmailType::class,[])
->add('password', PasswordType::class, [])
->add('display_name', TextType::class,[])
->add('roles', ChoiceType::class, [
'choices' => [
'USER' => false,
'RESOURCE_MANAGER' => 'RESOURCE_MANAGER',
'SUPER ADMIN' => 'SUPER_ADMIN',
],
'multiple' => false
])
->add('save', SubmitType::class,[])
->getForm();
}
public function showUserManagePage() public function showUserManagePage()
{ {
$users = $this->getDoctrine()
->getRepository(User::class)
->findAll();
$menus = new Menus();
return $this->render('security/listUsers.html.twig', [
"menus" => $menus->getMenus( $this->getUser() ),
"users" => $users,
"formCreateUser" => $this->getformCreateUser()->createView()
]);
} }
} }

View File

@ -0,0 +1,36 @@
{% extends 'base.html.twig' %}
{% block title %}Manage users{% endblock %}
{% block header %}<h1>Manage users</h1>{% endblock %}
{% block nav %}{% include 'menus.html.twig' %}{% endblock %}
{% block content %}
<article id="FormCreateUser">
<h2>Create a new user</h2>
{{ form(formCreateUser) }}
</article>
<article>
<h2>Users list</h2>
<table>
<thead>
<tr>
<th>Displayed Name</th>
<th>Login (email)</th>
<th>Roles</th>
<th>Active</th>
</tr>
</thead>
<tbody>
{% for u in users %}
<tr>
<td>{{ u.displayName }} </td>
<td>{{ u.email }}</td>
<td>{{ u.roles|join(',') }}</td>
<td>{{ u.active? 'Yes':'No' }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</article>
{% endblock %}