/**
  * Looks up user supplied email address / alias and sends a mail
  *
  * @param $email email address or username
  */
 function sendMail($in)
 {
     $in = trim($in);
     if (is_email($in)) {
         $user_id = UserFinder::byEmail($in);
     } else {
         $user_id = UserFinder::byUsername($in);
     }
     $error = ErrorHandler::getInstance();
     if (!$user_id) {
         $error->add('Invalid email address or username');
         return false;
     }
     $email = UserSetting::getEmail($user_id);
     if (!$email) {
         throw new \Exception('entered email not found');
     }
     $code = Token::generate($user_id, 'activation_code');
     $pattern = array('/@USERNAME@/', '/@IP@/', '/@URL@/', '/@EXPIRETIME@/');
     $user = User::get($user_id);
     $page = XmlDocumentHandler::getInstance();
     $url = $page->getUrl() . 'u/reset_pwd/' . $code;
     $replacement = array($user->getName(), client_ip(), $url, shortTimePeriod($this->expire_time_email));
     $msg = preg_replace($pattern, $replacement, $this->password_msg);
     //d($msg);
     $mail = SendMail::getInstance();
     $mail->addRecipient($email);
     $mail->setSubject('Forgot password');
     $mail->send($msg);
     return true;
 }
Ejemplo n.º 2
0
         // marking item approved is all that's needed
         case MODERATE_UPLOAD:
         case MODERATE_USER:
         case MODERATE_PHOTO:
             break;
         default:
             throw new \Exception('Unhandled ModerationObject type ' . $o->type);
     }
     redir('a/moderation');
 }
 echo '<h1>Moderate object # ' . $this->child . '</h1>';
 switch ($o->type) {
     case MODERATE_CHANGE_USERNAME:
         $u = User::get($o->owner);
         echo '<h2>' . $u->name . ' wants to change username to ' . $o->data . '</h2>';
         if (UserFinder::byUsername($o->data)) {
             echo 'Username is taken!<br/>';
         } else {
             echo '&raquo; ' . ahref('?approve', 'Approve') . '<br/>';
         }
         echo '<br/>';
         echo '&raquo; ' . ahref('?deny', 'Deny') . '<br/>';
         break;
     case MODERATE_UPLOAD:
         echo '<h2>Moderate file with reference ' . $o->reference . '</h2>';
         if ($o->owner) {
             $u = User::get($o->owner);
             echo 'Uploaded by ' . $u->name;
         }
         $view = new ViewModel('views/user/file_details.php');
         $view->registerVar('owner', $o->data);