syncData() 공개 메소드

Syncronizes the data of the given user with the FOSRestBundle.
public syncData ( User $user )
$user PartKeepr\AuthBundle\Entity\User
예제 #1
0
 /**
  * Create a new item.
  *
  * @param Request    $request
  * @param string|int $id
  *
  * @throws NotFoundHttpException
  * @throws RuntimeException
  * @throws UserProtectedException
  * @throws UserLimitReachedException
  *
  * @return mixed
  */
 public function __invoke(Request $request, $id)
 {
     /**
      * @var ResourceInterface
      */
     list($resourceType, $format) = $this->extractAttributes($request);
     /**
      * @var User
      */
     $data = $this->getItem($this->dataProvider, $resourceType, $id);
     $context = $resourceType->getDenormalizationContext();
     $context['object_to_populate'] = $data;
     if ($data->isProtected()) {
         throw new UserProtectedException();
     }
     $data = $this->serializer->deserialize($request->getContent(), $resourceType->getEntityClass(), $format, $context);
     if ($data->isActive()) {
         if ($this->userService->checkUserLimit()) {
             throw new UserLimitReachedException();
         }
     }
     $this->userService->syncData($data);
     $data->setNewPassword('');
     $data->setPassword('');
     $data->setLegacy(false);
     return $data;
 }
예제 #2
0
 public function __invoke(Request $request)
 {
     if ($this->container->hasParameter('partkeepr.auth.allow_password_change') && $this->container->getParameter('partkeepr.auth.allow_password_change') === false) {
         throw new PasswordChangeNotAllowedException();
     }
     $user = $this->userService->getUser();
     if (!$request->request->has('oldpassword') && !$request->request->has('newpassword')) {
         throw new \Exception('old password and new password need to be specified');
     }
     $FOSUser = $this->userManager->findUserByUsername($user->getUsername());
     if ($FOSUser !== null) {
         $encoder = $this->encoderFactory->getEncoder($FOSUser);
         $encoded_pass = $encoder->encodePassword($request->request->get('oldpassword'), $FOSUser->getSalt());
         if ($FOSUser->getPassword() != $encoded_pass) {
             throw new OldPasswordWrongException();
         }
         $this->userManipulator->changePassword($user->getUsername(), $request->request->get('newpassword'));
     } else {
         if ($user->isLegacy()) {
             if ($user->getPassword() !== md5($request->request->get('oldpassword'))) {
                 throw new OldPasswordWrongException();
             }
             $user->setNewPassword($request->request->get('newpassword'));
             $this->userService->syncData($user);
         } else {
             throw new \Exception('Cannot change password for LDAP users');
         }
     }
     $user->setPassword('');
     $user->setNewPassword('');
     return $user;
 }
예제 #3
0
 /**
  * Create a new item.
  *
  * @param Request $request
  *
  * @return mixed
  *
  * @throws NotFoundHttpException
  * @throws RuntimeException
  * @throws UserLimitReachedException
  */
 public function __invoke(Request $request)
 {
     /**
      * @var $resourceType ResourceInterface
      */
     list($resourceType, $format) = $this->extractAttributes($request);
     if ($this->userService->checkUserLimit() === true) {
         throw new UserLimitReachedException();
     }
     /**
      * @var User $data
      */
     $data = $this->serializer->deserialize($request->getContent(), $resourceType->getEntityClass(), $format, $resourceType->getDenormalizationContext());
     $data->setProvider($this->userService->getBuiltinProvider());
     $data->setLegacy(false);
     $this->userService->syncData($data);
     $data->setNewPassword("");
     $data->setPassword("");
     return $data;
 }