Admin Panel - User management

This commit is contained in:
2024-04-26 19:52:35 +02:00
parent 34ecf58097
commit 30773d7af4
3 changed files with 52 additions and 1 deletions
@@ -0,0 +1,47 @@
<?php
namespace App\Controller\Admin;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\User;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\Field;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
class UserCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return User::class;
}
public function configureFields(string $pageName): iterable
{
yield TextField::new ('username');
yield TextField::new ('username')->onlyWhenUpdating()->setDisabled(true);
$availableRoles = ['User' => 'ROLE_USER', 'Admin' => 'ROLE_ADMIN', 'Test' => 'ROLE_TEST'];
yield ChoiceField::new ('roles')
->setChoices($availableRoles)
->allowMultipleChoices(true);
yield FormField::addPanel('Change password')->setIcon('fa fa-key');
yield Field::new ('password', 'New password')->onlyWhenCreating()->setRequired(true)
->setFormType(RepeatedType::class)
->setFormTypeOptions([
'type' => PasswordType::class,
'first_options' => ['label' => 'New password'],
'second_options' => ['label' => 'Repeat password'],
'error_bubbling' => true,
'invalid_message' => 'The password fields do not match.',
]);
//TODO: Allow password change on Update.
}
}