public function editProfileAction(Application $app, Request $request) { $data = array('login' => 'Login', 'password' => 'Password'); $usersModel = new UsersModel($app); $user = $usersModel->getCurrentUser($app); $id = $user['id']; $role = $user['role_id']; $data['id'] = $id; $data['role'] = $role; $form = $app['form.factory']->createBuilder(new EditProfileForm(), $data)->getForm(); $form->handleRequest($request); if ($form->isValid()) { $data = $form->getData(); $data['password'] = $app['security.encoder.digest']->encodePassword($data['password'], ''); $profileModel = new profilesModel($app); $profileModel->updateUser($data); $app['session']->getFlashBag()->add('message', array('type' => 'success', 'content' => $app['translator']->trans('Updated!'))); return $app->redirect($app['url_generator']->generate('auth_login'), 301); } $this->view['form'] = $form->createView(); return $app['twig']->render('profile/editProfile.twig', $this->view); }
public function changePasswordAction(Application $app, Request $request) { $usersModel = new UsersModel($app); $user = $usersModel->getCurrentUser($app); $form = $app['form.factory']->createBuilder(new ChangePasswordForm())->getForm(); $form->handleRequest($request); if ($form->isValid()) { $data = $form->getData(); $data['old_password'] = $app['security.encoder.digest']->encodePassword($data['old_password'], ''); if ($data['old_password'] == $user['password']) { unset($data['old_password']); $data['new_password'] = $app['security.encoder.digest']->encodePassword($data['new_password'], ''); $data['id'] = $user['id']; var_dump($data); $profileModel = new profilesModel($app); $profileModel->updatePassword($data); $app['session']->getFlashBag()->add('message', array('type' => 'success', 'content' => $app['translator']->trans('Password updated'))); return $app->redirect($app['url_generator']->generate('profile_index'), 301); } } $this->view['form'] = $form->createView(); return $app['twig']->render('profile/changePassword.twig', $this->view); }