fix-admin and crudify user admin

This commit is contained in:
2021-09-22 18:18:49 +02:00
parent f93c2d8d32
commit b5c2dd7bd2
21 changed files with 247 additions and 185 deletions

View File

@@ -23,32 +23,22 @@ namespace Chill\MainBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
/**
* Class AdminController
*
* @package Chill\MainBundle\Controller
* @author julien.fastre@champs-libres.coop
* @author marc@champs-libres.coop
*/
use Symfony\Component\Routing\Annotation\Route;
class AdminController extends AbstractController
{
public function indexAction($menu = 'admin',
$header_title = 'views.Main.admin.index.header_title',
$page_title = 'views.Main.admin.index.page_title') {
return $this->render('@ChillMain/Admin/layout.html.twig');
/**
* @Route("/{_locale}/admin", name="chill_main_admin_central")
*/
public function indexAction()
{
return $this->render('@ChillMain/Admin/index.html.twig');
}
public function indexPermissionsAction()
{
return $this->render('@ChillMain/Admin/layout_permissions.html.twig');
}
public function configurationWarningsAction()
{
$alertManager = $this->get('chill_main.configuration_alert_manager');
}
}

View File

@@ -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.
*