Example #1
0
 /**
  * Create new request and sends email to user
  * @static
  * @param string Mail adress
  * @throws MailFailureException, UserNotFoundException
  */
 public static function createRequest($mail)
 {
     LostPW::cleanUp();
     $user = User::find('email', $mail);
     if ($user == NULL) {
         throw new UserNotFoundException();
     }
     // Delete old requests
     $sql = System::getDatabase()->prepare('DELETE FROM lostpw WHERE user_ID = :uid');
     $sql->execute(array(':uid' => $user->uid));
     // Create new request
     $hash = LostPW::createHash();
     $sql = System::getDatabase()->prepare('INSERT INTO lostpw (user_ID, hash, time) VALUES (:uid, :hash, :time)');
     $sql->execute(array(':uid' => $user->uid, ':hash' => $hash, ':time' => time()));
     // Send Mail
     $content = new Template();
     $content->assign('link', Router::getInstance()->build('AuthController', 'lostpw_check', array('hash' => $hash)));
     $content->assign('user', $user);
     $content->assign('title', System::getLanguage()->_('LostPW'));
     // Determine template file
     $tpl = 'mails/lostpw.' . LANGUAGE . '.tpl';
     foreach ($content->getTemplateDir() as $dir) {
         $file = 'mails/lostpw.' . $user->lang . '.tpl';
         if (file_exists($dir . $file)) {
             $tpl = $file;
             break;
         }
     }
     $mail = new Mail(System::getLanguage()->_('LostPW'), $content->fetch($tpl), $user);
     $mail->send();
 }