/** * @param SentMessage $message * @param array $recipientsIDs * @return NewMessageResultObject * @throws \Exception */ public function sendMessage(SentMessage $message, array $recipientsIDs) { $recipients = $this->usersReader->findUsersByIDs($recipientsIDs); $messageResult = new NewMessageResultObject($message); $references = $this->messagesWriter->sendMessage($message, $recipients); $messageResult->addMessageReferences($references); return $messageResult; }
/** * Performs an authentication against e.g. database. * and returns IIdentity on success or throws AuthenticationException * @return IIdentity * @throws AuthenticationException * @throws InaccessibleAccountException */ public function authenticate(array $credentials) { list($email, $password) = $credentials; $user = $this->usersReader->getUserByEmail($email); if ($user === null) { throw new AuthenticationException('Zadali jste špatný email.'); } if (!Passwords::verify($password, $user->password)) { throw new AuthenticationException('Zadali jste špatné heslo.'); } elseif (Passwords::needsRehash($user->password)) { $user->password = Passwords::hash($password); } if (!$user->isUserAccountAccessible()) { throw new InaccessibleAccountException(); // user is banned } $this->onLoggedIn($user); return new FakeIdentity($user->getId(), get_class($user)); }
/** * @param Invitation $invitation * @return EntityResultObject * @throws InvitationAlreadyExistsException * @throws UserAlreadyExistsException */ public function createInvitation(Invitation $invitation) { $isEmailRegistered = $this->usersReader->isEmailRegistered($invitation->email); if ($isEmailRegistered === true) { throw new UserAlreadyExistsException(); } $this->invitationsHandler->process($invitation); $resultObject = new EntityResultObject($invitation); $this->onInvitationCreation($invitation, $resultObject); return $resultObject; }
/** * @param Listing $listing * @param int $recipientID * @param $description * @param array|null $ignoredListingDays * @return EntityResultObject * @throws RecipientsNotFoundException * @throws \Exception */ public function shareListing(Listing $listing, $recipientID, $description, array $ignoredListingDays = []) { $recipient = $this->usersReader->findUsersByIDs([$recipientID]); if (empty($recipient)) { throw new RecipientsNotFoundException(); } $newListing = $this->listingsManager->shareListing($listing, $recipient[0], $description, $ignoredListingDays); $resultObject = new EntityResultObject($newListing); $this->onListingSharing($newListing, $listing->getUser(), $resultObject); return $resultObject; }
/** * @param User $newUser * @param Invitation $invitation * @return User * @throws DuplicateUsernameException * @throws DuplicateEmailException * @throws InvalidUserInvitationEmailException */ public function registerUser(User $newUser, Invitation $invitation) { if ($newUser->email !== $invitation->email) { throw new InvalidUserInvitationEmailException(); } $this->em->beginTransaction(); $user = $this->em->safePersist($newUser); if ($user === false) { $this->em->rollback(); // e.g. when two users are trying to register // at the same time on the same Invitation if ($this->usersReader->isEmailRegistered($newUser->email)) { $this->invitationsWriter->removeInvitation($invitation); throw new DuplicateEmailException(); } if ($this->usersReader->isUsernameRegistered($newUser->username)) { throw new DuplicateUsernameException(); } } $this->invitationsWriter->removeInvitation($invitation); $this->em->commit(); return $user; }
/** * @param User $user * @return mixed */ public function getTotalWorkedStatistics(User $user) { return $this->usersReader->getTotalWorkedStatistics($user); }