function changePassword(Request $request, Application $app) { $form = $app['form.factory']->create(new UserChangePasswordForm()); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $data = $form->getData(); if (!$app['currentUser']->checkPassword($data['oldpassword'])) { $form->addError(new FormError('old password wrong')); } else { $app['currentUser']->setPassword($data['password1']); $userAccountRepository = new UserAccountRepository(); $userAccountRepository->editPassword($app['currentUser']); $app['flashmessages']->addMessage("Password Changed."); return $app['twig']->render('index/currentuser/changePasswordDone.html.twig', array()); } } } return $app['twig']->render('index/currentuser/changePassword.html.twig', array('form' => $form->createView())); }