Пример #1
0
 public function processUserRegistration(Form $form)
 {
     $values = $form->getValues();
     $forbiddenNames = array_flip(['systém', 'system', 'admin', 'administrator', 'administrátor']);
     if (array_key_exists(strtolower($values['username']), $forbiddenNames)) {
         $form->addError('Vámi zadané jméno nelze použít. Vyberte si prosím jiné.');
         return;
     }
     $values['ip'] = $this->getHttpRequest()->getRemoteAddress();
     $values['role'] = 'employee';
     $user = new User($values['username'], $values['password'], $values['email'], $values['ip'], $this->invitation->getSender(), $values['role']);
     try {
         $this->usersFacade->registerNewUser($user, $this->invitation);
         $this->flashMessage('Váš účet byl vytvořen. Nyní se můžete přihlásit.', 'success');
         $this->redirect('Login:default');
     } catch (InvitationValidityException $iu) {
         $this->flashMessage('Registrovat se může pouze uživatel s platnou pozvánkou.', 'warning');
         $this->redirect('Login:default');
     } catch (InvalidUserInvitationEmailException $iue) {
         $form->addError('Nesouhlasí Vámi zadaný E-mail a E-mail vázaný na pozvánku.');
     } catch (\Exceptions\Runtime\DuplicateUsernameException $du) {
         $form->addError('Vámi zvolené jméno využívá již někdo jiný. Vyberte si prosím jiné jméno.');
     } catch (\Exceptions\Runtime\DuplicateEmailException $de) {
         $this->flashMessage('E-mail svázaný s pozvánkou využívá již jeden z registrovaných
              uživatelů. Nechte si zaslat novou pozvánku s jinou E-mailovou adresou.', 'warning');
         $this->redirect('Login:default');
     } catch (DBALException $d) {
         $form->addError('Registraci nelze dokončit. Zkuste to prosím později.');
     }
 }
 /**
  * @param Invitation $invitation
  * @throws InvitationExpiredException
  * @throws SendException
  */
 public function sendInvitation(Invitation $invitation)
 {
     try {
         $this->emailNotifier->send('Výčetkový systém <' . $this->systemEmail . '>', $invitation->email, function (ITemplate $template, Invitation $invitation, $senderName, $applicationUrl) {
             $template->setFile(__DIR__ . '/../../model/Notifications/templates/invitation.latte');
             $template->invitation = $invitation;
             $template->username = $senderName;
             $template->applicationUrl = $applicationUrl;
         }, [$invitation, $invitation->getSender()->username, $this->applicationUrl]);
     } catch (SendException $e) {
         $this->onCritical(sprintf('Invitation sending failed. [%s]', $invitation->getEmail()), $e, self::class);
         throw $e;
     }
 }
Пример #3
0
 /**
  * @param User $user
  * @param Invitation $invitation
  * @return User
  * @throws InvalidUserInvitationEmailException
  * @throws InvitationNotFoundException
  * @throws InvitationExpiredException
  * @throws DuplicateEmailException
  * @throws DuplicateUsernameException
  */
 public function registerNewUser(User $user, Invitation $invitation)
 {
     if ($user->email !== $invitation->email) {
         throw new InvalidUserInvitationEmailException();
     }
     if (!$invitation->isActive()) {
         throw new InvitationExpiredException();
     }
     return $this->userSystemCreator->registerUser($user, $invitation);
 }
 /**
  * @param Invitation $invitation
  */
 private function checkInvitationState(Invitation $invitation)
 {
     if (!$invitation->isActive()) {
         throw new InvitationExpiredException();
     }
 }
 public function onAfterInvitationSending(Invitation $invitation)
 {
     $invitation->setLastSendingTime();
     $this->invitationsFacade->saveInvitation($invitation);
 }