Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/Controller/UserController.php b/Controller/UserController.php
- index 624b9e7..c4f8f14 100644
- --- a/Controller/UserController.php
- +++ b/Controller/UserController.php
- @@ -86,7 +86,7 @@ class UserController extends Controller
- if ($data = $this->get('request')->request->get($form->getName())) {
- $form->bind($data);
- if ($form->isValid()) {
- - $this->saveUser($user);
- + $this->get('fos_user.user_manager')->updateUser($user);
- $this->get('session')->setFlash('fos_user_user_update', 'success');
- $userUrl = $this->generateUrl('fos_user_user_show', array('username' => $user->getUsername()));
- return $this->redirect($userUrl);
- @@ -124,12 +124,12 @@ class UserController extends Controller
- $user = $form->getData();
- if ($this->container->getParameter('fos_user.confirmation_email.enabled')) {
- $user->setEnabled(false);
- - $this->saveUser($user);
- + $this->get('fos_user.user_manager')->updateUser($user);
- $this->get('session')->set('fos_user_send_confirmation_email/email', $user->getEmail());
- $url = $this->generateUrl('fos_user_user_send_confirmation_email');
- } else {
- $user->setEnabled(true);
- - $this->saveUser($user);
- + $this->get('fos_user.user_manager')->updateUser($user);
- $this->authenticateUser($user);
- $url = $this->generateUrl('fos_user_user_confirmed');
- }
- @@ -205,7 +205,7 @@ class UserController extends Controller
- $user->setConfirmationToken(null);
- $user->setEnabled(true);
- - $this->saveUser($user);
- + $this->get('fos_user.user_manager')->updateUser($user);
- $this->authenticateUser($user);
- return $this->redirect($this->generateUrl('fos_user_user_confirmed'));
- @@ -329,24 +329,6 @@ class UserController extends Controller
- }
- /**
- - * Save a user in database
- - *
- - * @param User $user
- - * @return null
- - **/
- - public function saveUser(User $user)
- - {
- - if (0 !== strlen($password = $user->getPlainPassword())) {
- - $encoder = $this->get('fos_user.encoder');
- - $user->setAlgorithm($this->container->getParameter('fos_user.encoder.algorithm'));
- - $user->setPassword($encoder->encodePassword($password, $user->getSalt()));
- - $user->eraseCredentials();
- - }
- -
- - $this->get('fos_user.user_manager')->updateUser($user);
- - }
- -
- - /**
- * Authenticate a user with Symfony Security
- *
- * @return null
- @@ -387,4 +369,4 @@ class UserController extends Controller
- {
- return $this->container->getParameter('fos_user.template.renderer');
- }
- -}
- \ No newline at end of file
- +}
- diff --git a/Document/UserManager.php b/Document/UserManager.php
- index e93e7af..3c47fb5 100644
- --- a/Document/UserManager.php
- +++ b/Document/UserManager.php
- @@ -47,7 +47,9 @@ class UserManager extends BaseUserManager
- public function updateUser(BaseUser $user)
- {
- + $this->updatePassword($user);
- +
- $this->dm->persist($user);
- $this->dm->flush();
- }
- -}
- \ No newline at end of file
- +}
- diff --git a/Entity/UserManager.php b/Entity/UserManager.php
- index 41e4762..9f9a51c 100644
- --- a/Entity/UserManager.php
- +++ b/Entity/UserManager.php
- @@ -12,14 +12,19 @@ class UserManager extends BaseUserManager
- protected $em;
- protected $class;
- protected $repository;
- + protected $encoder;
- + protected $algorithm;
- - public function __construct(EntityManager $em, $class)
- + public function __construct(EntityManager $em, $class, $encoder, $algorithm)
- {
- $this->em = $em;
- $this->repository = $em->getRepository($class);
- $metadata = $em->getClassMetadata($class);
- $this->class = $metadata->namespace.'\\'.$metadata->name;
- +
- + $this->encoder = $encoder;
- + $this->algorithm = $algorithm;
- }
- public function deleteUser(BaseUser $user)
- @@ -57,7 +62,9 @@ class UserManager extends BaseUserManager
- */
- public function updateUser(BaseUser $user)
- {
- + $this->updatePassword($user);
- +
- $this->em->persist($user);
- $this->em->flush();
- }
- -}
- \ No newline at end of file
- +}
- diff --git a/Model/UserManager.php b/Model/UserManager.php
- index b69571c..679e712 100644
- --- a/Model/UserManager.php
- +++ b/Model/UserManager.php
- @@ -107,4 +107,16 @@ abstract class UserManager implements UserManagerInterface, UserProviderInterfac
- return $user;
- }
- -}
- \ No newline at end of file
- +
- + /**
- + * {@inheritDoc}
- + */
- + public function updatePassword(BaseUser $user)
- + {
- + if (0 !== strlen($password = $user->getPlainPassword())) {
- + $user->setAlgorithm($this->algorithm);
- + $user->setPassword($this->encoder->encodePassword($password, $user->getSalt()));
- + $user->eraseCredentials();
- + }
- + }
- +}
- diff --git a/Model/UserManagerInterface.php b/Model/UserManagerInterface.php
- index e667e7a..c2e26ef 100644
- --- a/Model/UserManagerInterface.php
- +++ b/Model/UserManagerInterface.php
- @@ -101,4 +101,13 @@ interface UserManagerInterface
- * @return void
- */
- function updateUser(User $user);
- +
- + /**
- + * Updates a user password if a plain password is set
- + *
- + * @SecureParam(name="user", permissions="EDIT")
- + * @param User $user
- + * @return void
- + */
- + function updatePassword(User $user);
- }
- diff --git a/Resources/config/user.xml b/Resources/config/user.xml
- index b296d56..035ad6f 100644
- --- a/Resources/config/user.xml
- +++ b/Resources/config/user.xml
- @@ -12,6 +12,8 @@
- <service id="fos_user.user_manager" class="%fos_user.user_manager.class%">
- <argument type="service" id="fos_user.object_manager" />
- <argument>%fos_user.model.user.class%</argument>
- + <argument type="service" id="fos_user.encoder" />
- + <argument>%fos_user.encoder.algorithm%</argument>
- </service>
- </services>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement