mirror of
https://github.com/resources-manager/resources-manager-webui.git
synced 2024-11-21 15:39:20 +01:00
commit
4c37fbad58
|
@ -21,4 +21,4 @@ register:
|
||||||
users:
|
users:
|
||||||
path: /users
|
path: /users
|
||||||
controller: App\Controller\SecurityController::showUserManagePage
|
controller: App\Controller\SecurityController::showUserManagePage
|
||||||
methods: GET
|
methods: GET|POST
|
|
@ -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,61 @@ class SecurityController extends AbstractController
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
private function getformCreateUser()
|
||||||
public function showUserManagePage()
|
|
||||||
{
|
{
|
||||||
|
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(Request $request, UserPasswordEncoderInterface $passwordEncoder)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
$formCreateUser = $this->getformCreateUser();
|
||||||
|
$formCreateUser->handleRequest($request);
|
||||||
|
|
||||||
|
if ($formCreateUser->isSubmitted() && $formCreateUser->isValid()) {
|
||||||
|
$userValues = $formCreateUser->getData();
|
||||||
|
|
||||||
|
$user = new User();
|
||||||
|
$user ->setEmail($userValues ["email"])
|
||||||
|
->setPassword( $passwordEncoder->encodePassword($user,$userValues ["password"]) )
|
||||||
|
->setDisplayName( $userValues ["display_name"] )
|
||||||
|
->setActive(true)
|
||||||
|
->setRoles(array( $userValues["roles"] ));
|
||||||
|
|
||||||
|
$entityManager = $this->getDoctrine()->getManager();
|
||||||
|
$entityManager->persist($user);
|
||||||
|
$entityManager->flush();
|
||||||
|
|
||||||
|
//empty the form
|
||||||
|
$formCreateUser = $this->getformCreateUser();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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" => $formCreateUser->createView()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
37
templates/security/listUsers.html.twig
Normal file
37
templates/security/listUsers.html.twig
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
{% 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) }}
|
||||||
|
<p>{{ form_errors(formCreateUser) }}</p>
|
||||||
|
</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 %}
|
Loading…
Reference in New Issue
Block a user