fix errors when creating user and updating password

This commit is contained in:
2018-09-04 16:55:34 +02:00
parent 04bdaa308a
commit e88265adcd
4 changed files with 46 additions and 18 deletions

View File

@@ -50,7 +50,7 @@ class UserController extends Controller
$em = $this->getDoctrine()->getManager();
$user->setPassword($this->get('security.password_encoder')
->encodePassword($user, $form['plainPassword']['password']->getData()));
->encodePassword($user, $form['plainPassword']->getData()));
$em->persist($user);
$em->flush();
@@ -177,12 +177,14 @@ class UserController extends Controller
*/
private function createEditPasswordForm(User $user)
{
return $this->createForm(UserPasswordType::class, $user, array(
'action' =>
$this->generateUrl('admin_user_update_password', array('id' => $user->getId())),
'method' => 'PUT'
))
->add('submit', SubmitType::class, array('label' => 'Change password'))
return $this->createForm(UserPasswordType::class, null, array(
'action' =>
$this->generateUrl('admin_user_update_password', array('id' => $user->getId())),
'method' => 'PUT',
'user' => $user
))
->add('submit', SubmitType::class, array('label' => 'Change password'))
->remove('actual_password')
;
}
@@ -356,15 +358,13 @@ class UserController extends Controller
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$password = $editForm->getData()->getPassword();
$password = $editForm->get('new_password')->getData();
// logging for debug !! WARNING print the new password !!
$this->get('logger')->debug('update password for an user',
array('method' => __METHOD__, 'password' => $password,
'user' => $user->getUsername()));
// logging for prod
$this->get('logger')->info('update password for an user',
array('method' => __METHOD__, 'user' => $user->getUsername()));
$this->get('logger')->info('update password for an user', [
'by' => $this->getUser()->getUsername(),
'user' => $user->getUsername()
]);
$user->setPassword($this->get('security.password_encoder')
->encodePassword($user, $password));