예제 #1
0
 public function executeForgot(sfWebRequest $request)
 {
     $this->forward404If($this->getUser()->isAuthenticated());
     $this->form = new PasswordEmailForm();
     if ($request->isMethod('post') && $this->form->bindAndCheck($request->getParameter('forgot'))) {
         $user = AuthorPeer::retrieveByEmail($this->form->getValue('email'));
         if (!$user->getPassword()) {
             $this->getUser()->setFlash('notice', 'The provided email is not a normal account with a password to recover. You probably used Sign in with Twitter.');
             $this->redirect('@homepage');
         }
         $hash = md5(uniqid(time(), true));
         $user->setCheckHash($hash);
         $user->save();
         $mailBody = $this->getPartial('forgotEmail', array('hash' => $hash, 'name' => $user->getFirstName()));
         require_once 'lib/vendor/swift/swift_init.php';
         # needed due to symfony autoloader
         $mailer = Swift_Mailer::newInstance(Swift_MailTransport::newInstance());
         $message = Swift_Message::newInstance('Retrieve your password')->setFrom(array(sfConfig::get('app_webmaster_email') => 'MooTools Plugins'))->setTo(array($user->getEmail() => $user->getFullname()))->setBody($mailBody, 'text/html');
         $mailer->send($message);
         $this->getUser()->setFlash('notice', 'An email with a confirmation link has been sent');
     }
 }