diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 44c7bc8..875fc4f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -7,7 +7,7 @@ jobs: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: '8.1' - name: Get composer cache directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" diff --git a/.gitignore b/.gitignore index d2dc1a9..0189468 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,8 @@ /nbproject/ .DS_Store Thumbs.db -/.php_cs.cache +/.php-cs-fixer.cache +/.phpunit.result.cache Tests/Fixtures/TestProject/bower.json Tests/Fixtures/TestProject/.bowerrc Tests/Fixtures/TestProject/web/bundles diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 85% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index 2284acb..3819498 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -1,6 +1,6 @@ setRiskyAllowed(true) ->setRules([ '@PSR2' => true, @@ -11,7 +11,6 @@ 'combine_consecutive_unsets' => true, 'concat_space' => ['spacing' => 'one'], 'declare_strict_types' => true, - 'dir_constant' => true, 'ereg_to_preg' => true, 'heredoc_to_nowdoc' => true, 'include' => true, @@ -19,7 +18,7 @@ 'magic_constant_casing' => true, 'modernize_types_casting' => true, 'native_function_casing' => true, - 'native_function_invocation' => true, + 'native_function_invocation' => ['strict' => false], 'new_with_braces' => true, 'no_alias_functions' => true, 'no_blank_lines_after_class_opening' => true, @@ -28,17 +27,16 @@ 'no_empty_comment' => true, 'no_empty_phpdoc' => true, 'no_empty_statement' => true, - 'no_extra_consecutive_blank_lines' => true, + 'no_extra_blank_lines' => true, 'no_leading_import_slash' => true, 'no_leading_namespace_whitespace' => true, 'no_mixed_echo_print' => true, 'no_multiline_whitespace_around_double_arrow' => true, - 'no_multiline_whitespace_before_semicolons' => true, + 'multiline_whitespace_before_semicolons' => false, 'no_php4_constructor' => true, 'no_singleline_whitespace_before_semicolons' => true, 'no_spaces_around_offset' => true, - 'no_trailing_comma_in_list_call' => true, - 'no_trailing_comma_in_singleline_array' => true, + 'no_trailing_comma_in_singleline' => true, 'no_unneeded_control_parentheses' => true, 'no_unneeded_curly_braces' => true, 'no_unused_imports' => true, @@ -64,7 +62,7 @@ 'phpdoc_to_comment' => true, 'phpdoc_types' => true, 'phpdoc_var_without_name' => true, - 'psr4' => true, + 'psr_autoloading' => true, 'self_accessor' => true, 'semicolon_after_instruction' => true, 'short_scalar_cast' => true, @@ -74,18 +72,16 @@ 'strict_comparison' => true, 'strict_param' => true, 'ternary_operator_spaces' => true, - 'trailing_comma_in_multiline_array' => true, + 'trailing_comma_in_multiline' => true, 'trim_array_spaces' => true, 'unary_operator_spaces' => true, - 'void_return' => true, 'whitespace_after_comma_in_array' => true, ]) ->setFinder( PhpCsFixer\Finder::create() ->exclude([ 'vendor', - 'Tests/Fixtures/TestProject/var', + 'tests/Fixtures/TestProject/var', ]) ->in(__DIR__) - ) -; + ); diff --git a/Command/CommandUtil.php b/Command/CommandUtil.php index 70aef90..cbefb07 100644 --- a/Command/CommandUtil.php +++ b/Command/CommandUtil.php @@ -6,8 +6,6 @@ class CommandUtil /** * Ensure that PHPExcel is available. * - * @param OutputInterface $output - * * @throws \RuntimeException */ public static function checkPhpExcel(OutputInterface $output): void diff --git a/Command/RoleDocumentCreateCommand.php b/Command/RoleDocumentCreateCommand.php index b480451..54cc381 100644 --- a/Command/RoleDocumentCreateCommand.php +++ b/Command/RoleDocumentCreateCommand.php @@ -77,17 +77,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int } /** - * Get default roles. - * - * @param string|null $userName - * @param string|null $groupName - * @param bool|null $defaultState - * * @throws \LogicException - * - * @return array|bool */ - private function getDefaultRoles($userName, $groupName, $defaultState) + private function getDefaultRoles(?string $userName, ?string $groupName, ?bool $defaultState): array|bool { if ($userName xor $groupName) { if (null !== $defaultState) { @@ -105,15 +97,9 @@ private function getDefaultRoles($userName, $groupName, $defaultState) } /** - * Get user roles. - * - * @param string $userName - * * @throws \RuntimeException - * - * @return array */ - private function getUserRoles($userName) + private function getUserRoles(string $userName): array { $user = $this->userManager->findUserBy(['username' => $userName]); if (!$user) { @@ -124,15 +110,9 @@ private function getUserRoles($userName) } /** - * Get group roles. - * - * @param string $groupName - * * @throws \RuntimeException - * - * @return array */ - private function getGroupRoles($groupName) + private function getGroupRoles(string $groupName): array { $group = $this->groupManager->findGroupBy(['name' => $groupName]); if (!$group) { diff --git a/Command/RoleDocumentImportCommand.php b/Command/RoleDocumentImportCommand.php index 16d633c..03324c0 100644 --- a/Command/RoleDocumentImportCommand.php +++ b/Command/RoleDocumentImportCommand.php @@ -10,23 +10,13 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -/** - * Role document import command. - * - * @author Pavel Batecko - */ class RoleDocumentImportCommand extends Command { - private UserManager $userManager; - private GroupManager $groupManager; - public function __construct( - UserManager $userManager, - GroupManager $groupManager + private UserManager $userManager, + private GroupManager $groupManager ) { parent::__construct(); - $this->userManager = $userManager; - $this->groupManager = $groupManager; } /** @@ -90,14 +80,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int } /** - * Apply roles to user. - * - * @param string $userName - * @param array $roles - * * @throws \RuntimeException */ - private function applyRolesToUser($userName, array $roles): void + private function applyRolesToUser(string $userName, array $roles): void { $user = $this->userManager->findUserBy(['username' => $userName]); if (!$user) { @@ -109,14 +94,9 @@ private function applyRolesToUser($userName, array $roles): void } /** - * Apply roles to group. - * - * @param string $groupName - * @param array $roles - * * @throws \RuntimeException */ - private function applyRolesToGroup($groupName, array $roles): void + private function applyRolesToGroup(string $groupName, array $roles): void { $group = $this->groupManager->findGroupBy(['name' => $groupName]); if (!$group) { diff --git a/Controller/ChangePasswordController.php b/Controller/ChangePasswordController.php index 31b73cc..66ba894 100644 --- a/Controller/ChangePasswordController.php +++ b/Controller/ChangePasswordController.php @@ -10,7 +10,7 @@ use Symfony\Component\Routing\Annotation\Route; /** - * @Route("/profile", name="fos_user_") + * @Route("/profile", name="user_") */ class ChangePasswordController extends AbstractController { @@ -24,12 +24,12 @@ public function changePasswordAction(Request $request, UserManager $userManager) return $this->createAccessDeniedException(); } - $form = $this->createForm(ChangePasswordType::class, $user); + $form = $this->createForm(ChangePasswordType::class, $user, ['data_class' => $user::class]); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $userManager->updateUser($user); - return new RedirectResponse($this->generateUrl('fos_user_profile_show')); + return new RedirectResponse($this->generateUrl('user_profile_show')); } return $this->render('@ImaticUser/ChangePassword/change_password.html.twig', [ diff --git a/Controller/ProfileController.php b/Controller/ProfileController.php index 9019b5b..78be1a9 100644 --- a/Controller/ProfileController.php +++ b/Controller/ProfileController.php @@ -9,14 +9,17 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; -/** - * @Route("/profile", name="fos_user_profile_") - */ +#[Route( + path: '/profile', + name: 'user_profile_', +)] class ProfileController extends AbstractController { - /** - * @Route("/", methods={"GET"}, name="show") - */ + #[Route( + path: '/', + methods: ['GET'], + name: 'show', + )] public function showAction() { $user = $this->getUser(); @@ -29,22 +32,25 @@ public function showAction() ]); } - /** - * @Route("/edit", methods={"GET", "POST"}, name="edit") - */ - public function editAction(Request $request, UserManager $userManager) + #[Route( + path: '/edit', + methods: ['GET', 'POST'], + name: 'edit', + )] + public function editAction(Request $request, UserManager $userManager): \Symfony\Component\HttpFoundation\Response|RedirectResponse { $user = $this->getUser(); if (!$user instanceof UserInterface) { $this->createAccessDeniedException(); } - $form = $this->createForm(ProfileType::class, $user); + \assert($user instanceof UserInterface); + $form = $this->createForm(ProfileType::class, $user, ['data_class' => $user::class]); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $userManager->updateUser($user); - return new RedirectResponse($this->generateUrl('fos_user_profile_show')); + return new RedirectResponse($this->generateUrl('user_profile_show')); } return $this->render('@ImaticUser/Profile/edit.html.twig', [ diff --git a/Controller/ResettingController.php b/Controller/ResettingController.php index 0e7ec40..cb92c79 100644 --- a/Controller/ResettingController.php +++ b/Controller/ResettingController.php @@ -10,7 +10,7 @@ use Symfony\Component\Routing\Annotation\Route; /** - * @Route("/resetting", name="fos_user_resetting_") + * @Route("/resetting", name="user_resetting_") */ class ResettingController extends AbstractController { @@ -41,7 +41,7 @@ public function sendEmailAction(Request $request, UserManager $userManager, Mail if (null !== $user && !$user->isPasswordRequestNonExpired($this->retryTtl)) { if (!$user->isAccountNonLocked()) { - return new RedirectResponse($this->generateUrl('fos_user_resetting_request')); + return new RedirectResponse($this->generateUrl('user_resetting_request')); } if (null === $user->getConfirmationToken()) { @@ -53,7 +53,7 @@ public function sendEmailAction(Request $request, UserManager $userManager, Mail $userManager->updateUser($user); } - return new RedirectResponse($this->generateUrl('fos_user_resetting_check_email', ['username' => $username])); + return new RedirectResponse($this->generateUrl('user_resetting_check_email', ['username' => $username])); } /** @@ -64,7 +64,7 @@ public function checkEmailAction(Request $request) $username = $request->query->get('username'); if (empty($username)) { - return new RedirectResponse($this->generateUrl('fos_user_resetting_request')); + return new RedirectResponse($this->generateUrl('user_resetting_request')); } return $this->render('@ImaticUser/Resetting/check_email.html.twig', [ @@ -79,11 +79,11 @@ public function resetAction(Request $request, $token, UserManager $userManager) { $user = $userManager->findUserByConfirmationToken($token); if (null === $user) { - return new RedirectResponse($this->generateUrl('fos_user_security_login')); + return new RedirectResponse($this->generateUrl('user_security_login')); } if (!$user->isPasswordRequestNonExpired($this->tokenTtl)) { - return new RedirectResponse($this->generateUrl('fos_user_resetting_request')); + return new RedirectResponse($this->generateUrl('user_resetting_request')); } $form = $this->createForm(ResettingFormType::class, $user); @@ -94,7 +94,7 @@ public function resetAction(Request $request, $token, UserManager $userManager) $user->setEnabled(true); $userManager->updateUser($user); - return new RedirectResponse($this->generateUrl('fos_user_profile_show')); + return new RedirectResponse($this->generateUrl('user_profile_show')); } return $this->render('@ImaticUser/Resetting/reset.html.twig', [ diff --git a/Controller/RoleController.php b/Controller/RoleController.php index 5877669..0db138e 100644 --- a/Controller/RoleController.php +++ b/Controller/RoleController.php @@ -15,6 +15,7 @@ /** * @Route("/imatic/user/role") + * * @Config\Security("has_role('ROLE_IMATIC_USER_USER_ADMIN')") */ class RoleController extends AbstractController @@ -23,17 +24,19 @@ class RoleController extends AbstractController const TYPE_GROUP = 'group'; - /** - * @param $type - * @param int $id - * - * @Route( - * path="/display/{type}/{id}", - * requirements={"type"="user|group", "id"="\d+"} - * ) - * @Config\Template("@ImaticUser/Role/display.html.twig") - */ - public function displayAction($type, $id, RoleProviderInterface $roleProvider) + #[ + Route( + path: '/display/{type}/{id}', + requirements: [ + 'type' => 'user|group', + 'id' => '\d+', + ] + ), + Config\Template( + '@ImaticUser/Role/display.html.twig' + ) + ] + public function displayAction(mixed $type, int $id, RoleProviderInterface $roleProvider) { $roleMap = []; @@ -49,20 +52,16 @@ public function displayAction($type, $id, RoleProviderInterface $roleProvider) } /** - * @param Request $request - * @param string $type - * @param int $id - * @param string $role - * - * @return Response - * * @throws AccessDeniedException - * @Route( - * path="/switch/{type}/{id}/{role}", - * requirements={"type"="user|group", "id"="\d+"} - * ) */ - public function switchAction(Request $request, $type, $id, $role) + #[Route( + path: '/switch/{type}/{id}/{role}', + requirements: [ + 'type' => 'user|group', + 'id' => '\d+', + ] + )] + public function switchAction(Request $request, string $type, int $id, string $role): Response { if ( !$this->isGranted(\sprintf('ROLE_IMATIC_USER_ADMIN_%s_ROLE', \strtoupper($type))) @@ -84,23 +83,12 @@ public function switchAction(Request $request, $type, $id, $role) return new Response(); } - /** - * @param string $type - * - * @return UserManager|GroupManager - */ - private function getManager($type) + private function getManager(string $type): UserManager|GroupManager { return $this->get(\sprintf('imatic_user.manager.%s', $type)); } - /** - * @param string $type - * @param int $id - * - * @return UserInterface|GroupInterface - */ - private function findObject($type, $id) + private function findObject(string $type, int $id): UserInterface|GroupInterface { $manager = $this->getManager($type); $object = $type === static::TYPE_USER @@ -114,10 +102,7 @@ private function findObject($type, $id) return $object; } - /** - * @param UserInterface|GroupInterface $object - */ - private function updateObject($object): void + private function updateObject(UserInterface|GroupInterface $object): void { if ($object instanceof UserInterface) { $this->getManager(static::TYPE_USER)->updateUser($object); @@ -126,7 +111,7 @@ private function updateObject($object): void } } - public static function getSubscribedServices() + public static function getSubscribedServices(): array { return \array_merge( [ diff --git a/Controller/SecurityController.php b/Controller/SecurityController.php index 7d6d92d..73ef35b 100644 --- a/Controller/SecurityController.php +++ b/Controller/SecurityController.php @@ -9,7 +9,7 @@ use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; /** - * @Route("", name="fos_user_security_") + * @Route("", name="user_security_") */ class SecurityController extends AbstractController { @@ -36,7 +36,7 @@ public function loginAction(Request $request, CsrfTokenManagerInterface $tokenMa $error = null; } - $lastUsername = (null === $session) ? '' : $session->get($lastUsernameKey); + $lastUsername = ($session->isStarted() === false) ? '' : $session->get($lastUsernameKey); $csrfToken = $tokenManager ? $tokenManager->getToken('authenticate')->getValue() diff --git a/Controller/UserController.php b/Controller/UserController.php index 1a5f04d..a7e8870 100644 --- a/Controller/UserController.php +++ b/Controller/UserController.php @@ -13,6 +13,7 @@ /** * @Route("/user") + * * @Config\Security("has_role('ROLE_IMATIC_USER_USER_ADMIN')") */ class UserController implements ContainerAwareInterface @@ -34,6 +35,7 @@ public function listAction() /** * @Route("/{id}", requirements={"id"="\d+"}, methods={"GET"}, name="imatic_user_user_show") + * * @Config\Template() */ public function showAction($id) @@ -60,7 +62,6 @@ public function editAction($id) /** * @Route("/create", methods={"GET", "POST"}, name="imatic_user_user_create") - * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function createAction() { diff --git a/Data/Handler/User/UserCreateHandler.php b/Data/Handler/User/UserCreateHandler.php index 465829c..1511f9a 100644 --- a/Data/Handler/User/UserCreateHandler.php +++ b/Data/Handler/User/UserCreateHandler.php @@ -2,7 +2,6 @@ namespace Imatic\Bundle\UserBundle\Data\Handler\User; use Imatic\Bundle\DataBundle\Data\Command\CommandInterface; -use Imatic\Bundle\DataBundle\Data\Command\CommandResultInterface; use Imatic\Bundle\DataBundle\Data\Command\HandlerInterface; use Imatic\Bundle\UserBundle\Manager\UserManager; @@ -15,12 +14,7 @@ public function __construct(UserManager $userManager) $this->userManager = $userManager; } - /** - * @param CommandInterface $command - * - * @return CommandResultInterface|bool|void - */ - public function handle(CommandInterface $command) + public function handle(CommandInterface $command): void { $user = $command->getParameter('data'); diff --git a/Data/Handler/User/UserDeleteHandler.php b/Data/Handler/User/UserDeleteHandler.php index 0dc517b..a1281db 100644 --- a/Data/Handler/User/UserDeleteHandler.php +++ b/Data/Handler/User/UserDeleteHandler.php @@ -2,7 +2,6 @@ namespace Imatic\Bundle\UserBundle\Data\Handler\User; use Imatic\Bundle\DataBundle\Data\Command\CommandInterface; -use Imatic\Bundle\DataBundle\Data\Command\CommandResultInterface; use Imatic\Bundle\DataBundle\Data\Command\HandlerInterface; use Imatic\Bundle\UserBundle\Manager\UserManager; use Imatic\Bundle\UserBundle\Model\UserInterface; @@ -16,12 +15,7 @@ public function __construct(UserManager $userManager) $this->userManager = $userManager; } - /** - * @param CommandInterface $command - * - * @return CommandResultInterface|bool|void - */ - public function handle(CommandInterface $command) + public function handle(CommandInterface $command): void { $user = $command->getParameter('user'); if (!($user instanceof UserInterface)) { diff --git a/Data/Handler/User/UserEditHandler.php b/Data/Handler/User/UserEditHandler.php index 7d85351..7015fae 100644 --- a/Data/Handler/User/UserEditHandler.php +++ b/Data/Handler/User/UserEditHandler.php @@ -2,7 +2,6 @@ namespace Imatic\Bundle\UserBundle\Data\Handler\User; use Imatic\Bundle\DataBundle\Data\Command\CommandInterface; -use Imatic\Bundle\DataBundle\Data\Command\CommandResultInterface; use Imatic\Bundle\DataBundle\Data\Command\HandlerInterface; use Imatic\Bundle\UserBundle\Manager\UserManager; @@ -15,12 +14,7 @@ public function __construct(UserManager $userManager) $this->userManager = $userManager; } - /** - * @param CommandInterface $command - * - * @return CommandResultInterface|bool|void - */ - public function handle(CommandInterface $command) + public function handle(CommandInterface $command): void { $user = $command->getParameter('data'); diff --git a/Data/Query/User/UserListQuery.php b/Data/Query/User/UserListQuery.php index 6adfd75..0ed1728 100644 --- a/Data/Query/User/UserListQuery.php +++ b/Data/Query/User/UserListQuery.php @@ -9,21 +9,11 @@ class UserListQuery implements QueryObjectInterface, SortableQueryObjectInterface, FilterableQueryObjectInterface { - /** - * @var string - */ - private $class; - - public function __construct($class) - { - $this->class = $class; + public function __construct( + private string $class + ) { } - /** - * @param EntityManager $em - * - * @return QueryBuilder - */ public function build(EntityManager $em): QueryBuilder { return (new QueryBuilder($em)) @@ -31,10 +21,7 @@ public function build(EntityManager $em): QueryBuilder ->from($this->class, 'u'); } - /** - * @return array - */ - public function getSorterMap() + public function getSorterMap(): array { return [ 'username' => 'u.username', @@ -44,15 +31,12 @@ public function getSorterMap() ]; } - /** - * @return array - */ - public function getDefaultSort() + public function getDefaultSort(): array { return ['username' => 'ASC']; } - public function getFilterMap() + public function getFilterMap(): array { return [ 'username' => 'u.username', diff --git a/Data/Query/User/UserQuery.php b/Data/Query/User/UserQuery.php index 75da6a2..1f80c93 100644 --- a/Data/Query/User/UserQuery.php +++ b/Data/Query/User/UserQuery.php @@ -8,27 +8,12 @@ class UserQuery implements QueryObjectInterface, SingleResultQueryObjectInterface { - /** - * @var string - */ - private $class; - - /** - * @var int - */ - private $id; - - public function __construct($id, $class) - { - $this->class = $class; - $this->id = $id; + public function __construct( + private int $id, + private string $class + ) { } - /** - * @param EntityManager $em - * - * @return QueryBuilder - */ public function build(EntityManager $em): QueryBuilder { return (new QueryBuilder($em)) diff --git a/DataFixtures/ORM/LoadDefaultUsers.php b/DataFixtures/ORM/LoadDefaultUsers.php index 1a48cfe..bce8a64 100644 --- a/DataFixtures/ORM/LoadDefaultUsers.php +++ b/DataFixtures/ORM/LoadDefaultUsers.php @@ -40,17 +40,7 @@ public function loadDefaultUsersAndGroups(ObjectManager $manager): void $manager->flush(); } - /** - * @param string $username - * @param string $password - * @param string $email - * @param array $groups - * @param array $roles - * @param bool $enabled - * - * @return User - */ - protected function createUser($username, $password, $email, array $groups = [], array $roles = [], $enabled = true) + protected function createUser(string $username, string $password, string $email, array $groups = [], array $roles = [], bool $enabled = true): User { $user = new User(); $user->setUsername($username); @@ -71,13 +61,7 @@ protected function createUser($username, $password, $email, array $groups = [], return $user; } - /** - * @param string $name - * @param array $roles - * - * @return Group - */ - protected function createGroup($name, array $roles = []) + protected function createGroup(string $name, array $roles = []): Group { $group = new Group(); $group->setName($name); diff --git a/DependencyInjection/Compiler/SecurityPass.php b/DependencyInjection/Compiler/SecurityPass.php index 1943d59..2236a6f 100644 --- a/DependencyInjection/Compiler/SecurityPass.php +++ b/DependencyInjection/Compiler/SecurityPass.php @@ -9,24 +9,18 @@ class SecurityPass implements CompilerPassInterface { - /** - * @param ContainerBuilder $container - */ public function process(ContainerBuilder $container): void { $this->processRoleProviders($container); $this->processTranslationStrategies($container); } - /** - * @param ContainerBuilder $container - */ protected function processRoleProviders(ContainerBuilder $container): void { $config = $container->getExtensionConfig('imatic_user'); $processor = new Processor(); $configuration = $processor->processConfiguration(new Configuration(), $config); - $definition = $container->getDefinition('imatic_user.security.role.provider.chain_role_provider'); + $definition = $container->getDefinition(\Imatic\Bundle\UserBundle\Security\Role\Provider\ChainRoleProvider::class); $roleProviders = $configuration['security']['role']; foreach ($container->findTaggedServiceIds('imatic_user.role_provider') as $id => $tagAttributes) { @@ -49,12 +43,9 @@ protected function processRoleProviders(ContainerBuilder $container): void } } - /** - * @param ContainerBuilder $container - */ protected function processTranslationStrategies(ContainerBuilder $container): void { - $definition = $container->getDefinition('imatic_user.security.role.translation.role_translator'); + $definition = $container->getDefinition(\Imatic\Bundle\UserBundle\Security\Role\Translation\RoleTranslator::class); foreach (\array_keys($container->findTaggedServiceIds('imatic_user.role_translation_strategy')) as $id) { $definition->addMethodCall('addStrategy', [new Reference($id)]); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php old mode 100755 new mode 100644 index a9f6120..ffd67ff --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -12,10 +12,7 @@ */ class Configuration implements ConfigurationInterface { - /** - * @return TreeBuilder - */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $builder = new TreeBuilder('imatic_user'); $rootNode = $builder->getRootNode(); @@ -47,10 +44,7 @@ public function addEmailsSection(ArrayNodeDefinition $node): void ->end(); } - /** - * @param ArrayNodeDefinition $node - */ - private function addEntitiesSection($node): void + private function addEntitiesSection(ArrayNodeDefinition $node): void { $node ->children() @@ -79,10 +73,7 @@ private function addEntitiesSection($node): void ->end(); } - /** - * @param ArrayNodeDefinition $node - */ - private function addAdminSection($node): void + private function addAdminSection(ArrayNodeDefinition $node): void { $node ->addDefaultsIfNotSet() @@ -106,9 +97,6 @@ private function addAdminSection($node): void ->end(); } - /** - * @param ArrayNodeDefinition $node - */ private function addSecuritySection(ArrayNodeDefinition $node): void { $node diff --git a/DependencyInjection/ImaticUserExtension.php b/DependencyInjection/ImaticUserExtension.php old mode 100755 new mode 100644 index d965471..1e0f5b0 --- a/DependencyInjection/ImaticUserExtension.php +++ b/DependencyInjection/ImaticUserExtension.php @@ -24,7 +24,8 @@ public function load(array $configs, ContainerBuilder $container): void $container->setParameter('imatic_user.admin.form.user', $config['admin']['form']['user']); - $container->setParameter('imatic.user.email.resseting_from', [$config['email']['address'] => $config['email']['sender_name']]); + $container->setParameter('imatic.user.email.resseting_from_address', $config['email']['address']); + $container->setParameter('imatic.user.email.resseting_from_sender_name', $config['email']['sender_name']); $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yml'); diff --git a/Entity/Group.php b/Entity/Group.php index fee6ac9..c6f95fc 100644 --- a/Entity/Group.php +++ b/Entity/Group.php @@ -5,95 +5,66 @@ use Imatic\Bundle\UserBundle\Model\GroupInterface; use Symfony\Component\Validator\Constraints as Assert; -/** - * Group. - * - * @author Viliam Husár - * - * @ORM\MappedSuperclass() - */ +#[ORM\MappedSuperclass()] class Group implements GroupInterface { - /** - * @var int - * - * @ORM\Id() - * @ORM\Column(type="integer") - * @ORM\GeneratedValue(strategy="AUTO") - */ - protected $id; - - /** - * @var string - * - * @ORM\Column(type="string", unique=true) - * @Assert\NotBlank(groups={"Registration"}) - * @Assert\Length(min=2, max=255, groups={"Registration"}) - */ - protected $name; - - /** - * @var array - * - * @ORM\Column(type="array") - */ - protected $roles; - - /** - * Constructor. - * - * @param string $name - * @param array $roles - */ - public function __construct($name = null, $roles = []) + #[ + ORM\Column( + type: 'integer', + ), + ORM\Id(), + ORM\GeneratedValue( + strategy: 'AUTO', + ), + ] + protected int $id; + + #[ + ORM\Column( + type: 'string', + unique: true, + ), + Assert\NotBlank( + groups: ['Registration'] + ), + Assert\Length( + min: 2, + groups: ['Registration'], + max: 255, + ), + ] + protected string $name; + + #[ORM\Column( + type: 'array', + )] + protected array $roles; + + public function __construct(string $name = null, array $roles = []) { $this ->setName($name) ->setRoles($roles); } - /** - * Returns ID. - * - * @return int - */ - public function getId() + public function getId(): int { return $this->id; } - /** - * Sets name. - * - * @param string $name - * - * @return $this - */ - public function setName($name) + public function setName(string $name): static { $this->name = $name; return $this; } - /** - * Returns name. - * - * @return string - */ - public function getName() + public function getName(): string { return $this->name; } - /** - * Sets roles. - * - * @param array $roles - * - * @return $this - */ - public function setRoles(array $roles) + public function setRoles(array $roles): static { $this->roles = []; @@ -104,14 +75,7 @@ public function setRoles(array $roles) return $this; } - /** - * Adds role. - * - * @param string $role - * - * @return $this - */ - public function addRole($role) + public function addRole(string $role): static { $role = (string) $role; $role = \strtoupper($role); @@ -123,14 +87,7 @@ public function addRole($role) return $this; } - /** - * Removes role. - * - * @param string $role - * - * @return $this - */ - public function removeRole($role) + public function removeRole(string $role): static { $role = (string) $role; @@ -142,31 +99,19 @@ public function removeRole($role) return $this; } - /** - * Returns roles. - * - * @return array - */ - public function getRoles() + public function getRoles(): array { return $this->roles; } - /** - * Returns true if user has role. - * - * @param string $role - * - * @return bool - */ - public function hasRole($role) + public function hasRole(string $role): bool { $role = (string) $role; return \in_array(\strtoupper($role), $this->roles, true); } - public function __toString() + public function __toString(): string { return (string) $this->name; } diff --git a/Entity/User.php b/Entity/User.php index eb2ea99..88cf969 100644 --- a/Entity/User.php +++ b/Entity/User.php @@ -15,164 +15,185 @@ * * @author Viliam Husár * - * @ORM\MappedSuperclass() * @DoctrineAssert\UniqueEntity(fields="usernameCanonical", errorPath="username", groups={"Registration", "Profile"}) * @DoctrineAssert\UniqueEntity(fields="emailCanonical", errorPath="email", groups={"Registration", "Profile"}) */ -class User implements UserInterface +#[ORM\MappedSuperclass()] +class User implements UserInterface, \Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface { - /** - * @var int - * - * @ORM\Id() - * @ORM\Column(type="integer") - * @ORM\GeneratedValue(strategy="AUTO") - */ - protected $id; - - /** - * @var string - * - * @ORM\Column(type="string", length=255) - * @Assert\NotBlank(groups={"Registration", "Profile"}) - * @Assert\Length(min=2, max=255, groups={"Registration", "Profile"}) - */ - protected $username; - - /** - * @var string - * - * @ORM\Column(type="string", length=255, unique=true) - */ - protected $usernameCanonical; - - /** - * @var string - * - * @ORM\Column(type="string", length=255) - * @Assert\NotBlank(groups={"Registration", "Profile"}) - * @Assert\Length(min=2, max=254, groups={"Registration", "Profile"}) - * @Assert\Email(groups={"Registration", "Profile"}) - */ - protected $email; - - /** - * @var string - * - * @ORM\Column(type="string", length=255, unique=true) - */ - protected $emailCanonical; - - /** - * Encrypted password. - * - * @var string - * - * @ORM\Column(type="string") - */ - protected $password; + #[ + ORM\Id(), + ORM\Column( + type: 'integer', + ), + ORM\GeneratedValue( + strategy: 'AUTO', + ), + ] + protected int $id; + + #[ + ORM\Column( + type: 'string', + length: 255, + ), + Assert\NotBlank( + groups: [ + 'Registration', + 'Profile', + ], + ), + Assert\Length( + min: 2, + max: 255, + groups: [ + 'Registration', + 'Profile', + ], + ) + ] + protected string $username; + + #[ORM\Column( + type: 'string', + length: 255, + unique: true, + )] + protected string $usernameCanonical; + + #[ + ORM\Column( + type: 'string', + length: 255, + ), + Assert\NotBlank( + groups: [ + 'Registration', + 'Profile', + ], + ), + Assert\Length( + min: 2, + max: 254, + groups: [ + 'Registration', + 'Profile', + ], + ), + Assert\Email( + groups: [ + 'Registration', + 'Profile', + ], + ) + ] + protected string $email; + + #[ORM\Column( + type: 'string', + length: 255, + unique: true, + )] + protected string $emailCanonical; + + #[ORM\Column( + type: 'string', + )] + protected string $password; /** * Plain password, Used for model validation, must not be persisted. - * - * @var string - * - * @Assert\NotBlank(groups={"Registration", "ResetPassword", "ChangePassword"}) - * @Assert\Length(min=2, groups={"Registration", "Profile", "ResetPassword", "ChangePassword"}) - */ - protected $plainPassword; - - /** - * The salt to use for hashing. - * - * @var string - * - * @ORM\Column(type="string") - */ - protected $salt; - - /** - * @var DateTime|null - * - * @ORM\Column(type="datetime", nullable=true) */ - protected $lastLogin; + #[ + Assert\NotBlank( + groups: [ + 'Registration', + 'ResetPassword', + 'ChangePassword', + ], + ), + Assert\Length( + min: 2, + groups: [ + 'Registration', + 'Profile', + 'ResetPassword', + 'ChangePassword', + ], + ) + ] + protected ?string $plainPassword = null; + + #[ORM\Column( + type: 'string', + nullable: true, + )] + protected ?string $salt; + + #[ORM\Column( + type: 'datetime', + nullable: true, + )] + protected ?DateTime $lastLogin = null; /** * Random string sent to the user email address in order to verify it. - * - * @var string - * - * @ORM\Column(type="string", nullable=true) - */ - protected $confirmationToken; - - /** - * @var DateTime|null - * - * @ORM\Column(type="datetime", nullable=true) - */ - protected $passwordRequestedAt; - - /** - * @var bool - * - * @ORM\Column(type="boolean") - */ - protected $enabled; - - /** - * @var bool - * - * @ORM\Column(type="boolean") - */ - protected $locked; - - /** - * @var bool - * - * @ORM\Column(type="boolean") - */ - protected $expired; - - /** - * @var DateTime|null - * - * @ORM\Column(type="datetime", nullable=true) - */ - protected $expiresAt; - - /** - * @var bool - * - * @ORM\Column(type="boolean") */ - protected $credentialsExpired; + #[ORM\Column( + type: 'string', + nullable: true, + )] + protected ?string $confirmationToken; + + #[ORM\Column( + type: 'datetime', + nullable: true, + )] + protected ?DateTime $passwordRequestedAt; + + #[ORM\Column( + type: 'boolean', + )] + protected bool $enabled; + + #[ORM\Column( + type: 'boolean', + )] + protected bool $locked; + + #[ORM\Column( + type: 'boolean', + )] + protected bool $expired; + + #[ORM\Column( + type: 'datetime', + nullable: true, + )] + protected ?DateTime $expiresAt; + + #[ORM\Column( + type: 'boolean', + )] + protected bool $credentialsExpired; + + #[ORM\Column( + type: 'datetime', + nullable: true, + )] + protected ?DateTime $credentialsExpireAt; + + #[ORM\Column( + type: 'array', + )] + protected array $roles; + + #[ORM\ManyToMany( + targetEntity: GroupInterface::class, + cascade: ['persist'], + )] + protected Collection $groups; - /** - * @var DateTime|null - * - * @ORM\Column(type="datetime", nullable=true) - */ - protected $credentialsExpireAt; - - /** - * @var array - * - * @ORM\Column(type="array") - */ - protected $roles; - - /** - * @var Collection - * - * @ORM\ManyToMany(targetEntity="Imatic\Bundle\UserBundle\Model\GroupInterface", cascade={"persist"}) - */ - protected $groups; - - /** - * Constructor. - */ public function __construct() { $this->salt = \base_convert(\sha1(\uniqid((string) \mt_rand(), true)), 16, 36); @@ -184,130 +205,70 @@ public function __construct() $this->groups = new ArrayCollection(); } - /** - * Returns string representation. - * - * @return string - */ - public function __toString() + public function __toString(): string { return (string) $this->getUsername(); } - /** - * Returns id. - * - * @return mixed - */ - public function getId() + public function getId(): ?int { - return $this->id; + return $this->id ?? null; } - /** - * Sets username. - * - * @param string $username - * - * @return $this - */ - public function setUsername($username) + public function setUsername(string $username): UserInterface { $this->username = (string) $username; return $this; } - /** - * Returns username. - * - * @return string - */ - public function getUsername() + public function getUsername(): string { return $this->username; } - /** - * Sets canonical username. - * - * @param string $usernameCanonical - * - * @return $this - */ - public function setUsernameCanonical($usernameCanonical) + public function setUsernameCanonical(string $usernameCanonical): UserInterface { $this->usernameCanonical = (string) $usernameCanonical; return $this; } - /** - * Returns canonical username. - * - * @return string - */ - public function getUsernameCanonical() + public function getUsernameCanonical(): string { return $this->usernameCanonical; } - /** - * Sets email. - * - * @param string $email - * - * @return $this - */ - public function setEmail($email) + public function getUserIdentifier(): string + { + return $this->getUsername(); + } + + public function setEmail(string $email): UserInterface { $this->email = (string) $email; return $this; } - /** - * Returns email. - * - * @return string - */ - public function getEmail() + public function getEmail(): string { return $this->email; } - /** - * Sets canonical email. - * - * @param string $emailCanonical - * - * @return $this - */ - public function setEmailCanonical($emailCanonical) + public function setEmailCanonical(string $emailCanonical): UserInterface { $this->emailCanonical = (string) $emailCanonical; return $this; } - /** - * Returns canonical email. - * - * @return string - */ - public function getEmailCanonical() + public function getEmailCanonical(): string { return $this->emailCanonical; } - /** - * Sets encrypted password. - * - * @param string $password - * - * @return $this - */ - public function setPassword($password) + public function setPassword(string $password): UserInterface { $this->password = (string) $password; @@ -316,254 +277,130 @@ public function setPassword($password) /** * Returns encrypted password. - * - * @return string */ - public function getPassword() + public function getPassword(): ?string { return $this->password; } - /** - * Sets plain password. - * - * @param string $password - * - * @return $this - */ - public function setPlainPassword($password) + public function setPlainPassword(string $password): UserInterface { $this->plainPassword = (string) $password; return $this; } - /** - * Returns plain password. - * - * @return string - */ - public function getPlainPassword() + public function getPlainPassword(): ?string { return $this->plainPassword; } - /** - * @param string|null $salt - * - * @return $this - */ - public function setSalt($salt) + public function setSalt(?string $salt): UserInterface { $this->salt = $salt; return $this; } - /** - * Returns salt. - * - * @return string - */ - public function getSalt() + public function getSalt(): ?string { return $this->salt; } - /** - * Sets last login. - * - * @param DateTime $time - * - * @return $this - */ - public function setLastLogin(DateTime $time = null) + public function setLastLogin(DateTime $time = null): UserInterface { $this->lastLogin = $time; return $this; } - /** - * Returns last login time. - * - * @return DateTime - */ - public function getLastLogin() + public function getLastLogin(): ?DateTime { return $this->lastLogin; } - /** - * Sets confirmation token. - * - * @param string $confirmationToken - * - * @return $this - */ - public function setConfirmationToken($confirmationToken) + public function setConfirmationToken(?string $confirmationToken): UserInterface { $this->confirmationToken = $confirmationToken; return $this; } - /** - * Returns confirmation token. - * - * @return string - */ - public function getConfirmationToken() + public function getConfirmationToken(): ?string { return $this->confirmationToken; } - /** - * Sets password request at. - * - * @param DateTime $date - * - * @return $this - */ - public function setPasswordRequestedAt(DateTime $date = null) + public function setPasswordRequestedAt(DateTime $date = null): UserInterface { $this->passwordRequestedAt = $date; return $this; } - /** - * Returns password requested at. - * - * @return null|\DateTime - */ - public function getPasswordRequestedAt() + public function getPasswordRequestedAt(): ?DateTime { return $this->passwordRequestedAt; } - /** - * Sets enabled. - * - * @param bool $bool - * - * @return $this - */ - public function setEnabled($bool) + public function setEnabled(bool $boolean): UserInterface { - $this->enabled = (bool) $bool; + $this->enabled = (bool) $boolean; return $this; } - /** - * Returns true if user is enabled, false otherwise. - * - * @return bool - */ - public function isEnabled() + public function isEnabled(): bool { return $this->enabled; } - /** - * Sets locked. - * - * @param bool $bool - * - * @return $this - */ - public function setLocked($bool) + public function setLocked(bool $bool): UserInterface { $this->locked = (bool) $bool; return $this; } - /** - * Returns true if user is locked, false otherwise. - * - * @return bool - */ - public function isLocked() + public function isLocked(): bool { return !$this->isAccountNonLocked(); } - /** - * Sets expired. - * - * @param bool $bool - * - * @return User - */ - public function setExpired($bool) + public function setExpired(bool $bool): self { $this->expired = (bool) $bool; return $this; } - /** - * Returns true if user is expired, false otherwise. - * - * @return bool - */ - public function isExpired() + public function isExpired(): bool { return !$this->isAccountNonExpired(); } - /** - * Sets expired at. - * - * @param DateTime $date - * - * @return $this - */ - public function setExpiresAt(DateTime $date = null) + public function setExpiresAt(DateTime $date = null): UserInterface { $this->expiresAt = $date; return $this; } - /** - * Sets credential expired at. - * - * @param DateTime $date - * - * @return $this - */ - public function setCredentialsExpireAt(DateTime $date = null) + public function setCredentialsExpireAt(DateTime $date = null): UserInterface { $this->credentialsExpireAt = $date; return $this; } - /** - * Sets credentials expired. - * - * @param bool $bool - * - * @return $this - */ - public function setCredentialsExpired($bool) + public function setCredentialsExpired(bool $bool): UserInterface { $this->credentialsExpired = (bool) $bool; return $this; } - /** - * Sets roles. - * - * @param array $roles - * - * @return $this - */ - public function setRoles(array $roles) + public function setRoles(array $roles): UserInterface { $this->roles = []; @@ -574,14 +411,7 @@ public function setRoles(array $roles) return $this; } - /** - * Adds role. - * - * @param string $role - * - * @return $this - */ - public function addRole($role) + public function addRole(string $role): UserInterface { $role = (string) $role; $role = \strtoupper($role); @@ -596,14 +426,7 @@ public function addRole($role) return $this; } - /** - * Removes role. - * - * @param string $role - * - * @return $this - */ - public function removeRole($role) + public function removeRole(string $role): UserInterface { $role = (string) $role; @@ -615,12 +438,7 @@ public function removeRole($role) return $this; } - /** - * Returns roles. - * - * @return array - */ - public function getRoles() + public function getRoles(): array { $roles = $this->roles; @@ -642,26 +460,15 @@ public function getRoles() * instead, e.g. * * $securityContext->isGranted('ROLE_USER'); - * - * @param string $role - * - * @return bool */ - public function hasRole($role) + public function hasRole(string $role): bool { $role = (string) $role; return \in_array(\strtoupper($role), $this->getRoles(), true); } - /** - * Adds group. - * - * @param GroupInterface $group - * - * @return $this - */ - public function addGroup(GroupInterface $group) + public function addGroup(GroupInterface $group): UserInterface { if (!$this->getGroups()->contains($group)) { $this->getGroups()->add($group); @@ -670,14 +477,7 @@ public function addGroup(GroupInterface $group) return $this; } - /** - * Removes group. - * - * @param GroupInterface $group - * - * @return $this - */ - public function removeGroup(GroupInterface $group) + public function removeGroup(GroupInterface $group): UserInterface { if ($this->getGroups()->contains($group)) { $this->getGroups()->removeElement($group); @@ -687,21 +487,14 @@ public function removeGroup(GroupInterface $group) } /** - * Returns groups. - * * @return Collection|GroupInterface[] */ - public function getGroups() + public function getGroups(): Collection { return $this->groups; } - /** - * Returns group names. - * - * @return array - */ - public function getGroupNames() + public function getGroupNames(): array { $names = []; foreach ($this->getGroups() as $group) { @@ -711,26 +504,12 @@ public function getGroupNames() return $names; } - /** - * Returns true if user has given group, false otherwise. - * - * @param string $name - * - * @return bool - */ - public function hasGroup($name) + public function hasGroup(string $name): bool { return \in_array($name, $this->getGroupNames(), true); } - /** - * Sets super admin. - * - * @param bool $bool - * - * @return $this - */ - public function setSuperAdmin($bool) + public function setSuperAdmin(bool $bool): UserInterface { $bool = (bool) $bool; @@ -743,22 +522,12 @@ public function setSuperAdmin($bool) return $this; } - /** - * Returns true if user is super admin, false otherwise. - * - * @return bool - */ - public function isSuperAdmin() + public function isSuperAdmin(): bool { return $this->hasRole(static::ROLE_SUPER_ADMIN); } - /** - * Returns true if user account is not expired, false otherwsie. - * - * @return bool - */ - public function isAccountNonExpired() + public function isAccountNonExpired(): bool { if (true === $this->expired) { return false; @@ -771,22 +540,12 @@ public function isAccountNonExpired() return true; } - /** - * Returns true if account is not locked, false otherwise. - * - * @return bool - */ - public function isAccountNonLocked() + public function isAccountNonLocked(): bool { return !$this->locked; } - /** - * Returns true if user credentials are not expired, false otherwise. - * - * @return bool - */ - public function isCredentialsNonExpired() + public function isCredentialsNonExpired(): bool { if (true === $this->credentialsExpired) { return false; @@ -799,35 +558,21 @@ public function isCredentialsNonExpired() return true; } - /** - * Returns true if user credentials expired, false otherwise. - * - * @return bool - */ - public function isCredentialsExpired() + public function isCredentialsExpired(): bool { return !$this->isCredentialsNonExpired(); } - /** - * Returns true if password request is not expired. - * - * @param int $ttl - * - * @return bool - */ - public function isPasswordRequestNonExpired($ttl) + public function isPasswordRequestNonExpired(int $ttl): bool { return $this->getPasswordRequestedAt() instanceof DateTime && - $this->getPasswordRequestedAt()->getTimestamp() + $ttl > \time(); + $this->getPasswordRequestedAt()->getTimestamp() + $ttl > \time(); } /** * Returns true if same user, false otherwise. - * - * @return bool */ - public function isUser(UserInterface $user = null) + public function isUser(UserInterface $user = null): bool { return null !== $user && $this->getId() === $user->getId(); } @@ -844,30 +589,23 @@ public function eraseCredentials(): void * Serializes the user. * * The serialized data have to contain the fields used by the equals method and the username. - * - * @return string */ - public function serialize() + public function serialize(): string { return \serialize([ - $this->password, - $this->salt, - $this->usernameCanonical, - $this->username, - $this->expired, - $this->locked, - $this->credentialsExpired, - $this->enabled, - $this->id, - ]); + $this->password, + $this->salt, + $this->usernameCanonical, + $this->username, + $this->expired, + $this->locked, + $this->credentialsExpired, + $this->enabled, + $this->id, + ]); } - /** - * Unserializes the user. - * - * @param string $serialized - */ - public function unserialize($serialized): void + public function unserialize(string $serialized): void { $data = \unserialize($serialized); // add a few extra elements in the array to ensure that we have enough keys when unserializing @@ -884,6 +622,6 @@ public function unserialize($serialized): void $this->credentialsExpired, $this->enabled, $this->id - ) = $data; + ) = $data; } } diff --git a/Form/Type/User/ChangePasswordType.php b/Form/Type/User/ChangePasswordType.php old mode 100755 new mode 100644 index 392c090..793e144 --- a/Form/Type/User/ChangePasswordType.php +++ b/Form/Type/User/ChangePasswordType.php @@ -12,13 +12,6 @@ class ChangePasswordType extends AbstractType { - private string $userClass; - - public function __construct(string $userClass) - { - $this->userClass = $userClass; - } - public function buildForm(FormBuilderInterface $builder, array $options): void { $constraintsOptions = []; @@ -62,7 +55,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'data_class' => $this->userClass, 'csrf_token_id' => 'change_password', 'validation_groups' => ['ChangePassword', 'Default'], ]); @@ -70,6 +62,6 @@ public function configureOptions(OptionsResolver $resolver): void public function getBlockPrefix() { - return 'fos_user_change_password'; + return 'user_change_password'; } } diff --git a/Form/Type/User/ProfileType.php b/Form/Type/User/ProfileType.php old mode 100755 new mode 100644 index a0a5d96..db13050 --- a/Form/Type/User/ProfileType.php +++ b/Form/Type/User/ProfileType.php @@ -12,13 +12,6 @@ class ProfileType extends AbstractType { - private string $userClass; - - public function __construct(string $userClass) - { - $this->userClass = $userClass; - } - public function buildForm(FormBuilderInterface $builder, array $options): void { $this->buildUserForm($builder, $options); @@ -53,7 +46,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'data_class' => $this->userClass, 'csrf_token_id' => 'profile', 'validation_groups' => ['Profile', 'Default'], ]); @@ -61,7 +53,7 @@ public function configureOptions(OptionsResolver $resolver): void public function getBlockPrefix() { - return 'fos_user_profile'; + return 'user_profile'; } protected function buildUserForm(FormBuilderInterface $builder, array $options): void diff --git a/Form/Type/User/ResettingFormType.php b/Form/Type/User/ResettingFormType.php index 4f0b897..8902b68 100644 --- a/Form/Type/User/ResettingFormType.php +++ b/Form/Type/User/ResettingFormType.php @@ -9,13 +9,6 @@ class ResettingFormType extends AbstractType { - private string $userClass; - - public function __construct(string $userClass) - { - $this->userClass = $userClass; - } - public function buildForm(FormBuilderInterface $builder, array $options): void { $builder->add('plainPassword', RepeatedType::class, [ @@ -35,14 +28,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'data_class' => $this->userClass, 'csrf_token_id' => 'resetting', 'validation_groups' => ['ResetPassword', 'Default'], ]); } - public function getBlockPrefix() + public function getBlockPrefix(): string { - return 'fos_user_resetting'; + return 'user_resetting'; } } diff --git a/Form/Type/User/UserType.php b/Form/Type/User/UserType.php old mode 100755 new mode 100644 index 84406bd..aefbfb0 --- a/Form/Type/User/UserType.php +++ b/Form/Type/User/UserType.php @@ -11,14 +11,9 @@ class UserType extends AbstractType { - /** - * @var string - */ - private $userClass; - - public function __construct($userClass) - { - $this->userClass = $userClass; + public function __construct( + private string $userClass + ) { } public function buildForm(FormBuilderInterface $builder, array $options): void @@ -38,9 +33,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('save', SubmitType::class, ['attr' => ['class' => 'btn-primary']]); } - /** - * @param OptionsResolver $resolver - */ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ diff --git a/ImaticUserBundle.php b/ImaticUserBundle.php old mode 100755 new mode 100644 index c9a8c09..6126214 --- a/ImaticUserBundle.php +++ b/ImaticUserBundle.php @@ -7,9 +7,6 @@ class ImaticUserBundle extends Bundle { - /** - * @param ContainerBuilder $container - */ public function build(ContainerBuilder $container): void { $container->addCompilerPass(new SecurityPass()); diff --git a/Mailer/Mailer.php b/Mailer/Mailer.php index 68b6c97..da6535e 100644 --- a/Mailer/Mailer.php +++ b/Mailer/Mailer.php @@ -7,60 +7,64 @@ class Mailer { - private \Swift_Mailer $mailer; + private \Symfony\Component\Mailer\MailerInterface $mailer; private UrlGeneratorInterface $router; private Environment $twig; private HtmlEmailBuilder $htmlEmailBuilder; - private array $resettingFromEmail; + private string $resettingFromEmail; + private string $resettingFromSenderName; public function __construct( - \Swift_Mailer $mailer, - UrlGeneratorInterface $router, - Environment $twig, - HtmlEmailBuilder $htmlEmailBuilder, - array $resettingFromEmail + \Symfony\Component\Mailer\MailerInterface $mailer, + UrlGeneratorInterface $router, + Environment $twig, + HtmlEmailBuilder $htmlEmailBuilder, + string $resettingFromEmail, + string $resettingFromSenderName ) { $this->mailer = $mailer; $this->router = $router; $this->twig = $twig; $this->htmlEmailBuilder = $htmlEmailBuilder; $this->resettingFromEmail = $resettingFromEmail; + $this->resettingFromSenderName = $resettingFromSenderName; } public function sendResettingEmailMessage(UserInterface $user): void { $template = '@ImaticUser/Resetting/email.txt.twig'; - $url = $this->router->generate('fos_user_resetting_reset', ['token' => $user->getConfirmationToken()], UrlGeneratorInterface::ABSOLUTE_URL); + $url = $this->router->generate('user_resetting_reset', ['token' => $user->getConfirmationToken()], UrlGeneratorInterface::ABSOLUTE_URL); $context = [ 'user' => $user, 'confirmationUrl' => $url, ]; - $this->sendMessage($template, $context, $this->resettingFromEmail, (string) $user->getEmail()); + $this->sendMessage($template, $context, $this->resettingFromEmail, (string) $user->getEmail(), $this->resettingFromSenderName); } - private function sendMessage(string $templateName, array $context, $fromEmail, $toEmail): void + private function sendMessage(string $templateName, array $context, string $fromEmail, string $toEmail, string $senderName): void { $context = $this->twig->mergeGlobals($context); $template = $this->twig->loadTemplate($this->twig->getTemplateClass($templateName), $templateName); $subject = $template->renderBlock('subject', $context); $textBody = $template->renderBlock('body_text', $context); $htmlBody = $template->renderBlock('body_html', $context); + $address = new \Symfony\Component\Mime\Address($fromEmail, $senderName); - $message = (new \Swift_Message()) - ->setSubject($subject) - ->setFrom($fromEmail) - ->setTo($toEmail); + $message = new \Symfony\Component\Mime\Email(); + $message + ->subject($subject) + ->from($address) + ->to($toEmail); if (!empty($htmlBody)) { $htmlBody = $this->htmlEmailBuilder->build($htmlBody); $message - ->setBody($htmlBody, 'text/html') - ->addPart($textBody, 'text/plain'); + ->text($htmlBody, 'text/html') + ->html($textBody, 'text/plain'); } else { - $message->setBody($textBody); + $message->text($textBody); } - $this->mailer->send($message); } } diff --git a/Makefile b/Makefile index 151fb9f..ce1acf9 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,12 @@ SHELL := /usr/bin/env bash .PHONY: test -test: phpunit phpmd phpcs +test: phpunit phpcs .PHONY: phpcs phpcs: ./vendor/bin/php-cs-fixer fix --dry-run -.PHONY: phpmd -phpmd: - ./vendor/bin/phpmd $$((\ - find * -maxdepth 0 -not -name 'vendor' -not -name 'Tests' -type d && \ - find Tests/ -mindepth 1 -maxdepth 1 -not -name 'Fixtures' && \ - find Tests/Fixtures/ -mindepth 2 -maxdepth 2 -not -name 'var' \ - ) | paste --delimiter , --serial) text phpmd.xml - .PHONY: phpunit phpunit: ./vendor/bin/phpunit diff --git a/Manager/UserManager.php b/Manager/UserManager.php index cc0940b..fe138c4 100644 --- a/Manager/UserManager.php +++ b/Manager/UserManager.php @@ -15,13 +15,27 @@ class UserManager private EncoderFactoryInterface $encoderFactory; private string $userClass; - public function __construct(EntityManagerInterface $om, EncoderFactoryInterface $encoderFactory, string $userClass) - { + public function __construct( + EntityManagerInterface $om, + EncoderFactoryInterface $encoderFactory, + string $userClass + ) { $this->em = $om; $this->encoderFactory = $encoderFactory; $this->userClass = $userClass; } + /** + * Returns an empty user instance + */ + public function createUser(): UserInterface + { + $class = $this->getClass(); + $user = new $class(); + + return $user; + } + private function getRepository(): ObjectRepository { return $this->em->getRepository($this->userClass); diff --git a/Menu/UserMenuBuilder.php b/Menu/UserMenuBuilder.php old mode 100755 new mode 100644 index 91917be..62cfbd0 --- a/Menu/UserMenuBuilder.php +++ b/Menu/UserMenuBuilder.php @@ -6,36 +6,24 @@ class UserMenuBuilder { - /** - * @param Factory $factory - * @param Helper $helper - * - * @return \Knp\Menu\ItemInterface - */ - public function getMenu(Factory $factory, Helper $helper) + public function getMenu(Factory $factory, Helper $helper): \Knp\Menu\ItemInterface { - $menu = $factory->createItem((string) $helper->getUser()); + $menu = $factory->createItem($helper->getUser()->getUsername()); $helper->setDropdown($menu); - $menu->addChild($helper->trans('User Profile', [], 'ImaticUserBundle'), ['route' => 'fos_user_profile_show']); - $menu->addChild($helper->trans('Change password', [], 'ImaticUserBundle'), ['route' => 'fos_user_change_password']) + $menu->addChild($helper->trans('User Profile', [], 'ImaticUserBundle'), ['route' => 'user_profile_show']); + $menu->addChild($helper->trans('Change password', [], 'ImaticUserBundle'), ['route' => 'user_change_password']) ->setAttribute('divider', true); if ($helper->isUserGranted('ROLE_PREVIOUS_ADMIN')) { $menu->addChild($helper->trans('Switch user exit', [], 'ImaticUserBundleUser'), ['route' => 'homepage', 'routeParameters' => ['_switch_user' => '_exit']]); } - $menu->addChild($helper->trans('layout.logout', [], 'FOSUserBundle'), ['route' => 'fos_user_security_logout']); + $menu->addChild($helper->trans('layout.logout', [], 'ImaticUserBundle'), ['route' => 'user_security_logout']); return $menu; } - /** - * @param Factory $factory - * @param Helper $helper - * - * @return \Knp\Menu\ItemInterface - */ - public function getMenuAnon(Factory $factory, Helper $helper) + public function getMenuAnon(Factory $factory, Helper $helper): \Knp\Menu\ItemInterface { - $menu = $factory->createItem($helper->trans('layout.login', [], 'FOSUserBundle'), ['route' => 'fos_user_security_login']); + $menu = $factory->createItem($helper->trans('layout.login', [], 'ImaticUserBundle'), ['route' => 'user_security_login']); return $menu; } diff --git a/Model/GroupInterface.php b/Model/GroupInterface.php index 042c33f..920dc23 100644 --- a/Model/GroupInterface.php +++ b/Model/GroupInterface.php @@ -3,56 +3,22 @@ /** * Group interface. - * - * @author Viliam Husár */ interface GroupInterface { - /** - * @param string $role - * - * @return static - */ - public function addRole($role); - - /** - * @return mixed - */ - public function getId(); - - /** - * @return string - */ - public function getName(); - - /** - * @param string $role - * - * @return bool - */ - public function hasRole($role); - - /** - * @return array - */ - public function getRoles(); - - /** - * @param string $role - * - * @return static - */ - public function removeRole($role); - - /** - * @param string $name - * - * @return static - */ - public function setName($name); - - /** - * @return static - */ - public function setRoles(array $roles); + public function addRole(string $role): static; + + public function getId(): mixed; + + public function getName(): string; + + public function hasRole(string $role): bool; + + public function getRoles(): array; + + public function removeRole(string $role): static; + + public function setName(string $name): static; + + public function setRoles(array $roles): static; } diff --git a/Model/UserInterface.php b/Model/UserInterface.php index 90bd585..306448a 100644 --- a/Model/UserInterface.php +++ b/Model/UserInterface.php @@ -9,171 +9,51 @@ /** * User interface. - * - * @author Viliam Husár */ interface UserInterface extends BaseUserInterface { public const ROLE_DEFAULT = 'ROLE_USER'; public const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN'; - /** - * Returns the user unique id. - * - * @return mixed - */ - public function getId(); + public function getId(): ?int; - /** - * Sets the username. - * - * @param string $username - * - * @return static - */ - public function setUsername($username); + public function setUsername(string $username): self; - /** - * Gets the canonical username in search and sort queries. - * - * @return string - */ - public function getUsernameCanonical(); + public function getUsernameCanonical(): string; - /** - * Sets the canonical username. - * - * @param string $usernameCanonical - * - * @return static - */ - public function setUsernameCanonical($usernameCanonical); + public function setUsernameCanonical(string $usernameCanonical): self; - /** - * @param string|null $salt - * - * @return static - */ - public function setSalt($salt); + public function setSalt(?string $salt): self; - /** - * Gets email. - * - * @return string - */ - public function getEmail(); + public function getEmail(): string; - /** - * Sets the email. - * - * @param string $email - * - * @return static - */ - public function setEmail($email); + public function setEmail(string $email): self; - /** - * Gets the canonical email in search and sort queries. - * - * @return string - */ - public function getEmailCanonical(); + public function getEmailCanonical(): string; - /** - * Sets the canonical email. - * - * @param string $emailCanonical - * - * @return static - */ - public function setEmailCanonical($emailCanonical); + public function setEmailCanonical(string $emailCanonical): self; - /** - * Gets the plain password. - * - * @return string - */ - public function getPlainPassword(); + public function getPlainPassword():?string; - /** - * Sets the plain password. - * - * @param string $password - * - * @return static - */ - public function setPlainPassword($password); + public function setPlainPassword(string $password): self; - /** - * Sets the hashed password. - * - * @param string $password - * - * @return static - */ - public function setPassword($password); + public function setPassword(string $password): self; - /** - * Tells if the the given user has the super admin role. - * - * @return bool - */ - public function isSuperAdmin(); + public function isSuperAdmin(): bool; - /** - * @param bool $boolean - * - * @return static - */ - public function setEnabled($boolean); + public function setEnabled(bool $boolean): self; - /** - * Sets the super admin status. - * - * @param bool $boolean - * - * @return static - */ - public function setSuperAdmin($boolean); + public function setSuperAdmin(bool $boolean): self; - /** - * Gets the confirmation token. - * - * @return string|null - */ - public function getConfirmationToken(); + public function getConfirmationToken():?string; - /** - * Sets the confirmation token. - * - * @param string|null $confirmationToken - * - * @return static - */ - public function setConfirmationToken($confirmationToken); + public function setConfirmationToken(?string $confirmationToken): self; - /** - * Sets the timestamp that the user requested a password reset. - * - * @return static - */ - public function setPasswordRequestedAt(\DateTime $date = null); + public function setPasswordRequestedAt(\DateTime $date = null): self; - /** - * Checks whether the password reset request has expired. - * - * @param int $ttl Requests older than this many seconds will be considered expired - * - * @return bool - */ - public function isPasswordRequestNonExpired($ttl); + public function isPasswordRequestNonExpired(int $ttl): bool; - /** - * Sets the last login time. - * - * @return static - */ - public function setLastLogin(\DateTime $time = null); + public function setLastLogin(\DateTime $time = null): self; /** * Never use this to check if this user has access to anything! @@ -182,39 +62,20 @@ public function setLastLogin(\DateTime $time = null); * instead, e.g. * * $authorizationChecker->isGranted('ROLE_USER'); - * - * @param string $role - * - * @return bool */ - public function hasRole($role); + public function hasRole(string $role):bool; /** * Sets the roles of the user. * * This overwrites any previous roles. * - * @return static */ - public function setRoles(array $roles); + public function setRoles(array $roles): self; - /** - * Adds a role to the user. - * - * @param string $role - * - * @return static - */ - public function addRole($role); + public function addRole(string $role): self; - /** - * Removes a role to the user. - * - * @param string $role - * - * @return static - */ - public function removeRole($role); + public function removeRole(string $role): self; /** * Checks whether the user's account has expired. @@ -226,7 +87,7 @@ public function removeRole($role); * * @see AccountExpiredException */ - public function isAccountNonExpired(); + public function isAccountNonExpired(): bool; /** * Checks whether the user is locked. @@ -238,7 +99,7 @@ public function isAccountNonExpired(); * * @see LockedException */ - public function isAccountNonLocked(); + public function isAccountNonLocked(): bool; /** * Checks whether the user's credentials (password) has expired. @@ -250,7 +111,7 @@ public function isAccountNonLocked(); * * @see CredentialsExpiredException */ - public function isCredentialsNonExpired(); + public function isCredentialsNonExpired(): bool; /** * Checks whether the user is enabled. @@ -262,5 +123,5 @@ public function isCredentialsNonExpired(); * * @see DisabledException */ - public function isEnabled(); + public function isEnabled(): bool; } diff --git a/Monolog/LoggedInUserProcessor.php b/Monolog/LoggedInUserProcessor.php index 03c09b8..29aa734 100644 --- a/Monolog/LoggedInUserProcessor.php +++ b/Monolog/LoggedInUserProcessor.php @@ -6,12 +6,9 @@ class LoggedInUserProcessor { - /** @var TokenStorageInterface */ - private $tokenStorage; - - public function __construct(TokenStorageInterface $tokenStorage) - { - $this->tokenStorage = $tokenStorage; + public function __construct( + private TokenStorageInterface $tokenStorage + ) { } public function processRecord(array $record) diff --git a/Resources/app/Entity/Group.php b/Resources/app/Entity/Group.php old mode 100755 new mode 100644 index 58fb620..dcb85c2 --- a/Resources/app/Entity/Group.php +++ b/Resources/app/Entity/Group.php @@ -4,12 +4,10 @@ use Doctrine\ORM\Mapping as ORM; use Imatic\Bundle\UserBundle\Entity\Group as BaseGroup; -/** - * Group. - * - * @ORM\Entity() - * @ORM\Table() - */ +#[ + ORM\Entity(), + ORM\Table(), +] class Group extends BaseGroup { } diff --git a/Resources/app/Entity/User.php b/Resources/app/Entity/User.php old mode 100755 new mode 100644 index b11be95..3348099 --- a/Resources/app/Entity/User.php +++ b/Resources/app/Entity/User.php @@ -4,12 +4,10 @@ use Doctrine\ORM\Mapping as ORM; use Imatic\Bundle\UserBundle\Entity\User as BaseUser; -/** - * User. - * - * @ORM\Entity - * @ORM\Table() - */ +#[ + ORM\Entity(), + ORM\Table(), +] class User extends BaseUser { } diff --git a/Resources/config/services.yml b/Resources/config/services.yml old mode 100755 new mode 100644 index 77010b3..22e3481 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -1,174 +1,38 @@ services: - # Form - imatic_user.form.type.profile: - class: Imatic\Bundle\UserBundle\Form\Type\User\ProfileType - arguments: - - '%imatic_user.entity.user.class%' - tags: - - {name: form.type } - - imatic_user.form.type.change_password: - class: Imatic\Bundle\UserBundle\Form\Type\User\ChangePasswordType - arguments: - - '%imatic_user.entity.user.class%' - tags: - - {name: form.type } - - imatic_user.form.type.user: - class: Imatic\Bundle\UserBundle\Form\Type\User\UserType - arguments: - - '%imatic_user.entity.user.class%' - tags: - - {name: form.type } - - Imatic\Bundle\UserBundle\Form\Type\User\ResettingFormType: - arguments: - - '%imatic_user.entity.user.class%' - tags: - - { name: form.type } - - # Command handler - imatic_user.data.handler.user_edit: - class: Imatic\Bundle\UserBundle\Data\Handler\User\UserEditHandler - arguments: - - '@Imatic\Bundle\UserBundle\Manager\UserManager' - tags: - - { name: imatic_data.handler } + _defaults: + autowire: true + autoconfigure: true - imatic_user.data.handler.user_create: - class: Imatic\Bundle\UserBundle\Data\Handler\User\UserCreateHandler - arguments: - - '@Imatic\Bundle\UserBundle\Manager\UserManager' - tags: - - { name: imatic_data.handler } - - imatic_user.data.handler.user_delete: - class: Imatic\Bundle\UserBundle\Data\Handler\User\UserDeleteHandler - arguments: - - '@Imatic\Bundle\UserBundle\Manager\UserManager' - tags: - - { name: imatic_data.handler } + Imatic\Bundle\UserBundle\Controller\: + resource: '../../Controller/' + tags: [ 'controller.service_arguments' ] - # Menu - imatic_user.menu.user_menu: - class: Imatic\Bundle\UserBundle\Menu\UserMenuBuilder - public: true - tags: - - {name: imatic_view.menu, alias: imatic.user} - - {name: imatic_view.menu, alias: imatic.user_anon, method: getMenuAnon} - imatic_user.twig.extension.security: - class: Imatic\Bundle\UserBundle\Twig\Extension\SecurityExtension + Imatic\Bundle\UserBundle\Data\Handler\User\UserCreateHandler: + Imatic\Bundle\UserBundle\Data\Handler\User\UserEditHandler: + Imatic\Bundle\UserBundle\Security\Role\Provider\ChainRoleProvider: + Imatic\Bundle\UserBundle\Security\Role\Translation\RoleTranslator: + Imatic\Bundle\UserBundle\Mailer\HtmlEmailBuilder: + class: Imatic\Bundle\UserBundle\Mailer\NoopHtmlEmailBuilder + Imatic\Bundle\UserBundle\Mailer\Mailer: arguments: - - '@imatic_user.security.role.provider.model_role_provider' - - '@imatic_user.security.role.translation.role_translator' - tags: - - {name: twig.extension} - - # Security - imatic_user.security.role.metadata_factory: - class: Doctrine\ORM\Mapping\ClassMetadataFactory - factory: ['@Doctrine\ORM\EntityManagerInterface', 'getMetadataFactory'] - - # Security role provider - imatic_user.security.role.provider.model_role_provider: - class: Imatic\Bundle\UserBundle\Security\Role\Provider\ModelRoleProvider - arguments: ['@imatic_user.security.role.metadata_factory'] - public: false - tags: - - {name: imatic_user.role_provider, alias: model} - - imatic_user.security.role.provider.hierarchy_role_provider: - class: Imatic\Bundle\UserBundle\Security\Role\Provider\HierarchyRoleProvider - arguments: ['%security.role_hierarchy.roles%'] - tags: - - {name: imatic_user.role_provider, alias: hierarchy} + $resettingFromEmail: '%imatic.user.email.resseting_from_address%' + $resettingFromSenderName: '%imatic.user.email.resseting_from_sender_name%' - imatic_user.security.role.provider.chain_role_provider: - class: Imatic\Bundle\UserBundle\Security\Role\Provider\ChainRoleProvider - - imatic_user.role_provider: - alias: imatic_user.security.role.provider.chain_role_provider - - Imatic\Bundle\UserBundle\Security\Role\Provider\RoleProviderInterface: - alias: imatic_user.role_provider - - # Security role translation - imatic_user.security.role.translation.role_translator: - class: Imatic\Bundle\UserBundle\Security\Role\Translation\RoleTranslator - arguments: ['@translator'] - - imatic_user.security.role.translation.hierarchy_strategy: - class: Imatic\Bundle\UserBundle\Security\Role\Translation\HierarchyStrategy - arguments: ['@translator'] - tags: - - {name: imatic_user.role_translation_strategy} - - # User providers - imatic_user.user_provider.username: - class: Imatic\Bundle\UserBundle\Security\UserProvider - public: false - arguments: - - '@Imatic\Bundle\UserBundle\Manager\UserManager' imatic_user.user_provider.username_email: class: Imatic\Bundle\UserBundle\Security\EmailUserProvider - public: false - arguments: - - '@Imatic\Bundle\UserBundle\Manager\UserManager' - - imatic_user.user_filter: - class: Imatic\Bundle\UserBundle\Data\Filter\User\UserFilter - tags: - - { name: imatic_data.filter } - - imatic_user.monolog.logged_in_user_processor: - class: Imatic\Bundle\UserBundle\Monolog\LoggedInUserProcessor - arguments: - - '@security.token_storage' - tags: - - { name: 'monolog.processor', method: processRecord } Imatic\Bundle\UserBundle\Manager\UserManager: arguments: - - '@Doctrine\ORM\EntityManagerInterface' - - '@Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface' - - '%imatic_user.entity.user.class%' + $userClass: '%imatic_user.entity.user.class%' Imatic\Bundle\UserBundle\Manager\GroupManager: arguments: - - '@Doctrine\ORM\EntityManagerInterface' - - '%imatic_user.entity.group.class%' + $groupClass: '%imatic_user.entity.group.class%' - Imatic\Bundle\UserBundle\Mailer\HtmlEmailBuilder: - class: Imatic\Bundle\UserBundle\Mailer\NoopHtmlEmailBuilder + Imatic\Bundle\UserBundle\Data\Filter\User\UserFilter: - Imatic\Bundle\UserBundle\Mailer\Mailer: + Imatic\Bundle\UserBundle\Form\Type\User\UserType: arguments: - - '@Swift_Mailer' - - '@Symfony\Component\Routing\Generator\UrlGeneratorInterface' - - '@Twig\Environment' - - '@Imatic\Bundle\UserBundle\Mailer\HtmlEmailBuilder' - - '%imatic.user.email.resseting_from%' - - Imatic\Bundle\UserBundle\Controller\ResettingController: - tags: - - { name: controller.service_arguments } - - Imatic\Bundle\UserBundle\Controller\ProfileController: - tags: - - { name: controller.service_arguments } - - Imatic\Bundle\UserBundle\Controller\ChangePasswordController: - tags: - - { name: controller.service_arguments } - - Imatic\Bundle\UserBundle\EventListener\LastLoginListener: - arguments: - - '@Imatic\Bundle\UserBundle\Manager\UserManager' - tags: - - { name: kernel.event_subscriber } - - Imatic\Bundle\UserBundle\Controller\RoleController: - tags: - - { name: controller.service_arguments } + $userClass: '%imatic_user.entity.user.class%' diff --git a/Resources/views/ChangePassword/change_password.html.twig b/Resources/views/ChangePassword/change_password.html.twig index 7b3128e..914f793 100644 --- a/Resources/views/ChangePassword/change_password.html.twig +++ b/Resources/views/ChangePassword/change_password.html.twig @@ -1,18 +1,18 @@ -{% extends "ImaticUserBundle::layout.html.twig" %} +{% extends "@ImaticUser/layout.html.twig" %} {% block headline %} {{ 'Change password'|trans({}, 'ImaticUserBundle') }} {% endblock %} -{% block fos_user_content %} +{% block user_content %}
- {% embed 'ImaticViewBundle:Layout:grid.html.twig' with {rows: [{ cols: {sidebar: {size: 3}, form: {size:9} } }] } %} + {% embed '@ImaticView/Layout/grid.html.twig' with {rows: [{ cols: {sidebar: {size: 3}, form: {size:9} } }] } %} {% block sidebar %} - {{ include('ImaticUserBundle:Profile:menu.html.twig') }} + {{ include('@ImaticUser/Profile/menu.html.twig') }} {% endblock %} {% block form %} - {{ include('ImaticViewBundle:Component:form.html.twig', {form: form}, with_context = false) }} + {{ include('@ImaticView/Component/form.html.twig', {form: form}, with_context = false) }} {% endblock %} {% endembed %}
-{% endblock fos_user_content %} +{% endblock user_content %} diff --git a/Resources/views/Profile/edit.html.twig b/Resources/views/Profile/edit.html.twig index 5cbeb69..186648b 100644 --- a/Resources/views/Profile/edit.html.twig +++ b/Resources/views/Profile/edit.html.twig @@ -1,17 +1,17 @@ -{% extends "ImaticUserBundle::layout.html.twig" %} +{% extends "@ImaticUser/layout.html.twig" %} {% block headline %} {{ 'User Profile Edit'|trans({}, 'ImaticUserBundle') }} {% endblock %} -{% block fos_user_content %} +{% block user_content %}
- {% embed 'ImaticViewBundle:Layout:grid.html.twig' with {rows: [{ cols: {sidebar: {size: 3}, form: {size:9} } }] } %} + {% embed '@ImaticView/Layout/grid.html.twig' with {rows: [{ cols: {sidebar: {size: 3}, form: {size:9} } }] } %} {% block sidebar %} - {{ include('ImaticUserBundle:Profile:menu.html.twig') }} + {{ include('@ImaticUser/Profile/menu.html.twig') }} {% endblock %} {% block form %} - {{ include('ImaticViewBundle:Component:form.html.twig', {form: form}, with_context = false) }} + {{ include('@ImaticView/Component/form.html.twig', {form: form}, with_context = false) }} {% endblock %} {% endembed %}
diff --git a/Resources/views/Profile/menu.html.twig b/Resources/views/Profile/menu.html.twig index 55a32fd..9a846a4 100644 --- a/Resources/views/Profile/menu.html.twig +++ b/Resources/views/Profile/menu.html.twig @@ -1,8 +1,8 @@ -{% import 'ImaticViewBundle:Component:menu.html.twig' as menu %} +{% import '@ImaticView/Component/menu.html.twig' as menu %} {% set side_menu = [ -{'name': 'User Profile'|trans({}, 'ImaticUserBundle'), 'route': 'fos_user_profile_show'}, -{'name': 'User Profile Edit'|trans({}, 'ImaticUserBundle'), 'route': 'fos_user_profile_edit'}, -{'name': 'Change password'|trans({}, 'ImaticUserBundle'), 'route': 'fos_user_change_password'} +{'name': 'User Profile'|trans({}, 'ImaticUserBundle'), 'route': 'user_profile_show'}, +{'name': 'User Profile Edit'|trans({}, 'ImaticUserBundle'), 'route': 'user_profile_edit'}, +{'name': 'Change password'|trans({}, 'ImaticUserBundle'), 'route': 'user_change_password'} ] %} {{ menu.side(side_menu) }} \ No newline at end of file diff --git a/Resources/views/Profile/show.html.twig b/Resources/views/Profile/show.html.twig index 258d760..7f7af7d 100644 --- a/Resources/views/Profile/show.html.twig +++ b/Resources/views/Profile/show.html.twig @@ -1,14 +1,14 @@ -{% extends "ImaticUserBundle::layout.html.twig" %} +{% extends "@ImaticUser/layout.html.twig" %} {% block headline %} {{ 'User Profile'|trans({}, 'ImaticUserBundle') }} {% endblock %} -{% block fos_user_content %} +{% block user_content %}
- {% embed 'ImaticViewBundle:Layout:grid.html.twig' with {rows: [{ cols: {sidebar: {size: 3}, profile: {size:9} } }] } %} + {% embed '@ImaticView/Layout/grid.html.twig' with {rows: [{ cols: {sidebar: {size: 3}, profile: {size:9} } }] } %} {% block sidebar %} - {% include 'ImaticUserBundle:Profile:menu.html.twig' %} + {% include '@ImaticUser/Profile/menu.html.twig' %} {% endblock %} {% block profile %} @@ -16,7 +16,7 @@ {name: 'username', label: 'Username'}, {name: 'email', label: 'Email'} ] %} - {{ include('ImaticViewBundle:Component:show.html.twig', { item: user, fields: fields, show: {translationDomain: 'ImaticUserBundle'} }) }} + {{ include('@ImaticView/Component/show.html.twig', { item: user, fields: fields, show: {translationDomain: 'ImaticUserBundle'} }) }} {% endblock %} {% endembed %} diff --git a/Resources/views/Resetting/check_email.html.twig b/Resources/views/Resetting/check_email.html.twig index 01018e7..03de693 100644 --- a/Resources/views/Resetting/check_email.html.twig +++ b/Resources/views/Resetting/check_email.html.twig @@ -1,17 +1,17 @@ -{% import "ImaticViewBundle:Component:panel.html.twig" as widget %} -{% extends "ImaticUserBundle::layout.html.twig" %} +{% import "@ImaticView/Component/panel.html.twig" as widget %} +{% extends "@ImaticUser/layout.html.twig" %} {% block headline %} {{ 'resetting.request.submit'|trans({}, 'ImaticUserBundle') }} {% endblock %} -{% block fos_user_content %} +{% block user_content %}
- {% embed 'ImaticViewBundle:Layout:grid.html.twig' with {rows: [{ cols:{reseting: {size: 4, offset: 4} } }] } %} + {% embed '@ImaticView/Layout/grid.html.twig' with {rows: [{ cols:{reseting: {size: 4, offset: 4} } }] } %} {% block reseting %} - {% embed 'ImaticViewBundle:Component:panel.html.twig' %} - {% import "ImaticViewBundle:Component:message.html.twig" as message %} + {% embed '@ImaticView/Component/panel.html.twig' %} + {% import "@ImaticView/Component/message.html.twig" as message %} {% set panel = {type: 'app'} %} {% block panel_header %} @@ -26,4 +26,4 @@ {% endblock %} {% endembed %}
-{% endblock fos_user_content %} +{% endblock user_content %} diff --git a/Resources/views/Resetting/request.html.twig b/Resources/views/Resetting/request.html.twig index 9fc26a1..bb9cf13 100644 --- a/Resources/views/Resetting/request.html.twig +++ b/Resources/views/Resetting/request.html.twig @@ -1,18 +1,18 @@ -{% import "ImaticViewBundle:Component:message.html.twig" as message %} -{% import "ImaticViewBundle:Component:panel.html.twig" as widget %} -{% extends "ImaticUserBundle::layout.html.twig" %} +{% import "@ImaticView/Component/message.html.twig" as message %} +{% import "@ImaticView/Component/panel.html.twig" as widget %} +{% extends "@ImaticUser/layout.html.twig" %} {% block headline %} {{ 'resetting.request.submit'|trans({}, 'ImaticUserBundle') }} {% endblock %} -{% block fos_user_content %} +{% block user_content %}
-
- {% embed 'ImaticViewBundle:Layout:grid.html.twig' with {rows: [{ cols:{reseting: {size: 4, offset: 4} } }] } %} + + {% embed '@ImaticView/Layout/grid.html.twig' with {rows: [{ cols:{reseting: {size: 4, offset: 4} } }] } %} {% block reseting %} - {% embed 'ImaticViewBundle:Component:panel.html.twig' %} + {% embed '@ImaticView/Component/panel.html.twig' %} {% set panel = {type: 'app'} %} {% block panel_header %}

{{ 'resetting.request.submit'|trans({}, 'ImaticUserBundle') }}

@@ -41,4 +41,4 @@ {% endembed %}
-{% endblock fos_user_content %} +{% endblock user_content %} diff --git a/Resources/views/Resetting/reset.html.twig b/Resources/views/Resetting/reset.html.twig index d5a48ab..e559294 100644 --- a/Resources/views/Resetting/reset.html.twig +++ b/Resources/views/Resetting/reset.html.twig @@ -1,18 +1,18 @@ -{% import "ImaticViewBundle:Component:message.html.twig" as message %} -{% import "ImaticViewBundle:Component:panel.html.twig" as widget %} -{% extends "ImaticUserBundle::layout.html.twig" %} +{% import "@ImaticView/Component/message.html.twig" as message %} +{% import "@ImaticView/Component/panel.html.twig" as widget %} +{% extends "@ImaticUser/layout.html.twig" %} {% block headline %} {{ 'resetting.request.submit'|trans({}, 'ImaticUserBundle') }} {% endblock %} -{% block fos_user_content %} +{% block user_content %}
- {{ form_start(form, {action: path('fos_user_resetting_reset', {'token': token}), method: 'post'})|replace({'form-horizontal': ''})|raw }} - {% embed 'ImaticViewBundle:Layout:grid.html.twig' with {rows: [{ cols:{reseting: {size: 4, offset: 4} } }] } %} + {{ form_start(form, {action: path('user_resetting_reset', {'token': token}), method: 'post'})|replace({'form-horizontal': ''})|raw }} + {% embed '@ImaticView/Layout/grid.html.twig' with {rows: [{ cols:{reseting: {size: 4, offset: 4} } }] } %} {% block reseting %} - {% embed 'ImaticViewBundle:Component:panel.html.twig' %} + {% embed '@ImaticView/Component/panel.html.twig' %} {% set panel = {type: 'app'} %} {% block panel_header %}

{{ 'resetting.request.submit'|trans({}, 'ImaticUserBundle') }}

@@ -48,4 +48,4 @@ {{ form_widget(form._token) }}
-{% endblock fos_user_content %} +{% endblock user_content %} diff --git a/Resources/views/Role/display.html.twig b/Resources/views/Role/display.html.twig index 028a628..15c079e 100644 --- a/Resources/views/Role/display.html.twig +++ b/Resources/views/Role/display.html.twig @@ -1,4 +1,4 @@ -{% extends 'base.html.twig' %} +{% extends '@ImaticView/Layout/base.html.twig' %} {% block action %}
diff --git a/Resources/views/Security/base_login.html.twig b/Resources/views/Security/base_login.html.twig old mode 100755 new mode 100644 index 5e746eb..e970494 --- a/Resources/views/Security/base_login.html.twig +++ b/Resources/views/Security/base_login.html.twig @@ -1,15 +1,15 @@ -{% extends "ImaticUserBundle::layout.html.twig" %} +{% extends "@ImaticUser/layout.html.twig" %} {% block headline 'layout.login'|trans({}, 'ImaticUserBundle') %} {% block action %} - {% block fos_user_content %} + {% block user_content %}