Exemple #1
0
 public function doRecoverForm()
 {
     //$form = new \Floxim\Form\Form();
     $form = fx::data('floxim.form.form')->generate();
     $form->addFields(array('email' => array('label' => 'E-mail', 'validators' => 'email -l', 'value' => $this->getParam('email')), 'submit' => array('type' => 'submit', 'label' => fx::lang('Send me new password'))));
     if ($form->isSent() && !$form->hasErrors()) {
         $user = fx::data('floxim.user.user')->getByLogin($form->email);
         if (!$user) {
             $form->addError(fx::lang('User not found'), 'email');
         } else {
             $password = $user->generatePassword();
             $user['password'] = $password;
             $user->save();
             fx::data('session')->where('user_id', $user['id'])->delete();
             $mailer = fx::mail();
             $res = $mailer->to($form->email)->data('floxim.user.user', $user)->data('password', $password)->data('site', fx::env('site'))->template('user.password_recover')->send();
             if ($res) {
                 $form->addMessage('New password is sent to ' . $form->email);
             }
         }
     }
     return array('form' => $form);
 }