/** * Find settings by given id * * @param string $id * @return Newscoop\News\Settings */ public function find($id) { $settings = $this->repository->find($id); if ($settings === null) { $settings = new Settings(); } return $settings; }
/** * Authenticate a user * @return Zend\Authentication\Result Result */ public function authenticate() { $user = $this->userDocumentRepository->findOneByEmail($this->email); if (empty($user)) { return new Result(Result::FAILURE_IDENTITY_NOT_FOUND, [], ['No user exists with the credentials provided']); } if (!password_verify($this->password, $user->key)) { return new Result(Result::FAILURE_CREDENTIAL_INVALID, [], ['Wrong Credentials ']); } return new Result(Result::SUCCESS, $user->id, []); }
/** * Performs an authentication * @param array * @return Nette\Security\Identity * @throws Nette\Security\AuthenticationException */ public function authenticate(array $credentials) { list($email, $password) = $credentials; $user = $this->usersRepository->findOneBy(array('email' => $email)); if (!$user or !password_verify($password, $user->getPassword())) { throw new NS\AuthenticationException("Invalid credentials", self::FAILURE); } elseif (!$user->isActive()) { throw new NS\AuthenticationException("Your account hasn't been activated yet.", self::FAILURE); } $user->setAccountRule(AccountRules::getRuleForAccount($user->getAccount())); return $user; }
/** * Save item * * @param Newscoop\News\Item $item * @return void */ public function save(Item $item) { $persisted = $this->repository->find($item->getId()); if ($persisted !== null) { if ($item->getVersion() < $persisted->getVersion()) { return; } else { // @todo handle append signal $this->odm->remove($persisted); $this->odm->flush(); } } if ($item->isCanceled()) { return; } $this->odm->persist($item); $this->odm->flush(); }