/** * Method which changes form object before all operations (validation and saving). * * @access protected * @param Form $form * @since 1.0.1-dev, 2015-02-20 * @version 2.1.1-dev */ protected function alterForm(Form &$form) { parent::alterForm($form); $sCurrentRoute = Router::getCurrentRouteName(); # other pages switch ($sCurrentRoute) { // USER PASSWORD CHANGE case 'user_password_change': case 'password_recovery_code': $form->getField('password')->setLabel(__('New password')); $form->addField(Form\Field\Password::factory('new_password_confirm', $form)->setRequired()->setLabel(__('Confirm new password'))->addRule(['\\Plethora\\Validator\\Rules::sameAs', [':value', ':valuefrom:password']])); break; // USER REGISTRATION // USER REGISTRATION case 'register': $loginAttributes = $form->getField('login')->getAttributes(); $loginAttributes->removeAttribute('disabled'); $emailAttrs = $form->getField('email')->getAttributes(); $emailAttrs->removeAttribute('disabled'); $form->addField(Form\Field\Text::factory('email_confirm', $form)->setRequired()->setLabel(__('Confirm e-mail'))->setWeightToBeAfter('email')->addRule(['\\Plethora\\Validator\\Rules::sameAs', [':value', ':valuefrom:email']])); $form->getField('password')->setWeightToBeAfter('email_confirm'); $form->addField(Form\Field\Password::factory('password_confirm', $form)->setRequired()->setLabel(__('Confirm password'))->addRule(['\\Plethora\\Validator\\Rules::sameAs', [':value', ':valuefrom:password']])->setWeightToBeAfter('password')); break; } if (in_array($sCurrentRoute, ['backend', 'user_profile_edit', 'user_password_change'])) { $confirmField = Form\Field\PasswordConfirm::factory('password_check', $form); $confirmField->setLabel(__('Enter your password')); $confirmField->setTip(__('This field is used for a security purposes.')); $confirmField->setWeight(999); $confirmField->setPrefix('<div class="field_prefix" style="margin-top: 50px;"></div>'); $form->addField($confirmField); } if (in_array($sCurrentRoute, ['user_profile_edit'])) { $form->removeField('roles'); } if (in_array($sCurrentRoute, ['backend'])) { /* @var $password Field\Password */ $password = $form->getField('password'); $password->setRequiredNot(); } # captcha on needed pages if (in_array($sCurrentRoute, ['register'])) { $captchaField = Form\Field\Captcha::singleton('captcha'); $captchaField->setLabel(__('Security field')); $captchaField->setWeight(999999999); $captchaField->setFormIfSingleton($form); } }
/** @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); }