/** * Default action for database updating. * * @access public * @return View * @since 2014-08-17 * @version 1.2.0-dev */ public function actionDefault() { $this->addToTitle('Database updating module'); // create update form $oForm = new Form('db_update'); $oForm->setSubmitValue(__('make update')); // check if update button has been clicked if ($oForm->isSubmittedAndValid()) { $sUpdateOutput = static::makeUpdateNoExec(); Cache::set($sUpdateOutput, 'output', 'dbupdate'); Session::flash(Router::getCurrentUrl(), __('Database updated successfully.')); } // return View return View::factory('db_update/backend/default')->bind('oForm', $oForm); }
/** * @access public * @return Form * @since 1.0.0-alpha * @version 1.0.0-alpha */ public static function getForm() { if (static::$singleTonForm === NULL) { static::$singleTonForm = Form::factory('singletons'); } return static::$singleTonForm; }
/** * ACTION - User login. * * @access public * @return View * @since 1.0.2, 2013-12-07 * @version 1.0.7-dev, 2015-05-04 */ public function actionLogin() { $this->setTitle(Core::getAppName() . ' - ' . __('Login form')); $this->addBreadCrumb(__('Login form')); $oLoggedUser = Model\User::getLoggedUser(); if ($oLoggedUser instanceof Model\User) { Route::factory('user_profile')->redirectTo(['id' => $oLoggedUser->getId()]); } $failedLogins = \User\LoginFail::getCachedData(); if ($failedLogins > 4) { return View::factory('base/alert')->set('sType', 'danger')->set('sMsg', __('to.many.incorrect.logins')); } $oLoginForm = Form::factory('login'); $oLoginForm->addField(Form\Field\Text::factory('login', $oLoginForm)); $oLoginForm->addField(Form\Field\Password::factory('password', $oLoginForm)); if ($oLoginForm->isSubmittedAndValid()) { $sUsername = $oLoginForm->get('login'); $sPassword = $oLoginForm->get('password'); $sEncryptedPassword = Helper\Encrypter::factory()->encrypt($sUsername, $sPassword); $oUser = DB::query("SELECT u FROM \\Model\\User u WHERE u.login = :login AND u.password = :pass")->param('login', $sUsername)->param('pass', $sEncryptedPassword)->single(); if ($oUser instanceof Model\User) { Session::set('username', $sUsername); Session::set('uid', (int) $oUser->getId()); $oUser->setLoginDateNOW(); DB::flush(); # Get role permissions for particular user and set them in session \UserPermissions::reset(); Route::factory(Router::getCurrentRouteName())->redirectTo(); } else { $currentUrl = Router::currentUrl(); $alert = __('You have entered wrong username or password. Try again.'); \User\LoginFail::addLoginFail(); Session::flash($currentUrl, $alert, 'danger'); } } $oLoginForm->addToSuffix(View::factory('user/frontend/login_links')->render()); return View::factory('base/form')->bind('oForm', $oLoginForm); }
/** @noinspection PhpMissingParentCallCommonInspection */ public function actionDefault() { // create pass recovery form $oForm = Form::factory('password_recovery'); $emailField = Form\Field\Text::factory('email', $oForm)->setRequired()->setLabel('E-mail'); $oForm->addField($emailField); $oForm->addField(Form\Field\Captcha::factory('captcha', $oForm)); // if form is valid if ($oForm->isSubmittedAndValid()) { $sEmail = $oForm->getField('email')->getValueFirst(); // find user with particular e-mail $query = DB::query('SELECT u FROM \\Model\\User u WHERE u.email = :email'); $query->param('email', $sEmail); $oResult = $query->single(); /* @var $oResult User */ if ($oResult instanceof User) { $this->sendRecoveryCode($oResult); $sMessage = __("Message has been sent on your e-mail address. Click on the link from it's content to recover password to your account."); Session::flash(Router::getCurrentUrl(), $sMessage); } } // return view return View::factory('user/frontend/recovery/default')->bind('oForm', $oForm); }
/** * Set new \Plethora\Form object to particular form Field if is singleton. * * @access public * @param Form $form * @return Field * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function setFormIfSingleton(Form &$form) { $form->addEnctype(); parent::setFormIfSingleton($form); // TODO: Change the autogenerated stub }
/** * Contructor. The search engine form is generated in here. * * @access public * @param ModelCore $oModel * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function __construct(ModelCore $oModel) { $this->oModel = $oModel; $sModelClass = $oModel->getClass(); $aQueryParams = Router::getQueryStringParams(); $aDefaults = []; $sFormName = 'search_engine_for_' . str_replace('\\', '_', strtolower($sModelClass)); if (count($aQueryParams) > 0) { foreach ($aQueryParams as $sKey => $sValue) { $aDefaults[$sKey] = ['und' => [0 => $sValue]]; } } $oForm = Form::factory($sFormName, $aDefaults)->setView($this->getFormView())->setFieldsNameWithPrefix(FALSE)->removeCsrfToken(); $this->setForm($oForm); }
/** * If this field is a singleton, append it to a particular form which is not a form for singletons. * * @access public * @param Form $form * @throws Exception * @throws Exception\Fatal * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function setFormIfSingleton(Form &$form) { if ($form->getName() === 'singletons') { throw new Exception\Fatal('You can\'t append this field to the singletons form.'); } elseif ($this->getFormObject()->getName() !== 'singletons') { throw new Exception\Fatal('This field is already appended to other form.'); } else { $rules = $this->getFormObject()->getValidator()->getRules($this->getName()); $this->oForm = $form; $this->oForm->addField($this); $this->oForm->getValidator()->rules($this->getName(), $rules); $this->resetAllNeededAttributes(); $this->setWeight($this->oForm->getLastWeight()); } }
/** * Method in which can do some operations before saving to database. * * @access protected * @param Form $form * @since 1.0.0-alpha * @version 1.0.0-alpha */ protected function beforeSave(Form &$form) { if ($this->getModel()->hasLocales()) { $aDoNotSaveFor = array_diff(Core::getLanguages(), $form->getCheckedLanguages()); foreach ($aDoNotSaveFor as $sLang) { $this->getModel()->removeLocales($sLang); } } if (property_exists($this->getModel(), 'author') && !$this->getModel()->getAuthor() instanceof User) { $this->getModel()->setAuthor(User::getLoggedUser()); } if (property_exists($this->getModel(), 'modification_date')) { $this->getModel()->updateModificationDate(); } }
/** * ACTION - Backend delete action. * * @access public * @return View * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function actionDelete() { try { $this->loadModelForActions(); } catch (Exception $oExc) { $this->addToTitle(__('Error')); $this->addSystemMessage('XXX', 'error'); die('TODO'); } // check permissions $this->checkPermissions('delete'); // add title ad breadcrumb $this->alterBreadcrumbsTitleDelete(); // confirm message $sMessage = __('Are you sure that want to remove item <b>:name</b> with ' . 'id <b>:id</b> from <b>:section</b> section?', ['name' => $this->getModel()->getEntityTitle(), 'id' => $this->getModel()->getId(), 'section' => __(strtolower(Router::getControllerName()))]); $this->addSystemMessage($sMessage, 'danger'); // delete form $oForm = new Form('delete_form'); $oForm->setSubmitValue(__('delete')); // if form submitted if ($oForm->isSubmittedAndValid()) { $this->alterDeleteUpdateSort(); $this->alterDelete(); } // return View return View::factory($this->sViewForm)->bind('oForm', $oForm)->set('sTitle', $this->getTitle()); }