public function itemFormSubmitted(MyAppForm $form) { try { if ($form['save']->isSubmittedBy()) { $id = (int) $this->getParam('id'); $values = $form->getValues(); unset($values['password2']); $sendNotifyingEmail = $values['send_email']; unset($values['send_email']); // if not client-like user, unset supervisor if (!is_array($values['roles'])) { // depends on client view is ON/OFF $values['roles'] = array($values['roles']); } if (count(array_intersect(UsersModel::$clientRolesId, $values['roles'])) === 0) { $values['supervisor_id'] = null; } if ($id > 0) { $this->model->update($id, $values); $this->flashMessage('User updated.', self::FLASH_MESSAGE_SUCCESS); } else { if ($this->isClientMode) { $values['supervisor_id'] = $this->userId; } $values['approved'] = true; $id = $this->model->insert($values); $this->flashMessage('User created.', self::FLASH_MESSAGE_SUCCESS); if ($sendNotifyingEmail) { $this->sendRegBasicEmail($values); } } } } catch (InvalidStateException $e) { $form->addError($this->translate('Mail could not be sent. Try again later, please')); } catch (DibiDriverException $e) { // duplicate entry if ($e->getCode() === BaseModel::DUPLICATE_ENTRY_CODE) { $this->flashMessage("ERROR: " . $e->getMessage(), self::FLASH_MESSAGE_ERROR); } else { Debug::log($e); $this->flashMessage("ERROR: cannot save data!", self::FLASH_MESSAGE_ERROR); } } catch (OperationNotAllowedException $e) { $this->flashMessage(NOT_ALLOWED, self::FLASH_MESSAGE_ERROR); $this->redirect('this'); } $form->resetValues(); $this->refresh(null, 'add'); }
protected function createComponentTempLoginForm() { $form = new MyAppForm(); if (isset($this->getPresenter()->translator)) { $form->setTranslator($this->getPresenter()->translator); } $form->addText('email', 'E-mail')->setEmptyValue('@')->addRule(Form::FILLED)->addRule(Form::EMAIL); $form->addSubmit('send', 'Log me in!')->getControlPrototype()->class[] = 'ok-button'; $form->addProtection('Form validity time expired. Please send the form again.'); $form->onSubmit[] = array($this, 'tempLoginFormSubmitted'); return $form; }
/** * save user info * * @param MyAppForm */ public function save(MyAppForm $form) { try { if ($form['save']->isSubmittedBy()) { $values = $form->getValues(); $loginOnSuccess = !empty($values['loginOnSuccess']); if ($loginOnSuccess) { unset($values['loginOnSuccess']); } $this->model->updateLoggedUser($values, true); // to allow relogin after change of credentials - used when user forgot password and was redirected from ForgottenPass::tempLogin() if ($loginOnSuccess) { $this->user->logout(TRUE); $this->flashMessage('Password has been successfully updated. Please log in using new password now.', $this::FLASH_MESSAGE_SUCCESS); $this->redirect(':Front:Login:login'); } else { $this->flashMessage('Data updated.', $this::FLASH_MESSAGE_SUCCESS); } } } catch (DibiDriverException $e) { $this->flashMessage("ERROR: cannot save data!", $this::FLASH_MESSAGE_ERROR); } catch (InvalidPasswordException $e) { $this->flashMessage($e->getMessage(), $this::FLASH_MESSAGE_ERROR); } $this->refresh(null, 'this'); }
protected function createComponentLoginForm($name) { $form = new MyAppForm($this, $name); if ($this->useAjax) { $form->enableAjax(); } if (!$this->useAutocomplete) { $form->getElementPrototype()->autocomplete('off'); } if (isset($this->getPresenter()->translator)) { $form->setTranslator($this->getPresenter()->translator); } if ($this->errorsAsFlashMessages) { $form->setErrorsAsFlashMessages(); } $form->addClass('loginFrm'); $form->addText('username', $this->labels['username'])->addRule(Form::FILLED, 'Enter your username!'); $form->addPassword('password', $this->labels['password'])->addRule(Form::FILLED, 'Enter your password!'); if ($this->useRemember) { $form->addCheckbox('remember', $this->labels['remember']); } // if using labelOver we need to add class to ensure label is visible with javascript disabled if ($this->useLabelOver) { $form['password']->getLabelPrototype()->class('onlyJS'); $form['username']->getLabelPrototype()->class('onlyJS'); } $form->addHidden('key'); $form->addHidden('anchor'); $form->addSubmit('ok', $this->labels['submit'])->getControlPrototype()->class[] = 'ok-button'; if ($this->useProtection) { $form->addProtection('Form validity time expired. Please send the form again.'); } $form->onSubmit[] = callback($this, 'loginFormSubmitted'); return $form; }
/** * chyby vo formulari zobrazi ako flash a chyby zmaze * * @param AppForm $form */ public static function errorsAsFlashMessages(MyAppForm $form) { $errors = $form->getErrors(); foreach ($errors as $error) { Environment::getApplication()->getPresenter()->flashMessage($error, 'error'); } $form->cleanErrors(); }