mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
fix-admin and crudify user admin
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Chill\MainBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\CRUD\Controller\AbstractCRUDController;
|
||||
use Chill\MainBundle\CRUD\Controller\CRUDController;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -11,6 +13,9 @@ use Chill\MainBundle\Form\UserType;
|
||||
use Chill\MainBundle\Entity\GroupCenter;
|
||||
use Chill\MainBundle\Form\Type\ComposedGroupCenterType;
|
||||
use Chill\MainBundle\Form\UserPasswordType;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
|
||||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
|
||||
@@ -19,69 +24,61 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
*
|
||||
* @package Chill\MainBundle\Controller
|
||||
*/
|
||||
class UserController extends AbstractController
|
||||
class UserController extends CRUDController
|
||||
{
|
||||
|
||||
const FORM_GROUP_CENTER_COMPOSED = 'composed_groupcenter';
|
||||
|
||||
|
||||
/**
|
||||
* @var \Psr\Log\LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
|
||||
/**
|
||||
* @var ValidatorInterface
|
||||
*/
|
||||
private $validator;
|
||||
|
||||
|
||||
private UserPasswordEncoderInterface $passwordEncoder;
|
||||
|
||||
/**
|
||||
* UserController constructor.
|
||||
*
|
||||
* @param LoggerInterface $logger
|
||||
* @param ValidatorInterface $validator
|
||||
*/
|
||||
public function __construct(LoggerInterface $logger, ValidatorInterface $validator)
|
||||
{
|
||||
public function __construct(
|
||||
LoggerInterface $logger,
|
||||
ValidatorInterface $validator,
|
||||
UserPasswordEncoderInterface $passwordEncoder
|
||||
) {
|
||||
$this->logger = $logger;
|
||||
$this->validator = $validator;
|
||||
$this->passwordEncoder = $passwordEncoder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all User entities.
|
||||
*
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$entities = $em->createQuery('SELECT u FROM ChillMainBundle:User u '
|
||||
. 'ORDER BY u.username')
|
||||
->getResult();
|
||||
|
||||
return $this->render('@ChillMain/User/index.html.twig', array(
|
||||
'entities' => $entities,
|
||||
));
|
||||
}
|
||||
/**
|
||||
* Creates a new User entity.
|
||||
*
|
||||
*/
|
||||
public function createAction(Request $request)
|
||||
public function new(Request $request): Response
|
||||
{
|
||||
$user = new User();
|
||||
$form = $this->createCreateForm($user);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$user->setPassword($this->get('security.password_encoder')
|
||||
$user->setPassword($this->passwordEncoder
|
||||
->encodePassword($user, $form['plainPassword']->getData()));
|
||||
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->generateUrl('admin_user_show', array('id' => $user->getId())));
|
||||
} elseif ($form->isSubmitted() && !$form->isValid()){
|
||||
|
||||
}
|
||||
|
||||
return $this->render('@ChillMain/User/new.html.twig', array(
|
||||
@@ -110,21 +107,6 @@ class UserController extends AbstractController
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a form to create a new User entity.
|
||||
*
|
||||
*/
|
||||
public function newAction()
|
||||
{
|
||||
$user = new User();
|
||||
$form = $this->createCreateForm($user);
|
||||
|
||||
return $this->render('@ChillMain/User/new.html.twig', array(
|
||||
'entity' => $user,
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and displays a User entity.
|
||||
*
|
||||
|
Reference in New Issue
Block a user