Example #1
0
 public function index()
 {
     $form = new SimpleForm\Form(array('name' => 'forgotpassword', 'action' => '', 'method' => 'post'));
     $form->AddChild(new SimpleForm\Elements\TextField(array('name' => 'email', 'label' => _('TXT_EMAIL'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_EMAIL')), new SimpleForm\Rules\Email(_('ERR_WRONG_EMAIL'))))));
     if ($form->Validate()) {
         $formData = $form->getSubmitValues();
         $result = App::getModel('forgotpassword')->authProccess($formData['email']);
         if ($result > 0) {
             $hash = App::getModel('forgotpassword')->generateLink($formData['email']);
             $link = $this->registry->router->generate('frontend.forgotpassword', true, array('action' => 'confirm', 'param' => $hash));
             $this->registry->template->assign('link', $link);
             App::getModel('mailer')->sendEmail(array('template' => 'forgotPassword', 'email' => array($formData['email']), 'bcc' => false, 'subject' => _('TXT_PASSWORD_FORGOT'), 'viewid' => Helper::getViewId()));
             Session::setVolatileSendPassword(1, false);
             Session::setVolatileForgotPasswordError();
         } elseif ($result < 0) {
             Session::setVolatileForgotPasswordError(2, false);
         } else {
             Session::setVolatileSendPassword();
             Session::setVolatileForgotPasswordError(1, false);
         }
     }
     $error = Session::getVolatileForgotPasswordError();
     if ($error[0] == 1) {
         $this->registry->template->assign('emailerror', _('ERR_EMAIL_NO_EXIST'));
     } elseif ($error[0] == 2) {
         $this->registry->template->assign('emailerror', _('TXT_BLOKED_USER'));
     }
     $sendPasswd = Session::getVolatileSendPassword();
     if ($sendPasswd[0] == 1) {
         $this->registry->template->assign('sendPasswd', _('TXT_CHECK_PRIVATE_MAIL_WITH_NEW_PASSWD'));
     }
     $this->registry->template->assign('form', $form->getForm());
     return $this->registry->template->fetch($this->loadTemplate('index.tpl'));
 }