/** * Deletes the profile with given uniqueness. * * @param string $uniqueness * * @throws NonExistentUniquenessSharedException */ public function delete($uniqueness) { $result = $this->connectToStorageInternalWorker->connect()->remove(array('uniqueness' => $uniqueness)); if ($result['n'] == 0) { throw new NonExistentUniquenessSharedException($uniqueness); } }
/** * Picks the profile with given uniqueness. * * @param string $uniqueness * * @return array * * @throws NonExistentUniquenessSharedException */ public function pick($uniqueness) { $profile = $this->connectToStorageInternalWorker->connect()->findOne(['uniqueness' => $uniqueness], ['_id' => 0]); if (!$profile) { throw new NonExistentUniquenessSharedException($uniqueness); } return $profile; }
/** * Creates a profile. * * @param string $uniqueness * @param string $password * * @throws ExistentUniquenessSharedException * @throws \MongoCursorException */ public function create($uniqueness, $password) { $salt = $this->generator->generate(); $hash = $this->encoder->encode($password, $salt); try { $this->connectToStorageInternalWorker->connect()->insert(['uniqueness' => $uniqueness, 'salt' => $salt, 'hash' => $hash]); } catch (\MongoCursorException $e) { if (11000 == $e->getCode()) { throw new ExistentUniquenessSharedException(); } throw $e; } }
/** * Collects authentication profiles. * * @return \Iterator */ public function collect() { return $this->connectToStorageInternalWorker->connect()->find()->fields(['_id' => 0]); }