From: Raphaƫl Gertz Date: Sat, 28 Aug 2021 11:08:22 +0000 (+0200) Subject: Set slug with pseudonym and empty slug X-Git-Tag: 0.2.0~3 X-Git-Url: https://git.rapsys.eu/airbundle/commitdiff_plain/aa959195ee41ca2ce08b87214b84612847f0bbed?hp=5ef395b0614118645c4f4776eb24ddb4a9dedec0 Set slug with pseudonym and empty slug Improve reset password notice display conditions --- diff --git a/Controller/UserController.php b/Controller/UserController.php index 6385828..b4f5765 100644 --- a/Controller/UserController.php +++ b/Controller/UserController.php @@ -49,15 +49,6 @@ class UserController extends DefaultController { throw $this->createAccessDeniedException($this->translator->trans('Unable to access user: %mail%', ['%mail%' => $smail])); } - //With admin - if ($this->isGranted('ROLE_ADMIN')) { - //With pseudonym and without slug - if (!empty($pseudonym = $user->getPseudonym()) && empty($user->getSlug())) { - //Preset slug - $user->setSlug($slugger->slug($pseudonym)); - } - } - //Create the RegisterType form and give the proper parameters $edit = $this->createForm($this->config['edit']['view']['edit'], $user, [ //Set action to register route name and context @@ -119,11 +110,6 @@ class UserController extends DefaultController { //Add reset view $this->config['edit']['view']['context']['reset'] = $reset->createView(); - //Without admin role - //XXX: prefer a reset on login to force user unspam action - } else { - //Add notice - $this->addFlash('notice', $this->translator->trans('To change your password login with your mail and any password then follow the procedure')); } //With post method @@ -136,6 +122,15 @@ class UserController extends DefaultController { //Set data $data = $edit->getData(); + //With admin + if ($this->isGranted('ROLE_ADMIN')) { + //With pseudonym and without slug + if (!empty($pseudonym = $data->getPseudonym()) && empty($data->getSlug())) { + //Set slug + $data->setSlug($slugger->slug($pseudonym)); + } + } + //Queue snippet save $manager->persist($data); @@ -152,9 +147,14 @@ class UserController extends DefaultController { //Catch double slug or mail } catch (UniqueConstraintViolationException $e) { //Add error message mail already exists - $this->addFlash('error', $this->translator->trans('Account %mail% or with slug %slug% already exists', ['%mail%' => $data->getMail(), '%slug%' => $slug])); + $this->addFlash('error', $this->translator->trans('Account %mail% already exists', ['%mail%' => $data->getMail()])); } } + //Without admin role + //XXX: prefer a reset on login to force user unspam action + } elseif (!$this->isGranted('ROLE_ADMIN')) { + //Add notice + $this->addFlash('notice', $this->translator->trans('To change your password login with your mail and any password then follow the procedure')); } //Render view