/** * Create user object * * @return \Closure */ private function _createUserObject() { return function (Request $request, Application $app) { $user_data = null; if (in_array('user', $app->keys())) { $user_data = $app['user']; } /** @var User $user */ $user = new User(); if ($request->attributes->has('user_id')) { $user->setUserId($request->attributes->get('user_id')); } if ($user_data) { $user->setEmail($user_data['email']); $user->setFirstname($user_data['firstname']); $user->setLastname($user_data['lastname']); $user->setPassword(PasswordHash::hash($user_data['password'])); } $app['user'] = $user; }; }
/** * Change password * * @throws WrongPasswordException * @throws ErrorException */ public function changePassword() { /** @var User $user */ $user = $this->app['user']; //User $result_user = $this->getUser(); //Check password $check_password = PasswordHash::verify($user->getOldPassword(), $result_user['password']); if (!$check_password) { throw new WrongPasswordException(); } //Update user $this->db->beginTransaction(); try { $query_builder = $query_builder = $this->db->createQueryBuilder(); $qb = $query_builder->update('user')->set('password', $query_builder->expr()->literal($user->getPassword()))->where('user_id = :user_id')->setParameters(array(':user_id' => $user->getUserId())); $qb->execute(); $this->db->commit(); } catch (DBALException $e) { $this->db->rollBack(); throw new ErrorException(); } }