Exemplo n.º 1
0
 public function registerUser(array $data, array $selectedCollections = null, $providerId = null)
 {
     $provider = null;
     if ($providerId !== null) {
         $provider = $this->oauthProviderCollection->get($providerId);
     }
     $inscriptions = $this->registrationManager->getRegistrationSummary();
     $authorizedCollections = $this->getAuthorizedCollections($selectedCollections, $inscriptions);
     if (!isset($data['login'])) {
         $data['login'] = $data['email'];
     }
     $user = $this->userManipulator->createUser($data['login'], $data['password'], $data['email'], false);
     if (isset($data['geonameid'])) {
         $this->userManipulator->setGeonameId($user, $data['geonameid']);
     }
     foreach (self::$userPropertySetterMap as $property => $method) {
         if (isset($data[$property])) {
             call_user_func(array($user, $method), $data[$property]);
         }
     }
     $this->entityManager->persist($user);
     $this->entityManager->flush($user);
     if (null !== $provider) {
         $this->attachProviderToUser($provider, $user);
         $this->entityManager->flush();
     }
     $this->applyAclsToUser($authorizedCollections, $user);
     $this->createCollectionAccessDemands($user, $authorizedCollections);
     $user->setMailLocked(true);
     return $user;
 }
Exemplo n.º 2
0
 public function resetPassword($resetToken, $newPassword)
 {
     $token = $this->tokenRepository->findValidToken($resetToken);
     if ($token === null || $token->getType() != TokenManipulator::TYPE_PASSWORD) {
         $this->application->abort(401, 'A token is required');
     }
     $this->userManipulator->setPassword($token->getUser(), $newPassword);
     $this->tokenManipulator->delete($token);
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getUsrId($username, $password, Request $request)
 {
     if (null === ($user = $this->repository->findRealUserByLogin($username))) {
         return null;
     }
     if ($user->isSpecial()) {
         return null;
     }
     // check locked account
     if ($user->isMailLocked()) {
         throw new AccountLockedException('The account is locked', $user->getId());
     }
     if (false === $user->isSaltedPassword()) {
         // we need a quick update and continue
         if ($this->oldEncoder->isPasswordValid($user->getPassword(), $password, $user->getNonce())) {
             $this->userManipulator->setPassword($user, $password);
         }
     }
     if (false === $this->encoder->isPasswordValid($user->getPassword(), $password, $user->getNonce())) {
         return null;
     }
     return $user->getId();
 }
Exemplo n.º 4
0
 public function testInvalidGeonamedId()
 {
     $manager = $this->getMockBuilder('Alchemy\\Phrasea\\Model\\Manager\\UserManager')->disableOriginalConstructor()->getMock();
     $geoname = $this->getMockBuilder('Alchemy\\Geonames\\Geoname')->disableOriginalConstructor()->getMock();
     $geoname->expects($this->once())->method('get')->with($this->equalTo('country'))->will($this->returnValue(['code' => 'fr']));
     $geonamesConnector = $this->getMockBuilder('Alchemy\\Geonames\\Connector')->disableOriginalConstructor()->getMock();
     $geonamesConnector->expects($this->once())->method('geoname')->with($this->equalTo(-1))->will($this->returnValue($geoname));
     $passwordInterface = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface')->getMock();
     $user = self::$DI['app']['manipulator.user']->createUser('login', 'password');
     $manipulator = new UserManipulator($manager, $passwordInterface, $geonamesConnector, self::$DI['app']['repo.tasks'], self::$DI['app']['random.low']);
     $this->setExpectedException('Alchemy\\Phrasea\\Exception\\InvalidArgumentException', 'Invalid geonameid -1.');
     $manipulator->setGeonameId($user, -1);
 }
Exemplo n.º 5
0
 /**
  * @param string $login
  * @throws AccountException
  */
 public function deleteAccount($login = null)
 {
     $user = $this->getUserOrCurrentUser($login);
     $this->userManipulator->delete($user);
 }