Advertisement
Guest User

Untitled

a guest
Jul 8th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.21 KB | None | 0 0
  1. diff --git a/Controller/UserController.php b/Controller/UserController.php
  2. index 624b9e7..c4f8f14 100644
  3. --- a/Controller/UserController.php
  4. +++ b/Controller/UserController.php
  5. @@ -86,7 +86,7 @@ class UserController extends Controller
  6. if ($data = $this->get('request')->request->get($form->getName())) {
  7. $form->bind($data);
  8. if ($form->isValid()) {
  9. - $this->saveUser($user);
  10. + $this->get('fos_user.user_manager')->updateUser($user);
  11. $this->get('session')->setFlash('fos_user_user_update', 'success');
  12. $userUrl = $this->generateUrl('fos_user_user_show', array('username' => $user->getUsername()));
  13. return $this->redirect($userUrl);
  14. @@ -124,12 +124,12 @@ class UserController extends Controller
  15. $user = $form->getData();
  16. if ($this->container->getParameter('fos_user.confirmation_email.enabled')) {
  17. $user->setEnabled(false);
  18. - $this->saveUser($user);
  19. + $this->get('fos_user.user_manager')->updateUser($user);
  20. $this->get('session')->set('fos_user_send_confirmation_email/email', $user->getEmail());
  21. $url = $this->generateUrl('fos_user_user_send_confirmation_email');
  22. } else {
  23. $user->setEnabled(true);
  24. - $this->saveUser($user);
  25. + $this->get('fos_user.user_manager')->updateUser($user);
  26. $this->authenticateUser($user);
  27. $url = $this->generateUrl('fos_user_user_confirmed');
  28. }
  29. @@ -205,7 +205,7 @@ class UserController extends Controller
  30. $user->setConfirmationToken(null);
  31. $user->setEnabled(true);
  32.  
  33. - $this->saveUser($user);
  34. + $this->get('fos_user.user_manager')->updateUser($user);
  35. $this->authenticateUser($user);
  36.  
  37. return $this->redirect($this->generateUrl('fos_user_user_confirmed'));
  38. @@ -329,24 +329,6 @@ class UserController extends Controller
  39. }
  40.  
  41. /**
  42. - * Save a user in database
  43. - *
  44. - * @param User $user
  45. - * @return null
  46. - **/
  47. - public function saveUser(User $user)
  48. - {
  49. - if (0 !== strlen($password = $user->getPlainPassword())) {
  50. - $encoder = $this->get('fos_user.encoder');
  51. - $user->setAlgorithm($this->container->getParameter('fos_user.encoder.algorithm'));
  52. - $user->setPassword($encoder->encodePassword($password, $user->getSalt()));
  53. - $user->eraseCredentials();
  54. - }
  55. -
  56. - $this->get('fos_user.user_manager')->updateUser($user);
  57. - }
  58. -
  59. - /**
  60. * Authenticate a user with Symfony Security
  61. *
  62. * @return null
  63. @@ -387,4 +369,4 @@ class UserController extends Controller
  64. {
  65. return $this->container->getParameter('fos_user.template.renderer');
  66. }
  67. -}
  68. \ No newline at end of file
  69. +}
  70. diff --git a/Document/UserManager.php b/Document/UserManager.php
  71. index e93e7af..3c47fb5 100644
  72. --- a/Document/UserManager.php
  73. +++ b/Document/UserManager.php
  74. @@ -47,7 +47,9 @@ class UserManager extends BaseUserManager
  75.  
  76. public function updateUser(BaseUser $user)
  77. {
  78. + $this->updatePassword($user);
  79. +
  80. $this->dm->persist($user);
  81. $this->dm->flush();
  82. }
  83. -}
  84. \ No newline at end of file
  85. +}
  86. diff --git a/Entity/UserManager.php b/Entity/UserManager.php
  87. index 41e4762..9f9a51c 100644
  88. --- a/Entity/UserManager.php
  89. +++ b/Entity/UserManager.php
  90. @@ -12,14 +12,19 @@ class UserManager extends BaseUserManager
  91. protected $em;
  92. protected $class;
  93. protected $repository;
  94. + protected $encoder;
  95. + protected $algorithm;
  96.  
  97. - public function __construct(EntityManager $em, $class)
  98. + public function __construct(EntityManager $em, $class, $encoder, $algorithm)
  99. {
  100. $this->em = $em;
  101. $this->repository = $em->getRepository($class);
  102.  
  103. $metadata = $em->getClassMetadata($class);
  104. $this->class = $metadata->namespace.'\\'.$metadata->name;
  105. +
  106. + $this->encoder = $encoder;
  107. + $this->algorithm = $algorithm;
  108. }
  109.  
  110. public function deleteUser(BaseUser $user)
  111. @@ -57,7 +62,9 @@ class UserManager extends BaseUserManager
  112. */
  113. public function updateUser(BaseUser $user)
  114. {
  115. + $this->updatePassword($user);
  116. +
  117. $this->em->persist($user);
  118. $this->em->flush();
  119. }
  120. -}
  121. \ No newline at end of file
  122. +}
  123. diff --git a/Model/UserManager.php b/Model/UserManager.php
  124. index b69571c..679e712 100644
  125. --- a/Model/UserManager.php
  126. +++ b/Model/UserManager.php
  127. @@ -107,4 +107,16 @@ abstract class UserManager implements UserManagerInterface, UserProviderInterfac
  128.  
  129. return $user;
  130. }
  131. -}
  132. \ No newline at end of file
  133. +
  134. + /**
  135. + * {@inheritDoc}
  136. + */
  137. + public function updatePassword(BaseUser $user)
  138. + {
  139. + if (0 !== strlen($password = $user->getPlainPassword())) {
  140. + $user->setAlgorithm($this->algorithm);
  141. + $user->setPassword($this->encoder->encodePassword($password, $user->getSalt()));
  142. + $user->eraseCredentials();
  143. + }
  144. + }
  145. +}
  146. diff --git a/Model/UserManagerInterface.php b/Model/UserManagerInterface.php
  147. index e667e7a..c2e26ef 100644
  148. --- a/Model/UserManagerInterface.php
  149. +++ b/Model/UserManagerInterface.php
  150. @@ -101,4 +101,13 @@ interface UserManagerInterface
  151. * @return void
  152. */
  153. function updateUser(User $user);
  154. +
  155. + /**
  156. + * Updates a user password if a plain password is set
  157. + *
  158. + * @SecureParam(name="user", permissions="EDIT")
  159. + * @param User $user
  160. + * @return void
  161. + */
  162. + function updatePassword(User $user);
  163. }
  164. diff --git a/Resources/config/user.xml b/Resources/config/user.xml
  165. index b296d56..035ad6f 100644
  166. --- a/Resources/config/user.xml
  167. +++ b/Resources/config/user.xml
  168. @@ -12,6 +12,8 @@
  169. <service id="fos_user.user_manager" class="%fos_user.user_manager.class%">
  170. <argument type="service" id="fos_user.object_manager" />
  171. <argument>%fos_user.model.user.class%</argument>
  172. + <argument type="service" id="fos_user.encoder" />
  173. + <argument>%fos_user.encoder.algorithm%</argument>
  174. </service>
  175. </services>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement