diff --git a/src/Controller/AbstractSecurityController.php b/src/Controller/AbstractSecurityController.php index c76b0c4..1cf1251 100644 --- a/src/Controller/AbstractSecurityController.php +++ b/src/Controller/AbstractSecurityController.php @@ -2,7 +2,9 @@ namespace Smart\AuthenticationBundle\Controller; +use Smart\AuthenticationBundle\Security\Form\Type\UserProfileType; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; @@ -16,6 +18,18 @@ class AbstractSecurityController extends Controller * @var string */ protected $context; + + /** + * @param string $id The message id (may also be an object that can be cast to string) + * @param array $parameters An array of parameters for the message + * @param string|null $domain The domain for the message or null to use the default + * + * @return string + */ + protected function translate($id, array $parameters = array(), $domain = null) + { + return $this->get('translator')->trans($id, $parameters, $domain); + } /** * @return Response @@ -40,4 +54,42 @@ private function getAuthenticationUtils() { return $this->get('security.authentication_utils'); } + + /** + * @param Request $request + * + * @return Response + */ + public function profileAction(Request $request) + { + $user = $this->getUser(); + + $form = $this->createForm(UserProfileType::class, $user, []); + + $form->handleRequest($request); + + if (!$form->isSubmitted() || !$form->isValid()) { + return $this->render($this->context . '/security/profile.html.twig', [ + 'base_template' => $this->get('sonata.admin.pool')->getTemplate('layout'), + 'admin_pool' => $this->get('sonata.admin.pool'), + 'form' => $form->createView(), + 'security_profile_url' => $this->generateUrl('admin_security_profile'), + ]); + } + + if (null !== $user->getPlainPassword()) { + $encoder = $this->get('security.password_encoder'); + $user->setPassword( + $encoder->encodePassword($user, $user->getPlainPassword()) + ); + } + + $manager = $this->getDoctrine()->getManager(); + $manager->persist($user); + $manager->flush(); + + $this->addFlash('success', $this->translate('profile_edit.processed', [], 'security')); + + return $this->redirectToRoute('sonata_admin_dashboard'); + } } diff --git a/src/Resources/translations/admin.en.xlf b/src/Resources/translations/admin.en.xlf index 1cdfa3b..26b0ad8 100644 --- a/src/Resources/translations/admin.en.xlf +++ b/src/Resources/translations/admin.en.xlf @@ -18,6 +18,18 @@ form.label_last_name Lastname + + form.label_password + Password + + + form.label_password_confirmation + Password Confirmation + + + fieldset.label_profile + My profile + diff --git a/src/Resources/translations/admin.fr.xlf b/src/Resources/translations/admin.fr.xlf index 3c71788..f31f42f 100644 --- a/src/Resources/translations/admin.fr.xlf +++ b/src/Resources/translations/admin.fr.xlf @@ -18,6 +18,18 @@ form.label_last_name Nom + + form.label_password + Mot de passe + + + form.label_password_confirmation + Confirmation mot de passe + + + fieldset.label_profile + Mon compte + diff --git a/src/Resources/translations/security.en.xliff b/src/Resources/translations/security.en.xliff index 5cafd9f..a612089 100644 --- a/src/Resources/translations/security.en.xliff +++ b/src/Resources/translations/security.en.xliff @@ -42,6 +42,14 @@ user.action.logout Log out + + profile_edit.title + Edit your informations + + + profile_edit.processed + Informations updated. + diff --git a/src/Resources/translations/security.fr.xliff b/src/Resources/translations/security.fr.xliff index 4b4d68d..fb4dc31 100644 --- a/src/Resources/translations/security.fr.xliff +++ b/src/Resources/translations/security.fr.xliff @@ -42,6 +42,14 @@ user.action.logout Se déconnecter + + profile_edit.title + Modifier vos informations + + + profile_edit.processed + Vos informations ont été mise à jour. + diff --git a/src/Resources/views/block/user.html.twig b/src/Resources/views/block/user.html.twig index 04ceaec..57b8da8 100644 --- a/src/Resources/views/block/user.html.twig +++ b/src/Resources/views/block/user.html.twig @@ -1,9 +1,8 @@ {% trans_default_domain 'security' %} -