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; }
/** * * @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'); } }
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'); } }
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.'); } }
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'); } }
/** * 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 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'); }
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'); } }
/** * * @param Nette\Application\UI\Form $form * @throws \Exception */ public function signInFormSucceeded($form) { $values = $form->getValues(); if ($values->remember) { $this->user->setExpiration('14 days', FALSE); } else { $this->user->setExpiration('20 minutes', TRUE); } try { $user = $this->getActiveUserByUsername($values->username); if (!$user) { throw new \Exception('Uživatel není aktivní nebo neexistuje.'); } $this->user->login($user->username, $values->password); $this->flashMessage('Byl/a jste úspěšně přihlášen/a jako "' . $user->username . '"', 'success'); if (!empty($values['backSignInUrl'])) { $redirectToUrl = $values['backSignInUrl']; } else { $this->redirect('Homepage:'); } } catch (Nette\Security\AuthenticationException $e) { $form->addError($e->getMessage()); } catch (\Exception $e) { $form->addError($e->getMessage()); } if (!empty($redirectToUrl)) { $this->redirectUrl($redirectToUrl); } }
/** * @param \Nette\Application\UI\Form $form */ public function formSubmitted(Form $form) { $values = $form->getValues(); $this->getPaginator()->setDate($values['paginatorDate']); $this->date = $values['paginatorDate']->format('Y-m-d'); $this->redirect('this', array('date' => $this->date)); }
/** Submit * @param Form $form */ public function Submit(Form $form) { $values = $form->getValues(); $contactEntity = new ContactEntity(); $userEntity = new UserEntity(); $contactEntity->setValues((array) $values); $userEntity->setLogin($values->login); $userEntity->setAclRoleID(10); // guest role $userEntity->setPassword($values->password); $userEntity->setActive(TRUE); $contactEntity->setUser($userEntity); try { $this->contactRepository->push($contactEntity); $result = $this->contactRepository->save(); if ($result) { $this->flashMessage("Vaše registrace proběhla úspěšně."); $this->redirect('this'); } else { $form->addError("Vaše registrace neproběhla úspěšně."); } } catch (\PDOException $e) { if (strpos($e->getMessage(), "1062 Duplicate entry") !== FALSE) { $form->addError("Uživatel {$values->login} již existuje. Zvolte si prosím jiný přihlašovací email."); } else { $form->addError($e->getMessage()); } } }
public function addToBasketSubmitted(Form $form) { $values = $form->getValues(); $this->basketService->getBasket()->addItem($values->itemId, 1); $this->flashMessage('Zboží bylo přídáno do košíku.'); $this->redirect('this'); }
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'); }
/** * @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 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.'); } }
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 saveRole(Form $form) { $vals = $form->getValues(); $this->uzivatele->setRole($vals['id'], $vals['role']); $this->flashMessage("Oprávnění uložena"); $this->redirect("default"); }
/** * @param \Nette\Application\UI\Form $form */ public function Submit(NetteForm $form) { $json = new \stdClass(); $json->result = "error"; $json->message = $form->getValues()->area; $response = new JsonResponse($json); $this->getPresenter(TRUE)->sendResponse($response); }
/** * @param Form $form */ public function formSucceeded(Form $form) { $values = $form->getValues(); /** @var FooterEntity $item */ $item = $this->footerRepository->get($values->id); $item->text($values->text); $this->footerRepository->save($item); }
/** * @param Form $form */ public function Submit(Form $form) { $json = new \stdClass(); $json->result = "success"; $values = $form->getValues(); $result = false; if (!empty($values['userID'])) { $userEntity = $this->userRepository->get($values['userID']); if ($userEntity) { if ($this->user->isAllowed("user_management", "edit")) { $userEntity->setLogin($values['login']); if (!empty($values['password1'])) { $userEntity->setPassword($values['password1']); } if ($userEntity->getLogin() !== "root" && $userEntity->getUserID() !== $this->user->getId()) { $userEntity->setActive($values['active']); if ($userEntity->getRole()->getAclRoleID() != $this->user->getIdentity()->data['aclRoleID']) { $userEntity->setAclRoleID($values['role']); } } try { $result = $this->userRepository->save(); } catch (\PDOException $e) { $result = $e->getMessage(); } } else { $result = UserForm::PERMISSION; } } } else { if ($this->user->isAllowed("user_management", "add")) { $userEntity = new UserEntity(); $userEntity->setLogin($values['login'])->setPassword($values['password1'])->setActive($values['active'])->setAclRoleID($values['role']); try { $result = $this->userRepository->push($userEntity)->save(); } catch (\PDOException $e) { $result = $e->getMessage(); if (preg_match("/Duplicate entry/", $result)) { $result = "Nick <strong>" . $values['login'] . "</strong> již existuje. Zvolte prosím jiný login."; } } if ($result instanceof UserEntity || $result === TRUE) { $result = TRUE; } } else { $result = UserForm::PERMISSION; } } if ($result === TRUE) { $json->result = "success"; } else { $json->result = "error"; $json->message = $result; } $response = new JsonResponse($json); $this->getPresenter()->sendResponse($response); }
/** * @param Form $form */ public function formSucceeded(Form $form) { $values = $form->getValues(); $galleries = new GalleriesEntity(); $galleries->name($values->name); $galleries->description($values->description); $galleries->url(Strings::webalize($values->name)); $this->galleriesRepository->save($galleries); }
/** * @param Form $form */ public function formSucceeded(Form $form) { $values = $form->getValues(); $item = new SliderEntity(); $item->imgName($values->imgName); $item->imgTitle($values->imgTitle); $item->imgDescription($values->imgDescription); $this->sliderRepository->save($item); }
public function onBeforeChange(Form $form, User $user) { $values = $form->getValues(); if (!Passwords::verify($values['currentPassword'], $user->password)) { $this->flashMessage('Heslo nelze změnit, protože nesouhlasí Vaše aktuální heslo.', 'warning'); $this->redirect('this'); } }
/** * @param Form $form */ public function formSucceeded(Form $form) { $values = $form->getValues(); /** @var CommentsEntity $comment */ $comment = $this->commentRepository->get($values->id); $comment->allowed($values->allowed); $comment->text($values->text); $this->commentRepository->save($comment); }
/** * Spracovanie formulara pre pridanie komentara * @param Nette\Application\UI\Form $form */ public function onZapisKomentar(Nette\Application\UI\Form $form) { $this->clanok_komentar->uloz($form->getValues()); if (!$this->presenter->isAjax()) { $this->redirect('this'); } else { $this->redrawControl('koment'); } }
private function someMethod(Form $form) { $values = $form->getValues(TRUE); // array // poslat email // přesměrujeme zpět $this->presenter->flashMessage('Odesláno!'); $this->redirect('this'); }
/** * Process contact form, send message * @param Form */ public function processContactForm(Form $form) { $values = $form->getValues(TRUE); $message = new Message(); $message->addTo('*****@*****.**')->setFrom($values['email'])->setSubject('Zpráva z kontaktního formuláře')->setBody($values['message']); $mailer = new SendmailMailer(); $mailer->send($message); $this->flashMessage('Zpráva byla odeslána'); $this->redirect('this'); }
public function contactFormSubmitted(Form $form) { try { $this->sendMail($form->getValues()); $this->flashMessage('Zpráva úspěšně odeslána!'); $this->redirect('this'); } catch (\Nette\InvalidStateException $e) { $form->addError('Nepodařilo se odeslat e-mail, zkuste to prosím za chvíli.'); } }
public function onSuccess(Nette\Application\UI\Form $form) { $values = $form->getValues(); try { $this->user->login($values->username, $values->password); } catch (Nette\Security\AuthenticationException $e) { $form->addError($e->getMessage()); return; } }
public function saveEditForm(Form $form) { $data = $form->getValues(); $id = $data['id']; $name = $data['name']; $description = $data['description']; $this->experimentsModel->updateExperiment($id, $name, $description); $this->flashMessage('Experiment was successfully updated.', 'alert-success'); $this->redirect('list'); }