X-Git-Url: https://git.rapsys.eu/.gitweb.cgi/userbundle/blobdiff_plain/10322ae4af3fb083421e618c6c8f4b8dc0575126..refs/heads/master:/Controller/UserController.php diff --git a/Controller/UserController.php b/Controller/UserController.php index 3f3b5bf..c49c5de 100644 --- a/Controller/UserController.php +++ b/Controller/UserController.php @@ -13,13 +13,12 @@ namespace Rapsys\UserBundle\Controller; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; -use Rapsys\UserBundle\RapsysUserBundle; - use Symfony\Bridge\Twig\Mime\TemplatedEmail; use Symfony\Component\Form\FormError; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; +use Symfony\Component\HttpKernel\Exception\GoneHttpException; use Symfony\Component\Mailer\Exception\TransportExceptionInterface; use Symfony\Component\Mime\Address; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -37,7 +36,7 @@ class UserController extends AbstractController { */ public function index(Request $request): Response { //Without admin - if (!$this->checker->isGranted($this->config['default']['admin'])) { + if (!$this->checker->isGranted('ROLE_'.strtoupper($this->config['default']['admin']))) { //Throw 403 throw $this->createAccessDeniedException($this->translator->trans('Unable to list users', [], $this->alias)); } @@ -140,7 +139,7 @@ class UserController extends AbstractController { } //Prevent access when not admin, user is not guest and not currently logged user - if (!$this->checker->isGranted($this->config['default']['admin']) && $user != $this->security->getUser() || !$this->checker->isGranted('IS_AUTHENTICATED_FULLY')) { + if (!$this->checker->isGranted('ROLE_'.strtoupper($this->config['default']['admin'])) && $user != $this->security->getUser() || !$this->checker->isGranted('IS_AUTHENTICATED_FULLY')) { //Throw access denied //XXX: prevent slugger reverse engineering by not displaying decoded mail throw $this->createAccessDeniedException($this->translator->trans('Unable to access user', [], $this->alias)); @@ -155,17 +154,17 @@ class UserController extends AbstractController { //Set civility default 'civility_default' => $this->doctrine->getRepository($this->config['class']['civility'])->findOneByTitle($this->config['default']['civility']), //Disable mail - 'mail' => $this->checker->isGranted('ROLE_ADMIN'), + 'mail' => $this->checker->isGranted('ROLE_'.strtoupper($this->config['default']['admin'])), //Disable password 'password' => false, //Set method 'method' => 'POST', //Set domain 'translation_domain' => $this->alias - ]+($this->checker->isGranted($this->config['default']['admin'])?$this->config['edit']['admin']:$this->config['edit']['field'])); + ]+($this->checker->isGranted('ROLE_'.strtoupper($this->config['default']['admin']))?$this->config['edit']['admin']:$this->config['edit']['field'])); //With admin role - if ($this->checker->isGranted($this->config['default']['admin'])) { + if ($this->checker->isGranted('ROLE_'.strtoupper($this->config['default']['admin']))) { //Create the EditType form and give the proper parameters $reset = $this->factory->create($this->config['edit']['view']['reset'], $user, [ //Set action to edit route name and context @@ -238,7 +237,7 @@ class UserController extends AbstractController { } //Without admin role //XXX: prefer a reset on login to force user unspam action - } elseif (!$this->checker->isGranted($this->config['default']['admin'])) { + } elseif (!$this->checker->isGranted('ROLE_'.strtoupper($this->config['default']['admin']))) { //Add notice $this->addFlash('notice', $this->translator->trans('To change your password login with your mail and any password then follow the procedure', [], $this->alias)); } @@ -387,7 +386,7 @@ class UserController extends AbstractController { if ($pass != $this->slugger->hash($user->getPassword())) { //Throw not found //XXX: prevent use of outdated recover link - throw $this->createNotFoundException($this->translator->trans('Outdated recover link', [], $this->alias)); + throw new GoneHttpException($this->translator->trans('Outdated recover link', [], $this->alias)); } //Set context @@ -545,6 +544,7 @@ class UserController extends AbstractController { if (!empty($_POST['register']['mail'])) { //Log new user infos $this->logger->emergency( + //Translated register informations $this->translator->trans( 'register: mail=%mail% locale=%locale% confirm=%confirm% ip=%ip%', [ @@ -562,7 +562,12 @@ class UserController extends AbstractController { '%ip%' => $request->getClientIp() ], $this->alias - ) + ), + //Set context + [ + 'file' => __FILE__, + 'line' => __LINE__ + ] ); } @@ -586,7 +591,7 @@ class UserController extends AbstractController { 'method' => 'POST', //Set domain 'translation_domain' => $this->alias - ]+($this->checker->isGranted($this->config['default']['admin'])?$this->config['register']['admin']:$this->config['register']['field'])); + ]+($this->checker->isGranted('ROLE_'.strtoupper($this->config['default']['admin']))?$this->config['register']['admin']:$this->config['register']['field'])); //With post method if ($request->isMethod('POST')) {