Example #1
0
      $form->addSubmit('cancel', 'Cancel')->setAttribute('class', 'btn btn-default')->setValidationScope([]);
      return $form;
  }
  /** Vlastná validácia pre AddUserForm
 * @param Nette\Application\UI\Form $button
 */
  public function validateAddUserForm($button)
  {
      $values = $button->getForm()->getValues();
      if ($button->isSubmitted()->name == 'uloz') {
          // Over, ci dane username uz existuje.
          if ($this->users->findBy(['username' => $values->username])->count() > 0) {
              $button->addError(sprintf('Zadané užívateľské meno %s už existuje! Zvolte prosím iné!', $values->username));
          }
          // Over, ci dany email uz existuje.
Example #2
0
          $form->addText('rok', 'Rok narodenia:', 4, 5)->addRule(Form::RANGE, 'Rok narodenia musí byť v rozsahu od %d do %d', [1900, StrFTime("%Y", Time())]);
      }
      if ($user_view_fields["telefon"]) {
          $form->addText('telefon', 'Telefón:', 20, 20);
      }
      if ($user_view_fields["poznamka"]) {
          $form->addText('poznamka', 'Poznámka:', 50, 250);
      }
      if ($user_view_fields["pohl"]) {
          $form->addSelect('pohl', 'Pohlavie:', ['M' => 'Muž', 'Z' => 'Žena']);
      }
      $form->onValidate[] = [$this, 'validateEditUserForm'];
      $form->addSubmit('uloz', 'Ulož')->setAttribute('class', 'btn btn-success')->onClick[] = [$this, 'editUserFormSubmitted'];
      $form->addSubmit('cancel', 'Cancel')->setAttribute('class', 'btn btn-default')->setValidationScope(FALSE);
      return $form;
  }
  /** Vlastná validácia
 * @param Nette\Application\UI\Form $button
Example #3
0
 /** Spracovanie reistracneho formulara
  * @param Nette\Application\UI\Form $button Data formulara
  */
 public function userRegisterFormSubmitted($button)
 {
     // Inicializacia
     $values = $button->getForm()->getValues();
     //Nacitanie hodnot formulara
     // Over, ci dane username uz existuje. Ak ano vypis a skonc.
     if ($this->users->testUsername($values->username)) {
         $this->flashMessage($this->trLang('registracia_username_duble'), 'danger');
         return;
     }
     // Over, ci dany email uz existuje. Ak ano vypis a skonc.
     if ($this->users->testEmail($values->email)) {
         $this->flashMessage(sprintf($this->trLang('registracia_email_duble'), $values->email, $this->link('User:forgotPassword')), 'danger,n');
         return;
     }
     $new_password_key = $this->hasser->HashPassword($values->heslo . StrFTime("%Y-%m-%d %H:%M:%S", Time()));
     $uloz_data_user_profiles = ['meno' => $values->meno, 'priezvisko' => $values->priezvisko, 'pohl' => isset($values->pohl) ? $values->pohl : 'Z', 'modified' => StrFTime("%Y-%m-%d %H:%M:%S", Time()), 'created' => StrFTime("%Y-%m-%d %H:%M:%S", Time())];
     $uloz_data_users = ['username' => $values->username, 'password' => $this->hasser->HashPassword($values->heslo), 'email' => $values->email, 'activated' => 0];
     //Uloz info do tabulky users
     if (($uloz_users = $this->users->uloz($uloz_data_users)) !== FALSE) {
         //Ulozenie v poriadku
         $uloz_data_user_profiles['id_users'] = $uloz_users['id'];
         //nacitaj id ulozeneho clena
         $uloz_user_profiles = $this->user_profiles->uloz($uloz_data_user_profiles);
     }
     if ($uloz_user_profiles !== FALSE) {
         //Ulozenie v poriadku
         $this->flashMessage($this->trLang('base_save_ok'), 'success');
         $templ = new Latte\Engine();
         $params = ["site_name" => $this->nazov_stranky, "nadpis" => sprintf($this->trLang('email_activate_nadpis'), $this->nazov_stranky), "email_activate_txt" => $this->trLang('email_activate_txt'), "email_nefunkcny_odkaz" => $this->trLang('email_nefunkcny_odkaz'), "email_pozdrav" => $this->trLang('email_pozdrav'), "nazov" => $this->trLang('register_aktivacia'), "odkaz" => 'http://' . $this->nazov_stranky . $this->link("User:activateUser", $uloz_user_profiles['id'], $new_password_key)];
         $mail = new Message();
         $mail->setFrom($this->nazov_stranky . ' <' . $this->clen->users->email . '>')->addTo($values->email)->setSubject($this->trLang('register_aktivacia'))->setHtmlBody($templ->renderToString(__DIR__ . '/templates/User/email_activate-html.latte', $params));
         try {
             $sendmail = new SendmailMailer();
             $sendmail->send($mail);
             $this->users->find($uloz_users['id'])->update(['new_password_key' => $new_password_key]);
             $this->flashMessage($this->trLang('register_email_ok'), 'success');
         } catch (Exception $e) {
             $this->flashMessage($this->trLang('send_email_err') . $e->getMessage(), 'danger,n');
         }
         $this->redirect('Homepage:');
     } else {
         $this->flashMessage($this->trLang('register_save_err'), 'danger');
     }
     //Ulozenie sa nepodarilo
 }