Exemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var QuestionHelper $questionHelper */
     $questionHelper = $this->getHelper('question');
     $usernameQuestion = new Question('E-mail: ');
     $usernameQuestion->setValidator(function ($value) {
         if (trim($value) === '') {
             throw new \Exception('E-mail can not be empty');
         }
         if (!Validators::isEmail($value)) {
             throw new \Exception('E-mail is not valid');
         }
         return $value;
     });
     $passwordQuestion = new Question('Password: '******'') {
             throw new \Exception('The password can not be empty');
         }
         return $value;
     });
     $passwordQuestion->setHidden(TRUE);
     $passwordQuestion->setHiddenFallback(FALSE);
     $username = $questionHelper->ask($input, $output, $usernameQuestion);
     $password = $questionHelper->ask($input, $output, $passwordQuestion);
     $name = $questionHelper->ask($input, $output, new Question('Name: '));
     $user = $this->userFacade->add($username, $password, $name);
     $output->writeln('User ' . $user->getEmail() . ' was successfully created!');
 }
Exemplo n.º 2
0
 function signUpFormValidated(\Nette\Forms\BootstrapUIForm $form)
 {
     $userCorrects = preg_match("/^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_]{4,40}\$/", $form->getValues()->username, $userTest);
     $member = new \App\Model\MemberModel($this->database);
     $userExists = $member->getUserName($form->values->username);
     $emailExists = $member->getEmail($form->values->email);
     $formVal = $form->getValues(TRUE);
     if ($userExists > 0) {
         unset($formVal["username"]);
         $this->presenter->flashMessage('Uživatelské jméno již existuje', 'error');
     } elseif (\Nette\Utils\Validators::isEmail($form->values->email) == FALSE) {
         unset($formVal["email"]);
         $this->presenter->flashMessage('Neplatná e-mailová adresa', 'error');
     } elseif ($emailExists > 0) {
         unset($formVal["email"]);
         $this->presenter->flashMessage('E-mail již existuje', 'error');
     } elseif ($userTest == 0) {
         unset($formVal["username"]);
         $this->presenter->flashMessage('Uživatelské jméno obsahuje nepovolené znaky', 'error');
     } elseif (strlen($form->values->name) < 2) {
         $this->presenter->flashMessage('Příliš krátké jméno', 'error');
     } else {
         $msg = 1;
     }
     if ($msg != 1) {
         unset($formVal["pwd"], $formVal["pwd2"], $formVal["confirmation"]);
         $this->presenter->redirect(":Front:Sign:up", $formVal);
     }
 }
Exemplo n.º 3
0
 /**
  * @param $email
  * @throws \Nette\InvalidArgumentException
  */
 public function setEmail($email)
 {
     if (!Validators::isEmail($email)) {
         throw new InvalidArgumentException("Email must be in correct format.");
     }
     $this->email = $email;
 }
Exemplo n.º 4
0
 /**
  * @param array $emails
  * @return $this
  * @throws Exception
  * @throws \Dibi\Exception
  */
 public function setEmails(array $emails)
 {
     $this->dbPostfix->begin();
     try {
         foreach ($emails as $email) {
             if (!empty($email->id)) {
                 $this->dbPostfix->query("UPDATE mailbox SET [user]=%s, password=%s WHERE id=%i", $email->username, $email->password, $email->id);
             } else {
                 $this->dbPostfix->query("INSERT INTO mailbox", array('user' => $email->username, 'password' => $email->password, 'domain_id' => $this->getDomainId()));
             }
             if (!empty($email->alias)) {
                 $aliases = explode(',', str_replace(' ', '', $email->alias));
                 foreach ($aliases as $alias) {
                     if (!\Nette\Utils\Validators::isEmail($alias)) {
                         throw new CmsException($alias . ' není platný email.');
                     }
                 }
                 $aliasId = $this->dbPostfix->query("SELECT id FROM alias WHERE domain_id=%i AND [user]=%s", $this->getDomainId(), $email->username)->fetchSingle();
                 if (!empty($aliasId)) {
                     $this->dbPostfix->query("UPDATE alias SET target=%s WHERE id=%i", implode(',', $aliases), $aliasId);
                 } else {
                     $this->dbPostfix->query("INSERT INTO alias", array('domain_id' => $this->getDomainId(), 'user' => $email->username, 'target' => implode(',', $aliases)));
                 }
             }
         }
     } catch (Exception $ex) {
         $this->dbPostfix->rollback();
         throw $ex;
     }
     $this->dbPostfix->commit();
     return $this;
 }
Exemplo n.º 5
0
 /**
  * @param $email
  */
 public function __construct($email)
 {
     if (!Validators::isEmail($email)) {
         throw new \InvalidArgumentException("{$email} is not email.");
     }
     $this->email = $email;
 }
Exemplo n.º 6
0
 function sendFormSucceeded(\Nette\Forms\BootstrapUIForm $form)
 {
     $email = $form->getValues()->email;
     if ($form->values->layer == 'admin') {
         $lostPass = $this->database->table("helpdesk_emails")->where("template", "lostpass-admin")->fetch();
     } else {
         $lostPass = $this->database->table("helpdesk_emails")->where("template", "lostpass-member")->fetch();
     }
     if (!\Nette\Utils\Validators::isEmail($email)) {
         $this->presenter->flashMessage("Adresa je neplatná");
         $this->presenter->redirect(":Front:Sign:lostpass");
     }
     $passwordGenerate = \Nette\Utils\Random::generate(12, "987654321zyxwvutsrqponmlkjihgfedcba");
     if ($this->database->table('users')->where(array('email' => $email))->count() == 0) {
         $this->flashMessage("E-mail nenalezen");
         $this->presenter->redirect(":Front:Sign:lostpass");
     }
     $member = new \App\Model\MemberModel($this->database);
     $member->setActivation($email, $passwordGenerate);
     $latte = new \Latte\Engine();
     $latte->setLoader(new \Latte\Loaders\StringLoader());
     $params = array('code' => $passwordGenerate, 'email' => $email, 'settings' => $this->presenter->template->settings);
     $mail = new \Nette\Mail\Message();
     $mail->setFrom($this->presenter->template->settings['contacts:email:hq'])->addTo($email)->setSubject("Informace o novém hesle")->setHTMLBody($latte->renderToString($lostPass->body, $params));
     $mailer = new \Nette\Mail\SendmailMailer();
     $mailer->send($mail);
     $this->presenter->flashMessage('Informace o zapomenutém hesle odeslány', 'success');
     $this->presenter->redirect(this);
 }
Exemplo n.º 7
0
 private function validateEmail($email)
 {
     if (preg_match('#^(.+) +<(.*)>\\z#', $email, $matches)) {
         $email = $matches[2];
     } else {
         $email = $email;
     }
     return \Nette\Utils\Validators::isEmail($email);
 }
Exemplo n.º 8
0
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output) : int
 {
     $email = $input->getArgument('email');
     $password = $input->getArgument('password');
     $role = $input->getArgument('role');
     if (!Validators::isEmail($email)) {
         $output->writeln("<error>First argument must be valid email, but '{$email}' given!</error>");
         return 1;
     }
     $this->registrator->register($email, $password, $role);
     return 0;
 }
Exemplo n.º 9
0
 public function beforeCompile()
 {
     $containerBuilder = $this->getContainerBuilder();
     $mailerAlias = $containerBuilder->getByType('Nette\\Mail\\IMailer');
     $mailerDefinition = $containerBuilder->getDefinition($mailerAlias);
     $mailerFactory = $mailerDefinition->getFactory();
     $mailerDefinition->setFactory('Simplement\\MailQueue\\Mailer', array($mailerFactory))->addSetup('setConfig', array($this->config));
     if (!$this->config['defaultSender'] && isset($mailerFactory->arguments['smtp']) && $mailerFactory->arguments['smtp'] && isset($mailerFactory->arguments['username']) && ($email = $mailerFactory->arguments['username']) && \Nette\Utils\Validators::isEmail($this->getMail($email))) {
         $this->config['defaultSender'] = $email;
     }
     $containerBuilder->getDefinition($this->prefix('command.sendfronted'))->addSetup('setConfig', array($this->config));
     $containerBuilder->getDefinition($this->prefix('command.send'))->addSetup('setConfig', array($this->config));
 }
Exemplo n.º 10
0
 public function __construct($email, $password)
 {
     $email = (string) $email;
     $password = (string) $password;
     if (!Validators::isEmail($email)) {
         throw new EntityInvalidArgumentException(sprintf('Invalid e-mail %s.', $email));
     }
     if (strlen($password) < self::PASSWORD_MIN_LENGTH) {
         throw new EntityInvalidArgumentException(sprintf('Password must be at least %d characters long.', self::PASSWORD_MIN_LENGTH));
     }
     $this->email = $email;
     $this->password = Passwords::hash($password);
     $this->carts = new ArrayCollection();
 }
Exemplo n.º 11
0
 function sendFormValidated(\Nette\Forms\BootstrapUIForm $form)
 {
     if (strlen($form->values->name) < 2) {
         $this->flashMessage($this->translator->translate('messages.sign.fillInName'), "error");
         $this->redirect(":Front:Contact:default");
     }
     if (\Nette\Utils\Validators::isEmail($form->values->email) == FALSE) {
         $this->flashMessage($this->translator->translate('messages.sign.fillInEmail'), "error");
         $this->redirect(":Front:Contact:default");
     }
     if (strlen($form->values->message) < 2) {
         $this->flashMessage($this->translator->translate('messages.sign.fillInMessage'), "error");
         $this->redirect(":Front:Contact:default");
     }
 }
Exemplo n.º 12
0
 function signFormValidated(\Nette\Forms\BootstrapPHForm $form)
 {
     $event = $this->database->table("events")->get($form->values->event);
     if (strlen($form->values->name) < 2) {
         $this->presenter->flashMessage('Vyplňte jméno', "error");
         $this->presenter->redirect(this, array("id" => $event->pages_id, "event" => $event->id));
     }
     if (\Nette\Utils\Validators::isEmail($form->values->email) == FALSE) {
         $this->presenter->flashMessage('Vyplňte e-mail', "error");
         $this->presenter->redirect(this, array("id" => $event->pages_id, "event" => $event->id));
     }
     $eventSigned = $this->database->table("events_signed")->where(array("email" => $form->values->email, "events_id" => $event->id));
     if ($eventSigned->count() > 0) {
         $this->presenter->flashMessage('Tento e-mail už byl použit při registraci', "error");
         $this->presenter->redirect(this, array("id" => $event->pages_id, "event" => $event->id));
     }
 }
Exemplo n.º 13
0
    } elseif ($field->getName() === 'companies') {
        unset($values['id']);
        $context->table('companies')->where('id = ?', $reference->getToValue())->update($values);
    } elseif ($field->getName() === 'group') {
        unset($values['id']);
        $context->table('groups')->where('id = ?', $reference->getToValue())->update($values);
    } elseif ($field->getName() === 'wallet') {
        unset($values['id'], $values['wallet_id']);
        $context->table('wallets')->where('id = ?', $reference->getToValue())->update($values);
    }
};
$editable->onEditField[] = function (\Mesour\Editable\Structures\Fields\IStructureField $field, $newValue, $oldValue, $identifier = null, array $params = []) use($context, $source) {
    if ($field->getName() === 'group') {
        $data = ['group_id' => !$newValue ? null : $newValue];
    } else {
        if ($field->getName() === 'email' && !\Nette\Utils\Validators::isEmail($newValue)) {
            $exception = new \Mesour\Editable\ValidatorException('Value must be valid email.');
            $exception->setFieldName($field->getName());
            throw $exception;
        }
        $data = [$field->getName() => $newValue === false ? 0 : $newValue];
    }
    $context->table('users')->where('id = ?', $identifier)->update($data);
};
$created = $editable->create();
$currentUser = $source->fetch();
$currentUserId = $currentUser['id'];
?>

<hr style="margin-bottom: 50px;">
Exemplo n.º 14
0
 /**
  * @param string
  * @throws \Nette\InvalidArgumentException
  */
 private function validateEmail($email)
 {
     if (!\Nette\Utils\Validators::isEmail($email)) {
         throw new \Nette\InvalidArgumentException();
     }
 }
Exemplo n.º 15
0
Arquivo: User.php Projeto: venne/venne
 /**
  * @param string $email
  */
 public function setEmail($email)
 {
     if (!\Nette\Utils\Validators::isEmail($email)) {
         throw new \Nette\InvalidArgumentException(sprintf('E-mail must be in correct format. \'%s\' is given.', $email));
     }
     $this->email = $email;
 }
Exemplo n.º 16
0
 public function osobaCreateFormValidate(Form $form, $values)
 {
     if (!$this->user->loggedIn) {
         $this->error('Pro tuto akci musí být uživatel přihlášen.');
     }
     foreach ($this->parseOsoby($values->osoby) as $id => $osoba) {
         if (strlen($osoba['jmeno']) == 0) {
             $form->addError('Chyba, u ' . ($id + 1) . ' osoby není zadáno jméno.');
         }
         if (!Validators::isEmail($osoba['email'])) {
             $form->addError('Chyba, u ' . ($id + 1) . ' osoby není zadán platný email.');
         }
     }
 }
Exemplo n.º 17
0
 /**
  * @param $unsubscribeEmail
  * @throws \Exception
  */
 public function setUnsubscribeEmail($unsubscribeEmail)
 {
     if (!Validators::isEmail($unsubscribeEmail)) {
         throw new \Exception("Email has bad format");
     }
     $this->unsubscribeEmail = $unsubscribeEmail;
 }
Exemplo n.º 18
0
 /**
  * onSuccess event loginForm
  *
  * calls events onForgotSuccess[]
  *
  * @param Form $form
  * @param      $values
  *
  * @return bool
  */
 public function forgotPasswordFormSucceeded(Form $form, $values)
 {
     // not set email correct
     if (!Validators::isEmail($values->email)) {
         $form->addError($this->messages['err_email_not_correct']);
         return false;
     }
     // if not token set, user with email not exist
     if (!($token = $this->user->getAuthenticator()->resetPasswordToken($values->email))) {
         $form->addError($this->messages['err_email_does_not_exist']);
         return false;
     }
     $this->onForgotSuccess($values->email, $token);
     return true;
 }
Exemplo n.º 19
0
 /**
  * Default mailer.
  *
  * @param $message
  * @param $email
  * @param  string|\Exception|\Throwable
  *
  * @internal
  */
 public function defaultMailer($message, $email, $exceptionFile = NULL, $priority = NULL)
 {
     if (!is_null($this->host)) {
         $host = $this->host;
     } else {
         $host = preg_replace('#[^\\w.-]+#', '', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : php_uname('n'));
     }
     try {
         $emailSendJson = Nette\Utils\Json::decode(file_get_contents($this->directory . '/email-sent'), Nette\Utils\Json::FORCE_ARRAY);
     } catch (Nette\Utils\JsonException $e) {
         $emailSendJson = [];
     }
     $emailSendJson[$exceptionFile] = TRUE;
     @file_put_contents($this->directory . '/email-sent', Nette\Utils\Json::encode($emailSendJson));
     $mail = new Nette\Mail\Message();
     $mail->setFrom($this->fromEmail ?: (Nette\Utils\Validators::isEmail("noreply@{$host}") ? "noreply@{$host}" : "*****@*****.**"))->addTo(is_array($email) ? $email[0] : $email)->setSubject("PHP: An error (" . $this->getTitle($message, $priority) . ") occurred on the server {$host}")->setHtmlBody($this->formatMessage($message) . "\n\nsource: " . Tracy\Helpers::getSource() . (is_null($exceptionFile) ? '' : "\n\nexception link: " . Nette\Utils\Strings::replace($exceptionFile, ['~^(.*)exception--~' => 'http://' . $host . $this->path . 'exception--'])));
     if (is_array($email)) {
         foreach ($email as $k => $v) {
             if ($k == 0) {
                 continue;
             }
             $mail->addCc($v);
         }
     }
     $this->mailerClass->send($mail);
 }
Exemplo n.º 20
0
 function editFormValidated(\Nette\Forms\BootstrapUIForm $form)
 {
     if (\Nette\Utils\Validators::isEmail($form->values->email) == FALSE && strlen($form->values->email) > 0) {
         $this->onSave($form->values->pages_id, $error = 1);
     }
 }
Exemplo n.º 21
0
 /**
  * @param string $email
  */
 public function setEmail($email)
 {
     if (!Validators::isEmail($email)) {
         throw new InvalidArgumentException('E-mail is not in valid format.');
     }
     $this->email = $email;
 }
Exemplo n.º 22
0
 /**
  * @param $username
  * @return bool
  * @throws Trejjam\Authorization\User\ManagerException
  */
 public function isUsernameValid($username)
 {
     if (strlen($username) > $this->tables['users']['username']['length']) {
         throw new Trejjam\Authorization\User\ManagerException('The username is too long', Trejjam\Authorization\User\ManagerException::LONG_USERNAME);
     }
     switch ($this->tables['users']['username']['match']) {
         case 'email':
             if (!Nette\Utils\Validators::isEmail($username)) {
                 throw new Trejjam\Authorization\User\ManagerException('The username is not an email', Trejjam\Authorization\User\ManagerException::NOT_VALID_USERNAME);
             }
             break;
         default:
             if (!preg_match($this->tables['users']['username']['match'], $username)) {
                 throw new Trejjam\Authorization\User\ManagerException('The username is not match regex ' . $this->tables['users']['username']['match'], Trejjam\Authorization\User\ManagerException::NOT_VALID_USERNAME);
             }
     }
     return TRUE;
 }
Exemplo n.º 23
0
 static function validateEmail(TextBase $control)
 {
     return Validators::isEmail($control->getValue());
 }
Exemplo n.º 24
0
 /**
  * @param string             $to
  * @param bool(false)|string $name
  * @return $this
  * @throw EmailException
  */
 function replyTo($to, $name = NULL)
 {
     if (!Nette\Utils\Validators::isEmail($to)) {
         throw new EmailException('Email is not valid', EmailException::INVALID_EMAIL);
     }
     $this->replyTo = $to;
     $this->replyToName = $name;
     return $this;
 }
Exemplo n.º 25
0
 /**
  * Validate email
  * @param string $value
  * @param Rule $rule
  * @throws ValidationException
  */
 public static function validateEmail($value, Rule $rule)
 {
     if (!Validators::isEmail($value)) {
         throw ValidationException::createFromRule($rule, $value);
     }
 }
Exemplo n.º 26
0
Validators::isInRange(Strings::length($control->getValue()),$range);}static
function
validateEmail(TextBase$control){return
Validators::isEmail($control->getValue());}static
Exemplo n.º 27
0
 /**
  * Is control's value valid email address?
  * @return bool
  */
 public static function validateEmail(IControl $control)
 {
     return Validators::isEmail($control->getValue());
 }
Exemplo n.º 28
0
 public function setEmail($email)
 {
     if (!\Nette\Utils\Validators::isEmail($email)) {
         throw new \Nette\InvalidArgumentException("E-mail must be in correct format. '{$email}' is given.");
     }
     $this->email = $email;
     $this->generateSlug();
 }