/** * Adds text field to filter form * @param Nette\Application\UI\Form $form */ public function addToFormContainer($form) { $form->addText($this->key, $this->name); if ($this->getPlaceholder()) { $form[$this->key]->setAttribute('placeholder', $this->getPlaceholder()); } }
public function processCreateInvitation(Form $form) { $value = $form->getValues(); $invitation = new Invitation($value['email'], $this->user->getIdentity()); try { /** @var EntityResultObject $resultObject */ $resultObject = $this->invitationsFacade->createInvitation($invitation); $this->flashMessage('Registrační pozvánka byla vytvořena.', 'success'); if (!$resultObject->hasNoErrors()) { $error = $resultObject->getFirstError(); $this->flashMessage($error['message'], $error['type']); } } catch (InvitationCreationAttemptException $ca) { $this->flashMessage('Pozvánku nebyla vytvořena. Zkuste akci opakovat později.', 'error'); } catch (UserAlreadyExistsException $uae) { $form->addError('Pozvánku nelze odeslat. Uživatel s E-Mailem ' . $value['email'] . ' je již zaregistrován.'); return; } catch (InvitationAlreadyExistsException $iae) { $form->addError('Někdo jiný již odeslal pozvánku uživateli s E-mailem ' . $value['email']); return; } catch (DBALException $e) { $this->flashMessage('Při vytváření pozvánky došlo k chybě. Zkuste akci opakovat později.', 'error'); } $this->redirect('this'); }
public function FtpEditFormValidate(Form $form, $values) { $eqUsername = $this->share->findAll()->where('shareType_id = ?', self::shareType_id)->where('NOT folder_id = ?', $values->folder_id)->where('var = ?', $values->username)->fetchAll(); if ($eqUsername) { $form->addError('Toto přihlašovací jméno už existuje, zvolte prosím jiné.'); } }
/** * Process a directive edit form. * @param void */ public function formEditSave(Form $form) { $data = $form->getValues(); $this->id = $data->id; $this->title = $data->title; $this->date = $data->date; $this->change = $data->change; $this->revision = $data->revision; $oldName = $this->document; $this->setDocument(); try { $this->row->update(array('id' => $this->id, 'title' => $this->title, 'date' => $this->date, 'change' => $this->change, 'revision' => $this->revision, 'document' => $this->document)); if ($oldName) { $this->renameDocFile($oldName, $this->document); } foreach ($this->getComponents(FALSE, "Annex") as $annex) { $annex->id = $this->id; $annex->updateData(); } $this->presenter->flashMessage('Směrnice byla aktualizována.', 'success'); $this->redirect('this'); } catch (Nette\Application\AbortException $e) { throw $e; } catch (Exception $ex) { if ($ex->getCode() == 23000) { $this->presenter->flashMessage('Zadané číslo směrnice již existuje. ', 'error'); $this->handleEdit(); } } }
public function signInFormSubmitted(Form $form) { try { $user = $this->getUser(); $values = $form->getValues(); /*if ($values->persistent) { $user->setExpiration('+30 days', FALSE); }*/ /** make login */ $user->login($values->username, $values->password); /** get rights */ $userId = $user->getIdentity()->id; $permissions = array(); foreach ($this->permissionRepository->getLevels($userId)->fetchPairs('url') as $page => $level) { $permissions[$page] = $level->level; } /** test for admin */ $permissions['admin'] = $this->userRepository->isAdmin($userId); /** set permissions */ $user->getIdentity()->setRoles($permissions); $this->flashMessage('Přihlášení bylo úspěšné.', 'success'); $this->redirect('Homepage:'); } catch (Nette\Security\AuthenticationException $e) { $form->addError('Neplatné uživatelské jméno nebo heslo.'); } }
/** @return Form */ public function create() { $f = new Form(); $f->addText('text')->setRequired('TRUE')->setAttribute('placeholder', 'Vyhledat'); $f->addSubmit('submit', 'Vyhledat')->setAttribute('class', 'btn btn-primary'); return $f; }
/** * Callback for Account Settings Form onSuccess event. * @param Form $form * @param ArrayHash $values */ public function formSucceeded(Form $form, $values) { if (!$this->userManager->checkPassword($this->user->getId(), $values->current)) { $form->addError("Invalid current password"); } $this->userManager->setNewPassword($this->user->getId(), $values->new); }
public function create() { $form = new Form(); $form->getElementPrototype()->addClass('form-horizontal'); $form->setRenderer(new Bs3FormRenderer()); return $form; }
/** * @return \Nette\Application\UI\Form */ public function create() { $form = new Form(); $form->addGroup($this->user ? 'Upravit uživatele' : 'Přidat uživatele'); $form->addText("name", 'Jméno:')->setRequired('Vyplňte jméno'); $form->addText("email", 'Email:')->setRequired('Vyplňte email')->addRule(function ($ctrl) { if ($this->user and $this->user->email == $ctrl->getValue()) { return TRUE; } return (bool) (!$this->userFacade->findUserByEmail($ctrl->getValue())); }, 'Email je obsazen, zvolte prosím jiný'); $password = $form->addPassword("password", 'Heslo:'); $password2 = $form->addPassword("password2", 'Heslo znovu:'); if (!$this->user) { $password->setRequired('Vyplňte heslo'); $password2->addRule(Form::FILLED, 'Vyplňte heslo znovu pro kontrolu')->addRule(Form::EQUAL, 'Hesla se neshodují', $password); } else { $password2->addConditionOn($password, Form::FILLED)->setRequired('Vyplňte heslo znovu pro kontrolu')->addRule(Form::EQUAL, 'Hesla se neshodují', $password); } $form->addSubmit("send", $this->user ? 'Upravit uživatele' : 'Přidat uživatele'); $form->setRenderer(new Bs3FormRenderer()); $form->onSuccess[] = $this->processForm; if ($this->user) { $form->setDefaults(["name" => $this->user->name, "email" => $this->user->email]); } return $form; }
/** * * @param Nette\Application\UI\Form $form */ public function signupFormSubmitted(Form $form) { $formValues = $form->getValues(); $userUsernameRow = $this->userFacade->getByUsername($formValues->username); $userEmailRow = $this->userFacade->getByEmail($formValues->email); if ($userUsernameRow !== false || $userEmailRow !== false) { if ($userUsernameRow !== false) { $form['username']->addError('This username is already taken. Please use different one.'); } if ($userEmailRow !== false) { $form['email']->addError('This email is already taken. Please use different one.'); } } else { $hashedPassword = \Screwfix\Authenticator::calculateHash($formValues->password); $userArr = array('username' => $formValues->username, 'role' => 'member', 'email' => $formValues->email, 'password' => $hashedPassword); try { $this->userFacade->save($userArr); $user = $this->getUser(); if ($formValues->remember) { $user->setExpiration('+14 days', FALSE); } $user->login($formValues->username, $formValues->password); $pattern = $this->adjustPattern($formValues->patternInput['pattern'], $formValues->patternInput['firstDay']); $patternFilter = $this->shiftPatternFilterFactory->create($pattern); $this->patternFacade->save($user->getId(), $patternFilter); } catch (\Exception $ex) { $form->addError('Sorry, something went wrong. Please try again.'); } $this->redirect('Home:default'); } }
/** * LogIn-in form factory. * @return Nette\Application\UI\Form */ protected function createComponentLogInForm() { $form = new Nette\Application\UI\Form(); $form->setTranslator($this->translator->domain('ui')); $form->addText('username', 'login-username')->setRequired('please-enter-your-username')->setAttribute('autofocus'); $form->addPassword('password', 'login-password')->setRequired(''); $form->addCheckbox('remember', 'keep-me-signed-in'); $form->addSubmit('send', 'log-in'); $form->onSuccess[] = $this->logInFormSucceeded; // setup form rendering for Twitter Bootstrap $renderer = $form->getRenderer(); $renderer->wrappers['controls']['container'] = NULL; $renderer->wrappers['pair']['container'] = 'div class=form-group'; $renderer->wrappers['pair']['.error'] = 'has-error'; $renderer->wrappers['control']['container'] = 'div class=col-sm-3'; $renderer->wrappers['label']['container'] = 'div class="col-sm-3 control-label"'; $renderer->wrappers['control']['description'] = 'span class=help-block'; $renderer->wrappers['control']['errorcontainer'] = 'span class=help-block'; // make form and controls compatible with Twitter Bootstrap $form->getElementPrototype()->class('form-horizontal'); foreach ($form->getControls() as $control) { if ($control instanceof Controls\Button) { $control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default'); $usedPrimary = TRUE; } elseif ($control instanceof Controls\TextBase || $control instanceof Controls\SelectBox || $control instanceof Controls\MultiSelectBox) { $control->getControlPrototype()->addClass('form-control'); } elseif ($control instanceof Controls\Checkbox || $control instanceof Controls\CheckboxList || $control instanceof Controls\RadioList) { $control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type); } } return $form; }
public function create() : Form { $form = new Form(); $form->addText('value')->addRule($form::FILLED); $form->onSuccess[] = [$this, 'process']; return $form; }
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.'); } }
protected function createComponentAddSetting() { $form = new Form(); $form->addText('key', 'Klíč')->setRequired('Zadejte klíč nastavení'); $form->addText('value', 'Hodnota')->setRequired('Zadejte hodnotu nastavení'); $form->addSubmit('send', 'Zapsat'); $form->onSuccess[] = function (Form $f) { try { $val = $f->values; $this->settings->set($val->key, $val->value); $this->settings->push(); //Write $this->logger->log('System', 'edit', "%user% změnila(a) nastavení"); $msg = $this->flashMessage("Nastavení bylo zapsáno", 'success'); $msg->title = 'Yehet!'; $msg->icon = 'check'; $this->redirect('this'); } catch (\PDOException $e) { \Nette\Diagnostics\Debugger::log($e); $msg = $this->flashMessage("Něco se podělalo. Zkuste to prosím později.", 'danger'); $msg->title = 'Oh shit!'; $msg->icon = 'warning'; } }; return $form; }
public function uspesne(Form $form, $hodnoty) { $zaznam = $this->database->table('druhZivocicha')->get($this->Id); $zaznam->update($hodnoty); $form->getPresenter()->flashMessage('Úspešne editované!', 'uspech'); $form->getPresenter()->redirect('Druh:viac', $this->Id); }
protected function getBootstrapForm() { $form = new Form(); $renderer = new BT3Renderer(); $form->setRenderer($renderer); return $form; }
public function searchForGroupFormSubmitted(Form $form) { $query = $form->getValues(); $this->groupsOutput = $this->groupModel->findAllByName($query->name); $this->searchInput = $query->name; $this->template->groupsOutput = $this->groupsOutput == null; }
public function formSucceeded(Form $form) { try { $p = $this->getPresenter(); $values = $form->getValues(); $latest = $this->wikiDraftRepository->getLatestByWiki($this->item); $start = DateTime::from($values->startTime); if ($latest && $start < $latest->createdAt) { throw new Exceptions\WikiDraftConflictException($this->translator->translate('locale.error.newer_draft_created_meanwhile')); } unset($values->name); unset($values->startTime); $this->wikiDraftRepository->create($values, $this->user, $this->item, new Entities\WikiDraftEntity()); $ent = $this->item; $p->flashMessage($this->translator->translate('locale.item.updated')); } catch (Exceptions\WikiDraftConflictException $e) { $this->newerDraftExists = true; $this->addFormError($form, $e); } catch (Exceptions\MissingTagException $e) { $this->addFormError($form, $e); } catch (PossibleUniqueKeyDuplicationException $e) { $this->addFormError($form, $e); } catch (\Exception $e) { $this->addFormError($form, $e, $this->translator->translate('locale.error.occurred')); } if (!empty($ent)) { $p->redirect('this'); } }
/** * @return Form */ public function create() { $form = new Form(); $form->setTranslator($this->translator); $form->setRenderer(new BaseFormRenderer()); return $form; }
public function addEditSubmit(\Nette\Application\UI\Form $oForm) { $qoValues = $oForm->getValues(TRUE); $qoValues[self::USER_ID] = $this->user->id; $qoValues[self::LAST_EDIT] = new \DateTime(); $qoValues[self::TEXT] = str_replace("\n", "<br />", $qoValues[self::TEXT]); if (isset($qoValues['id'])) { if ($this->user->isAllowed('article', '_edit')) { $this->oModel->update($qoValues); $this->flashMessage("Článek úspěšně editován."); $this->redirect("this"); } else { $this->flashMessage("Nemáte dostatečná práva", "danger"); $this->redirect("this"); } } else { if ($this->user->isAllowed('article', '_add')) { $qoValues[self::MENU_ID] = $this->menu; $iId = $this->oModel->insert($qoValues)->id; $this->flashMessage("Článek úspěšně vložen"); $this->redirect("Menu:show", array("id" => $this->menu)); } else { $this->flashMessage("Nemáte dostatečná práva", "danger"); $this->redirect("this"); } } }
public function formSucceeded(Form $form) { try { $p = $this->getPresenter(); $values = $form->getValues(); if (strlen($values->__anti) > 0) { throw new FormSentBySpamException($this->translator->translate('locale.form.spam_attempt_sign_up')); } unset($values->__anti); $user = $this->userRepository->createRegistration($values); $link = $p->link('//:Admin:Sign:unlock', array('uid' => $user->id, 'token' => $user->token)); $this->sendEmail($this->contactEmail, $user->email, $this->translator->translate('locale.sign.sign_up_request'), $link); $p->flashMessage($this->translator->translate('locale.sign.sign_up_email_sent'), FlashType::SUCCESS); } catch (FormSentBySpamException $e) { $this->addFormError($form, $e); $this->redrawControl('formErrors'); } catch (PossibleUniqueKeyDuplicationException $e) { $this->addFormError($form, $e); $this->redrawControl('formErrors'); } catch (\Exception $e) { $this->addFormError($form, $e, $this->translator->translate('locale.error.occurred')); $this->redrawControl('formErrors'); } if (!empty($user)) { $p->redirect('Homepage:default'); } }
/** * @return Form */ public function create($role) { $rights = $this->database->table('rights')->fetchPairs('id', 'name'); $form = new Form(); $form->addHidden('id'); $form->addText('username', 'uživatelské jméno: ')->addRule(Form::FILLED, 'Zadejte prosím jméno.'); $form->addText('email', 'email: ')->addRule(Form::FILLED, 'Zadejte prosím email.')->addRule(Form::EMAIL, 'Email by měl mít platný formát'); if (in_array("admin", $role)) { // editace prav jen adminem $form->addSelect('rights_id', 'level práv: ', $rights); } $form->addSubmit('submit', 'uložit'); $form->addProtection('Vypršel časový limit, odešlete formulář znovu'); //bootstrap vzhled $renderer = $form->getRenderer(); $renderer->wrappers['controls']['container'] = NULL; $renderer->wrappers['pair']['container'] = 'div class=form-group'; $renderer->wrappers['pair']['.error'] = 'has-error'; $renderer->wrappers['control']['container'] = ''; $renderer->wrappers['label']['container'] = 'div class="control-label col-sm-5"'; $renderer->wrappers['control']['description'] = 'span class=help-block'; $renderer->wrappers['control']['errorcontainer'] = 'span class=help-block'; $form->getElementPrototype()->class('form-horizontal col-sm-12'); return $form; }
public function formSucceeded(Form $form) { try { $p = $this->getPresenter(); $values = $form->getValues(); $tag = $this->getSelectedTag($form); if ($this->item) { $ent = $this->videoRepository->update($values, $tag, $this->user, $this->item); $p->flashMessage($this->translator->translate('locale.item.updated')); } else { $ent = $this->videoRepository->create($values, $tag, $this->user, new Entities\VideoEntity()); $p->flashMessage($this->translator->translate('locale.item.created')); } } catch (Exceptions\MissingTagException $e) { $this->addFormError($form, $e); } catch (PossibleUniqueKeyDuplicationException $e) { $this->addFormError($form, $e); } catch (InvalidVideoUrlException $e) { $this->addFormError($form, $e); } catch (\Exception $e) { $this->addFormError($form, $e, $this->translator->translate('locale.error.occurred')); } if (!empty($ent)) { $p->redirect('this'); } }
public function changeCategoryRankFormSucceeded(Form $form) { $values = (object) $form->getHttpData(); $this->categoryFacade->changeRanks($values->categoryRank); $form->getPresenter()->flashMessage("Pořadí kategorií bylo úspěšně změněno.", "alert-success"); $form->getPresenter()->redirect("this"); }
/** * Adds select box to filter form * @param Nette\Application\UI\Form $form */ public function addToFormContainer($form) { $form->addText($this->key, $this->name)->setAttribute('data-provide', 'datepicker')->setAttribute('data-date-orientation', 'bottom')->setAttribute('data-date-format', $this->getJsFormat())->setAttribute('data-date-today-highlight', 'true')->setAttribute('data-date-autoclose', 'true'); if ($this->getPlaceholder()) { $form[$this->key]->setAttribute('placeholder', $this->getPlaceholder()); } }
public function createComponentLoginForm($name) { $form = new Application\UI\Form($this, $name); $form->addSubmit("submit", $this->user->isLoggedIn() ? "Logout" : "Login"); $form->onSuccess[] = array($this, "onSuccessLoginForm"); return $form; }
protected function createComponentHledani() { $form = new \Nette\Application\UI\Form(); $form->addText("keyword", "Klíčové slovo"); $form->onSuccess[] = $this->hledej; return $form; }
/** * @param \Nette\Application\UI\Form $form */ public function processRegister(\Nette\Application\UI\Form $form) { $values = $form->getValues(); if ($this->userRepository->existsUsername($values->username)) { $form["username"]->addError($this->t("forms.register.errors.exists-username")); } else { if ($this->userRepository->existsEmail($values->email)) { $form["email"]->addError($this->t("forms.register.errors.exists-email")); } else { $this->getDbUtils()->begin(); try { $registerOptions = $this->container->getParameters()["register"]; if ($registerOptions["activation"]) { $status = \Model\Common\RecordStatus::UNFINISHED; } else { $status = \Model\Common\RecordStatus::VALID; } $user = $this->userRepository->createNewUser($values, $registerOptions["defaultGroupId"], $status); if ($registerOptions["activation"]) { $this->sendActivationEmail($values->email, $user); $this->flashMessage($this->t("forms.register.messages.need-activate"), "info"); } else { $this->flashMessage($this->t("forms.register.messages.register-success"), "success"); } $form->setDefaults(array("username" => "", "email" => ""), TRUE); $this->getDbUtils()->commit(); } catch (\Exception $e) { $this->getDbUtils()->rollback(); $this->catchFormError($e, $form, $this->t("global.errors.database-error")); } } } $this->redrawControl("registerForm"); }
public function uspesne(Form $form, $hodnoty) { foreach ($hodnoty['umiestnenie'] as &$hodnota) { if ($hodnota === '') { $hodnota = NULL; } } $zaznam = $this->database->table('umiestnenie')->insert($hodnoty['umiestnenie']); if ($this->mod == 0) { foreach ($hodnoty['klietka'] as &$hodnota) { if ($hodnota === '') { $hodnota = NULL; } } $hodnoty['klietka']->IDUmiestnenia = $zaznam->IDUmiestnenia; $this->database->table('klietka')->insert($hodnoty['klietka']); } else { foreach ($hodnoty['vybeh'] as &$hodnota) { if ($hodnota === '') { $hodnota = NULL; } } $hodnoty['vybeh']->IDUmiestnenia = $zaznam->IDUmiestnenia; $this->database->table('vybeh')->insert($hodnoty['vybeh']); } $form->getPresenter()->flashMessage('Úspešne pridané!', 'uspech'); $form->getPresenter()->redirect('Umiestnenie:vypis'); }
public function formSucceeded(Form $form) { try { $p = $this->getPresenter(); $values = $form->getValues(); if (strlen($values->__anti) > 0) { throw new FormSentBySpamException($this->translator->translate('locale.form.spam_attempt_sign_reset')); } unset($values->__anti); $user = $this->userRepository->getByEmail($values->email); if (!$user) { throw new UserNotFoundException(); } $token = $this->userRepository->prepareNewToken($user); $link = $p->link('//:Admin:Sign:password', array('uid' => $user->id, 'token' => $token)); $this->sendEmail($this->contactEmail, $values->email, $this->translator->translate('locale.sign.new_password_request'), $link); $p->flashMessage($this->translator->translate('locale.sign.new_password_request_email_sent'), FlashType::INFO); } catch (FormSentBySpamException $e) { $this->addFormError($form, $e); $this->redrawControl('formErrors'); } catch (UserNotFoundException $e) { $this->addFormError($form, $e, $this->translator->translate('locale.error.occurred')); $this->redrawControl('formErrors'); } catch (\PDOException $e) { $this->addFormError($form, $e, $this->translator->translate('locale.error.occurred')); $this->redrawControl('formErrors'); } $p->redirect(':Front:Homepage:default'); }