mail() public static method

Mailer:mail is intended as a more robust simple replacement for php mail(),.
public static mail ( array $to, string $subject, string $body, array $from ) : boolean
$to array address eg array('helpdesk@example.com'=>'OpenEyes')
$subject string
$body string
$from array address eg array('helpdesk@example.com'=>'OpenEyes')
return boolean mail sent without error
 public function control()
 {
     if (isset($_POST['Submit']) && $_POST['Submit'] == 'Send Reset') {
         $this->disableCaching();
         $dao = DAOFactory::getDAO('OwnerDAO');
         $user = $dao->getByEmail($_POST['email']);
         if (isset($user)) {
             $token = $user->setPasswordRecoveryToken();
             $es = new SmartyThinkUp();
             $es->caching = false;
             $config = Config::getInstance();
             $es->assign('apptitle', $config->getValue('app_title'));
             $es->assign('recovery_url', "session/reset.php?token={$token}");
             $es->assign('server', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost');
             $es->assign('site_root_path', $config->getValue('site_root_path'));
             $message = $es->fetch('_email.forgotpassword.tpl');
             Mailer::mail($_POST['email'], $config->getValue('app_title') . " Password Recovery", $message);
             $this->addSuccessMessage('Password recovery information has been sent to your email address.');
         } else {
             $this->addErrorMessage('Error: account does not exist.');
         }
     }
     $this->setViewTemplate('session.forgot.tpl');
     return $this->generateView();
 }
 public function control()
 {
     $config = Config::getInstance();
     $this->addToView('is_registration_open', $config->getValue('is_registration_open'));
     if (isset($_POST['Submit']) && $_POST['Submit'] == 'Send Reset') {
         $this->disableCaching();
         $dao = DAOFactory::getDAO('OwnerDAO');
         $user = $dao->getByEmail($_POST['email']);
         if (isset($user)) {
             $token = $user->setPasswordRecoveryToken();
             $es = new ViewManager();
             $es->caching = false;
             $es->assign('apptitle', $config->getValue('app_title_prefix') . "ThinkUp");
             $es->assign('recovery_url', "session/reset.php?token={$token}");
             $es->assign('application_url', Utils::getApplicationURL($false));
             $es->assign('site_root_path', $config->getValue('site_root_path'));
             $message = $es->fetch('_email.forgotpassword.tpl');
             Mailer::mail($_POST['email'], $config->getValue('app_title_prefix') . "ThinkUp Password Recovery", $message);
             $this->addSuccessMessage('Password recovery information has been sent to your email address.');
         } else {
             $this->addErrorMessage('Error: account does not exist.');
         }
     }
     $this->view_mgr->addHelp('forgot', 'userguide/accounts/index');
     $this->setViewTemplate('session.forgot.tpl');
     return $this->generateView();
 }
Beispiel #3
0
function sendSummary()
{
    $userMail = Mailer::mailFromUser('mail');
    if (!$userMail) {
        return false;
    }
    $userMail = stripslashes($userMail);
    $mailText = 'Hallo,' . "\n" . 'hier eine Zusammenfassung aller Bücher, die mit deiner E-Mailadresse angeboten werden.';
    $books = new UsersBooks($userMail);
    $mailText .= $books->toString();
    return Mailer::mail($userMail, 'Deine Angebote', $mailText);
}
 public function testMandrill()
 {
     $config = Config::getInstance();
     $config->setValue("app_title_prefix", "My Crazy Custom ");
     $config->setValue("mandrill_api_key", "1234567890");
     $_SERVER['HTTP_HOST'] = "thinkup.com";
     Mailer::mail('*****@*****.**', 'Testing 123', 'Me worky, yo?');
     $email_body = Mailer::getLastMail();
     $this->debug($email_body);
     // Exact JSON structure copied from Mandrill's site
     $json = '{"text":"Me worky, yo?","subject":"Testing 123","from_email":"*****@*****.**",' . '"from_name":"My Crazy Custom ThinkUp","to":[{"email":"*****@*****.**","name":"*****@*****.**"}]}';
     // Compare JSON string, ignoring whitespace differences
     $this->assertEqual($json, $email_body);
 }
Beispiel #5
0
 public function testFromName()
 {
     $config = Config::getInstance();
     $config->setValue("app_title_prefix", "My Crazy Custom ");
     $_SERVER['HTTP_HOST'] = "my_thinkup_hostname";
     Mailer::mail('*****@*****.**', 'Testing 123', 'Me worky, yo?');
     $email_body = Mailer::getLastMail();
     $this->debug($email_body);
     $this->assertPattern('/From: "My Crazy Custom ThinkUp" <notifications@my_thinkup_hostname>/', $email_body);
     $config->setValue("app_title_prefix", "My Other Installation of ");
     $_SERVER['HTTP_HOST'] = "my_other_hostname";
     Mailer::mail('*****@*****.**', 'Testing 123', 'Me worky, yo?');
     $email_body = Mailer::getLastMail();
     $this->debug($email_body);
     $this->assertPattern('/From: "My Other Installation of ThinkUp" <notifications@my_other_hostname>/', $email_body);
 }
require_once 'mysql_conn.php';
if (isset($_POST['subject'])) {
    require_once 'books/UsersBooks.php';
    require_once 'tools/Mailer.php';
    $subject = stripslashes($_POST['subject']);
    $text = stripslashes($_POST['text']);
    $query = 'select distinct mail from books';
    $result = mysql_query($query);
    $user_number = mysql_num_rows($result);
    $sent_mails = 0;
    while ($mail_row = mysql_fetch_row($result)) {
        $mail = $mail_row[0];
        $bookList = new UsersBooks($mail);
        $books = $bookList->toString();
        $mail_text = $text . $books;
        $success = Mailer::mail($mail, $subject, $mail_text);
        if ($success) {
            $sent_mails++;
        }
    }
    header('Location: admin_mail.php?sent_mails=' . $sent_mails . '&user_number=' . $user_number);
}
include 'header.php';
?>

<div class="menu"><span><a href="admin.php">&larr; Zurück zur
Administrationsübersicht</a></span></div>

  <?php 
if (isset($_GET['sent_mails'])) {
    ?>
 /**
  * Generates a one time upgrade token, and emails admins with the token info.
  */
 public static function generateUpgradeToken()
 {
     $token_file = FileDataManager::getDataPath('.htupgrade_token');
     $md5_token = '';
     if (!file_exists($token_file)) {
         $fp = fopen($token_file, 'w');
         if ($fp) {
             $token = self::TOKEN_KEY . rand(0, time());
             $md5_token = md5($token);
             if (!fwrite($fp, $md5_token)) {
                 throw new OpenFileException("Unable to write upgrade token file: " + $token_file);
             }
             fclose($fp);
         } else {
             throw new OpenFileException("Unable to create upgrade token file: " + $token_file);
         }
         // email our admin with this token.
         $owner_dao = DAOFactory::getDAO('OwnerDAO');
         $admins = $owner_dao->getAdmins();
         if ($admins) {
             $tos = array();
             foreach ($admins as $admin) {
                 $tos[] = $admin->email;
             }
             $to = join(',', $tos);
             $upgrade_email = new ViewManager();
             $upgrade_email->caching = false;
             $upgrade_email->assign('application_url', Utils::getApplicationURL(false));
             $upgrade_email->assign('token', $md5_token);
             $message = $upgrade_email->fetch('_email.upgradetoken.tpl');
             $config = Config::getInstance();
             Mailer::mail($to, "Upgrade Your ThinkUp Database", $message);
         }
     }
 }
 /**
  * Generates a one time upgrade token, and emails admins with the token info.
  */
 public function generateUpgradeToken()
 {
     $token_file = THINKUP_WEBAPP_PATH . self::CACHE_DIR . '/upgrade_token';
     $md5_token = '';
     if (!file_exists($token_file)) {
         $fp = fopen($token_file, 'w');
         if ($fp) {
             $token = self::TOKEN_KEY . rand(0, time());
             $md5_token = md5($token);
             if (!fwrite($fp, $md5_token)) {
                 throw new OpenFileException("Unable to write upgrade token file: " + $token_file);
             }
             fclose($fp);
         } else {
             throw new OpenFileException("Unable to create upgrade token file: " + $token_file);
         }
         // email our admin with this token.
         $owner_dao = DAOFactory::getDAO('OwnerDAO');
         $admins = $owner_dao->getAdmins();
         if ($admins) {
             $tos = array();
             foreach ($admins as $admin) {
                 $tos[] = $admin->email;
             }
             $to = join(',', $tos);
             $upgrade_email = new SmartyThinkUp();
             $upgrade_email->caching = false;
             $server = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
             //supress test weirdness
             $upgrade_email->assign('server', $server);
             $upgrade_email->assign('token', $md5_token);
             $message = $upgrade_email->fetch('_email.upgradetoken.tpl');
             $config = Config::getInstance();
             Mailer::mail($to, "Upgrade Your ThinkUp Database", $message);
         }
     }
 }
Beispiel #9
0
            if ($od->doesOwnerExist($_POST['email'])) {
                $errormsg = "User account already exists.";
            } else {
                $es = new SmartyThinkTank();
                $es->caching = false;
                $activ_code = rand(1000, 9999);
                $cryptpass = $session->pwdcrypt($_POST['pass2']);
                $server = $_SERVER['HTTP_HOST'];
                $od->create($_POST['email'], $cryptpass, $_POST['country'], $activ_code, $_POST['full_name']);
                $es->assign('apptitle', $THINKTANK_CFG['app_title']);
                $es->assign('server', $server);
                $es->assign('site_root_path', $THINKTANK_CFG['site_root_path']);
                $es->assign('email', urlencode($_POST[email]));
                $es->assign('activ_code', $activ_code);
                $message = $es->fetch('_email.registration.tpl');
                Mailer::mail($_POST['email'], "Activate Your " . $THINKTANK_CFG['app_title'] . " Account", $message);
                echo $message;
                unset($_SESSION['ckey']);
                $successmsg = "Success! Check your email for an activation link.";
            }
        }
        $s->assign('name', $_POST["full_name"]);
        $s->assign('mail', $_POST["email"]);
    }
    $challenge = $captcha->generate($msg);
    $s->assign('captcha', $challenge);
}
if (isset($errormsg)) {
    $s->assign('errormsg', $errormsg);
} elseif (isset($successmsg)) {
    $s->assign('successmsg', $successmsg);
 public function control()
 {
     if ($this->isLoggedIn()) {
         $controller = new DashboardController(true);
         return $controller->go();
     } else {
         $this->disableCaching();
         $config = Config::getInstance();
         if (!$config->getValue('is_registration_open')) {
             $this->addToView('closed', true);
             $this->addErrorMessage('<p>Sorry, registration is closed on this ThinkUp installation.</p>' . '<p><a href="http://github.com/ginatrapani/thinkup/tree/master">Install ThinkUp on your own ' . 'server.</a></p>');
         } else {
             $owner_dao = DAOFactory::getDAO('OwnerDAO');
             $this->addToView('closed', false);
             $captcha = new Captcha();
             if (isset($_POST['Submit']) && $_POST['Submit'] == 'Register') {
                 foreach ($this->REQUIRED_PARAMS as $param) {
                     if (!isset($_POST[$param]) || $_POST[$param] == '') {
                         $this->addErrorMessage('Please fill out all required fields.');
                         $this->is_missing_param = true;
                     }
                 }
                 if (!$this->is_missing_param) {
                     if (!Utils::validateEmail($_POST['email'])) {
                         $this->addErrorMessage("Incorrect email. Please enter valid email address.");
                     } elseif (strcmp($_POST['pass1'], $_POST['pass2']) || empty($_POST['pass1'])) {
                         $this->addErrorMessage("Passwords do not match.");
                     } elseif (!$captcha->check()) {
                         // Captcha not valid, captcha handles message...
                     } else {
                         if ($owner_dao->doesOwnerExist($_POST['email'])) {
                             $this->addErrorMessage("User account already exists.");
                         } else {
                             $es = new SmartyThinkUp();
                             $es->caching = false;
                             $session = new Session();
                             $activ_code = rand(1000, 9999);
                             $cryptpass = $session->pwdcrypt($_POST['pass2']);
                             $server = $_SERVER['HTTP_HOST'];
                             $owner_dao->create($_POST['email'], $cryptpass, $activ_code, $_POST['full_name']);
                             $es->assign('server', $server);
                             $es->assign('email', urlencode($_POST['email']));
                             $es->assign('activ_code', $activ_code);
                             $message = $es->fetch('_email.registration.tpl');
                             Mailer::mail($_POST['email'], "Activate Your " . $config->getValue('app_title') . " Account", $message);
                             unset($_SESSION['ckey']);
                             $this->addSuccessMessage("Success! Check your email for an activation link.");
                         }
                     }
                 }
                 if (isset($_POST["full_name"])) {
                     $this->addToView('name', $_POST["full_name"]);
                 }
                 if (isset($_POST["email"])) {
                     $this->addToView('mail', $_POST["email"]);
                 }
             }
             $challenge = $captcha->generate();
             $this->addToView('captcha', $challenge);
         }
         return $this->generateView();
     }
 }
Beispiel #11
0
 public function requestNewPassword()
 {
     $id = $_POST['user'];
     if (self::levelOf($id) < 1) {
         return;
     }
     self::cleanChallenges();
     $query = 'insert into challenge (Kunde, challenge) values' . ' ("' . $id . '", md5(rand()));';
     mysql_query($query);
     $query = 'select Kunde, challenge from challenge where' . ' Kunde="' . $id . '";';
     $result = mysql_query($query);
     if (mysql_num_rows($result) != 1) {
         return;
     }
     list($id, $challenge) = mysql_fetch_row($result);
     $subject = 'Neues Passwort';
     $content = "Hallo!\n\n" . 'Für Ihre E-Mailadresse wurde bei der Erlassdatenbank ein' . " neues Passwort beantragt.\n" . "Mit dem folgenden Link kann es neu gesetzt werden:\n" . WEBDIR . '?user='******'Diese Nachricht wurde automatisch versandt.';
     Mailer::mail($id, $subject, $content);
 }
Beispiel #12
0
 public function mailFromTemplate($code, $to, $replacements = array(), $options = array())
 {
     $this->findTemplateAndMakeReplacements($code, $replacements);
     return Mailer::mail($to, $this->_template->subject, $this->_template->plaintext_body, $this->_template->html_body, $options);
 }
Beispiel #13
0
 /**
  * 插入后置操作,向留言表增加刚插入id
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2013-03-01 13:30:52
  *
  * @param $data     插入数据
  * @param $options  查询表达式
  *
  * @return void 无返回值
  */
 protected function _afterInsert($data, $options)
 {
     if (TB_COMMENTS != $options['table']) {
         return;
     }
     $pk_value = $data[$this->_pk_field];
     if ($parent_info = C('T_PARENT_INFO')) {
         //父
         $max_reply_level = $this->_module->getGuestbookCommentsSetting(C('T_VERIFYCODE_MODULE'), 'max_reply_level');
         if ($max_reply_level == $parent_info['level']) {
             //最多5层回复
             $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . ',level>' . $max_reply_level . var_export($parent_info, true);
             trigger_error($log);
             $parent_info['level']--;
             $parent_info['node'] = substr($parent_info['node'], 0, strrpos($parent_info['node'], ','));
             $node_arr = explode(',', $parent_info['node']);
             $parent_id = $node_arr[$max_reply_level > 2 ? $max_reply_level - 2 : 1];
             //父级id取第四个
         }
         $update = array('level' => $parent_info['level'] + 1, 'node' => $parent_info['node'] . ',' . $pk_value);
         if (!empty($parent_id)) {
             $update['parent_id'] = $parent_id;
         }
         $this->where($this->_pk_field . '=' . $pk_value)->save($update);
         $this->where(array($this->_pk_field => array('IN', $parent_info['node'])))->save(array('last_reply_time' => time()));
         //更新最上层最后回复时间
     } else {
         $update = array('node' => $pk_value);
         $this->where($this->_pk_field . '=' . $pk_value)->save($update);
         //节点关系
     }
     if ($v = $this->_module->getGuestbookCommentsSetting(C('T_VERIFYCODE_MODULE'), 'alternation')) {
         //间隔
         session(C('T_VERIFYCODE_MODULE'), time() + $v);
     }
     $type = C('T_TYPE');
     if (!$this->_module->getGuestbookCommentsSetting(C('T_VERIFYCODE_MODULE'), 'check')) {
         //不需要审核
         if (COMMENT_TYPE_GUESTBOOK != $type) {
             //评论数+1
             $this->execute('UPDATE ' . (COMMENT_TYPE_BLOG == $type ? TB_BLOG : TB_MINIBLOG) . ' SET comments=comments+1 WHERE blog_id=' . $data['blog_id']);
         }
         if (($parent_info = C('T_PARENT_INFO')) && $parent_info['at_email']) {
             require_cache(LIB_PATH . 'Mailer.class.php');
             $mailer = new Mailer($this);
             $mailer->mail('comments_at_email', $parent_info);
         }
     }
     //总评论数+1
     COMMENT_TYPE_GUESTBOOK != $type && $this->execute('UPDATE ' . (COMMENT_TYPE_BLOG == $type ? TB_BLOG : TB_MINIBLOG) . ' SET total_comments=total_comments+1 WHERE blog_id=' . $data['blog_id']);
     $this->commit();
 }
Beispiel #14
0
 private function clean()
 {
     $subject = 'Suche beendet';
     $fixMailContent = 'Hallo!' . "\n" . "\n" . 'Folgende Suche(n) wurde(n) beendet und können über den Link neu' . "\n" . 'eingetragen werden:' . "\n";
     $toClean = array();
     $query = 'select search, mail from searches where life_counter=0;';
     $r = mysql_query($query);
     while ($search_array = mysql_fetch_array($r)) {
         $mail = $search_array['mail'];
         if (!isset($toClean[$mail])) {
             $toClean[$mail] = array();
         }
         $toClean[$mail][] = $search_array['search'];
     }
     $query = 'delete from searches where life_counter <= 0;';
     mysql_query($query);
     $query = 'update searches set life_counter = life_counter - 1;';
     mysql_query($query);
     foreach ($toClean as $mail => $searchArray) {
         $mailContent = $fixMailContent;
         foreach ($searchArray as $i => $search) {
             $mailContent .= "\n" . $search . "\n" . WEBDIR . 'save_search.php?search=' . urlencode($search) . '&mail=' . urlencode($mail) . "\n";
         }
         Mailer::mail($mail, $subject, $mailContent);
     }
 }
 /**
  * {@inheritDoc}
  */
 protected function _afterSetField($field, $value, $pk_id)
 {
     if ('status' == $field) {
         //审核状态
         $this->_afterAction();
         if ($at_email = C('T_INFO.at_email')) {
             require_cache(LIB_PATH . 'Mailer.class.php');
             $mailer = new Mailer($this->_model);
             foreach ($at_email as $v) {
                 $mailer->mail('comments_at_email', $v);
             }
         }
     }
 }
 /**
  * Step 3 - Populate database and finish
  */
 private function step3()
 {
     $this->setViewTemplate('install.step3.tpl');
     $config_file_exists = false;
     $config_file = THINKUP_WEBAPP_PATH . 'config.inc.php';
     // make sure we are here with posted data
     if (empty($_POST)) {
         $this->step1();
         return;
     }
     // check if we have made config.inc.php
     if (file_exists($config_file) && filesize($config_file) > 0) {
         // this is could be from step 2 is not able writing
         // to webapp dir
         $config_file_exists = true;
         require $config_file;
         $db_config['db_type'] = $THINKUP_CFG['db_type'];
         $db_config['db_name'] = $THINKUP_CFG['db_name'];
         $db_config['db_user'] = $THINKUP_CFG['db_user'];
         $db_config['db_password'] = $THINKUP_CFG['db_password'];
         $db_config['db_host'] = $THINKUP_CFG['db_host'];
         $db_config['db_socket'] = $THINKUP_CFG['db_socket'];
         $db_config['db_port'] = $THINKUP_CFG['db_port'];
         $db_config['table_prefix'] = $THINKUP_CFG['table_prefix'];
         $db_config['timezone'] = $THINKUP_CFG['timezone'];
         $email = trim($_POST['site_email']);
     } else {
         // make sure we're not from error or couldn't write config.inc.php
         if (!isset($_POST['db_user']) && !isset($_POST['db_passwd']) && !isset($_POST['db_name']) && !isset($_POST['db_host'])) {
             $this->addErrorMessage("Missing database credentials");
             $this->step2();
             return;
         }
         // trim each posted value
         $db_config['db_type'] = trim(@$_POST['db_type']);
         $db_config['db_name'] = trim($_POST['db_name']);
         $db_config['db_user'] = trim($_POST['db_user']);
         $db_config['db_password'] = trim($_POST['db_passwd']);
         $db_config['db_host'] = trim($_POST['db_host']);
         $db_config['db_socket'] = trim($_POST['db_socket']);
         $db_config['db_port'] = trim($_POST['db_port']);
         $db_config['table_prefix'] = trim($_POST['db_prefix']);
         $db_config['timezone'] = trim($_POST['timezone']);
         $email = trim($_POST['site_email']);
     }
     $db_config['db_type'] = 'mysql';
     //default for now
     $password = $_POST['password'];
     $confirm_password = $_POST['confirm_password'];
     $full_name = $_POST['full_name'];
     $display_errors = false;
     // check email
     if (!Utils::validateEmail($email)) {
         $this->addErrorMessage("Please enter a valid email address.", "email");
         $display_errors = true;
     }
     if ($password != $confirm_password || $password == '' || !preg_match("/(?=.{8,})(?=.*[a-zA-Z])(?=.*[0-9])/", $password)) {
         //check password
         if ($password != $confirm_password) {
             $this->addErrorMessage("Your passwords did not match.", "password");
         } else {
             if ($password == '') {
                 $this->addErrorMessage("Please choose a password.", "password");
             } else {
                 if (!preg_match("/(?=.{8,})(?=.*[a-zA-Z])(?=.*[0-9])/", $password)) {
                     $this->addErrorMessage("Password must be at least 8 characters and contain both numbers and letters.", "password");
                 }
             }
         }
         $display_errors = true;
     }
     if ($_POST['db_name'] == '') {
         $this->addErrorMessage("Please enter a database name.", "database_name");
         $display_errors = true;
     }
     if ($_POST['db_host'] == '') {
         $this->addErrorMessage("Please enter a database host.", "database_host");
         $display_errors = true;
     }
     if ($_POST['timezone'] == '') {
         $this->addErrorMessage("Please select a time zone.", "timezone");
         $display_errors = true;
     }
     if (($error = $this->installer->checkDb($db_config)) !== true) {
         //check db
         if (($p = strpos($error->getMessage(), "Unknown MySQL server host")) !== false || ($p = strpos($error->getMessage(), "Can't connect to MySQL server")) !== false || ($p = strpos($error->getMessage(), "Can't connect to local MySQL server through socket")) !== false || ($p = strpos($error->getMessage(), "Access denied for user")) !== false) {
             $db_error = substr($error->getMessage(), $p);
         } else {
             $db_error = $error->getMessage();
         }
         $disable_xss = true;
         $db_error = filter_var($db_error, FILTER_SANITIZE_SPECIAL_CHARS);
         $this->addErrorMessage("ThinkUp couldn't connect to your database. The error message is:<br /> " . " <strong>{$db_error}</strong><br />Please correct your database information and try again.", "database", $disable_xss);
         $display_errors = true;
     }
     if ($display_errors) {
         $this->setViewTemplate('install.step2.tpl');
         $this->addToView('db_name', $db_config['db_name']);
         $this->addToView('db_user', $db_config['db_user']);
         $this->addToView('db_passwd', $db_config['db_password']);
         $this->addToView('db_host', $db_config['db_host']);
         $this->addToView('db_prefix', $db_config['table_prefix']);
         $this->addToView('db_socket', $db_config['db_socket']);
         $this->addToView('db_port', $db_config['db_port']);
         $this->addToView('db_type', $db_config['db_type']);
         $this->addToView('current_tz', $_POST['timezone']);
         $this->addToView('tz_list', $this->getTimeZoneList());
         $this->addToView('site_email', $email);
         $this->addToView('full_name', $full_name);
         return;
     }
     $admin_user = array('email' => $email, 'password' => $password, 'confirm_password' => $confirm_password);
     // trying to create config file
     if (!$config_file_exists && !$this->installer->createConfigFile($db_config, $admin_user)) {
         $config_file_contents_arr = $this->installer->generateConfigFile($db_config, $admin_user);
         $config_file_contents_str = '';
         foreach ($config_file_contents_arr as $line) {
             $config_file_contents_str .= htmlentities($line);
         }
         $whoami = @exec('whoami');
         $disable_xss = true;
         if (!empty($whoami)) {
             $whoami = filter_var($whoami, FILTER_SANITIZE_SPECIAL_CHARS);
             $this->addErrorMessage("ThinkUp couldn't write the <code>config.inc.php</code> file.<br /><br />" . "Use root (or sudo) to create the file manually, and allow PHP to write to it, by executing the " . "following commands:<br /><code>sudo touch " . escapeshellcmd(THINKUP_WEBAPP_PATH . "config.inc.php") . "</code><br /><code>sudo chown {$whoami} " . escapeshellcmd(THINKUP_WEBAPP_PATH . "config.inc.php") . "</code><br /><br />If you don't have root access, create the <code>" . THINKUP_WEBAPP_PATH . "config.inc.php</code> file, show the contents of your config file below," . " and copy and paste the text into the <code>config.inc.php</code> file.", null, $disable_xss);
         } else {
             $this->addErrorMessage("ThinkUp couldn't write the <code>config.inc.php</code> file.<br /><br />" . "You will need to create the <code>" . THINKUP_WEBAPP_PATH . "config.inc.php</code> file manually, and paste the following text into it.", null, $disable_xss);
         }
         $this->addToView('config_file_contents', $config_file_contents_str);
         $this->addToView('_POST', $_POST);
         $this->setViewTemplate('install.config.tpl');
         return;
     }
     unset($admin_user['confirm_password']);
     // check tables
     $this->installer->checkTable($db_config);
     // if empty, we're ready to populate the database with ThinkUp tables
     $this->installer->populateTables($db_config);
     //Set the application server name in app settings for access by command-line scripts
     Installer::storeServerName();
     $owner_dao = DAOFactory::getDAO('OwnerDAO', $db_config);
     if (!$owner_dao->doesAdminExist() && !$owner_dao->doesOwnerExist($email)) {
         // create admin if not exists
         $activation_code = $owner_dao->createAdmin($email, $password, $full_name);
         // view for email
         $cfg_array = array('site_root_path' => Utils::getSiteRootPathFromFileSystem(), 'source_root_path' => THINKUP_ROOT_PATH, 'debug' => false, 'app_title_prefix' => "", 'cache_pages' => false);
         $email_view = new ViewManager($cfg_array);
         $email_view->caching = false;
         $email_view->assign('application_url', Utils::getApplicationURL());
         $email_view->assign('email', urlencode($email));
         $email_view->assign('activ_code', $activation_code);
         $message = $email_view->fetch('_email.registration.tpl');
         Mailer::mail($email, "Activate Your New ThinkUp  Account", $message);
     } else {
         $email = 'Use your old email admin';
         $password = '******';
     }
     unset($THINKUP_CFG);
     $this->addToView('errors', $this->installer->getErrorMessages());
     $this->addToView('username', $email);
     $this->addToView('password', $password);
     $this->addToView('login_url', Utils::getSiteRootPathFromFileSystem() . 'session/login.php');
 }
Beispiel #17
0
 public function sendFirstQueued()
 {
     $message = self::model()->firstQueued();
     if (!$message->student->email) {
         return 0;
     }
     // acknowledged_at is null for not yet acknowledged messages
     // and it is set to 0 for messages that do not need to be acknowledged
     if (Mailer::mail(array($message->student->email => $message->student->__toString()), $message->subject, $message->body, $message->html, array('ack' => is_null($message->acknowledged_at) ? array('message_id' => $message->id) : false, 'message_id' => $message->id))) {
         $message->sent_at = date('Y-m-d H:i:s');
         $message->save(false);
         return 1;
     } else {
         return 0;
     }
 }
Beispiel #18
0
$s = new SmartyThinkTank();
$s->caching = false;
if ($_POST['Submit'] == 'Send') {
    if ($od->doesOwnerExist($_POST['email'])) {
        $newpwd = rand(10000, 99999);
        $server = $_SERVER['HTTP_HOST'];
        $cryptpass = $session->pwdcrypt($newpwd);
        $od->updatePassword($_POST['email'], $cryptpass);
        $es = new SmartyThinkTank();
        $es->caching = false;
        $es->assign('apptitle', $THINKTANK_CFG['app_title']);
        $es->assign('email', $_POST['email']);
        $es->assign('newpwd', $newpwd);
        $es->assign('server', $server);
        $es->assign('site_root_path', $THINKTANK_CFG['site_root_path']);
        $message = $es->fetch('_email.forgotpassword.tpl');
        Mailer::mail($_POST['email'], "The " . $THINKTANK_CFG['app_title'] . " Account Details You Requested", $message);
        $successmsg = "Password recovery information has been sent to your email address. <a href=\"login.php\">Sign in.</a>";
    } else {
        $errormsg = "Account does not exist";
    }
}
if (isset($errormsg)) {
    $s->assign('errormsg', $errormsg);
} elseif (isset($successmsg)) {
    $s->assign('successmsg', $successmsg);
}
$db->closeConnection($conn);
$cfg = new Config();
$s->assign('cfg', $cfg);
$s->display('session.forgot.tpl');
Beispiel #19
0
$od = DAOFactory::getDAO('OwnerDAO');
$s = new SmartyThinkTank();
$s->caching = false;
if (isset($_POST['Submit']) && $_POST['Submit'] == 'Send') {
    if ($od->doesOwnerExist($_POST['email'])) {
        $newpwd = rand(10000, 99999);
        $server = $_SERVER['HTTP_HOST'];
        $cryptpass = $session->pwdcrypt($newpwd);
        $od->updatePassword($_POST['email'], $cryptpass);
        $es = new SmartyThinkTank();
        $es->caching = false;
        $es->assign('apptitle', $config->getValue('app_title'));
        $es->assign('email', $_POST['email']);
        $es->assign('newpwd', $newpwd);
        $es->assign('server', $server);
        $es->assign('site_root_path', $config->getValue('site_root_path'));
        $message = $es->fetch('_email.forgotpassword.tpl');
        Mailer::mail($_POST['email'], "The " . $config->getValue('app_title') . " Account Details You Requested", $message);
        $successmsg = "Password recovery information has been sent to your email address. <a href=\"login.php\">Sign in.</a>";
    } else {
        $errormsg = "Account does not exist";
    }
}
if (isset($errormsg)) {
    $s->assign('errormsg', $errormsg);
} elseif (isset($successmsg)) {
    $s->assign('successmsg', $successmsg);
}
$db->closeConnection($conn);
$s->assign('site_root_path', $config->getValue('site_root_path'));
$s->display('session.forgot.tpl');
Beispiel #20
0
            if ($od->doesOwnerExist($_POST['email'])) {
                $errormsg = "User account already exists.";
            } else {
                $es = new SmartyThinkTank();
                $es->caching = false;
                $activ_code = rand(1000, 9999);
                $cryptpass = $session->pwdcrypt($_POST['pass2']);
                $server = $_SERVER['HTTP_HOST'];
                $od->create($_POST['email'], $cryptpass, $_POST['country'], $activ_code, $_POST['full_name']);
                $es->assign('apptitle', $config->getValue('app_title'));
                $es->assign('server', $server);
                $es->assign('site_root_path', $config->getValue('site_root_path'));
                $es->assign('email', urlencode($_POST['email']));
                $es->assign('activ_code', $activ_code);
                $message = $es->fetch('_email.registration.tpl');
                Mailer::mail($_POST['email'], "Activate Your " . $config->getValue('app_title') . " Account", $message);
                // echo $message; // debug
                unset($_SESSION['ckey']);
                $successmsg = "Success! Check your email for an activation link.";
            }
        }
        $s->assign('name', $_POST["full_name"]);
        $s->assign('mail', $_POST["email"]);
    }
    $challenge = $captcha->generate();
    $s->assign('captcha', $challenge);
}
if (isset($errormsg)) {
    $s->assign('errormsg', $errormsg);
} elseif (isset($successmsg)) {
    $s->assign('successmsg', $successmsg);
 /**
  * Send user email alert about invalid OAuth tokens. In test mode, this will only write the message body to a file
  * in the application data directory.
  * @param str $email
  * @param str $username
  */
 private function sendInvalidOAuthEmailAlert($email, $username)
 {
     $mailer_view_mgr = new SmartyThinkUp();
     $mailer_view_mgr->caching = false;
     $server = $_SERVER['HTTP_HOST'];
     $mailer_view_mgr->assign('server', $server);
     $mailer_view_mgr->assign('email', $email);
     $mailer_view_mgr->assign('faceboook_user_name', $username);
     $message = $mailer_view_mgr->fetch(Utils::getPluginViewDirectory('facebook') . '_email.invalidtoken.tpl');
     Mailer::mail($email, "Please re-authorize ThinkUp to access " . $username . " on Facebook", $message);
 }
 /**
  * Send out insight email digest for a given time period.
  * @param Owner $owner Owner to send for
  * @param str $start When to start insight lookup
  * @param str $template Email view template to use
  * @param array $options Plugin options
  * @param bool $weekly Is this a weekly email?
  * return bool Whether email was sent
  */
 private function sendDigestSinceWithTemplate($owner, $start, $template, &$options, $weekly)
 {
     $insights_dao = DAOFactory::GetDAO('InsightDAO');
     $start_time = date('Y-m-d H:i:s', strtotime($start, $this->current_timestamp));
     $insights = $insights_dao->getAllOwnerInstanceInsightsSince($owner->id, $start_time);
     $num_insights = count($insights);
     if ($num_insights == 0) {
         return false;
     }
     $config = Config::getInstance();
     $view = new ViewManager();
     $view->caching = false;
     $logger = Logger::getInstance();
     // If we've got a Mandrill key and template, send HTML
     if ($config->getValue('mandrill_api_key') != null && !empty($options['mandrill_template'])) {
         $logger->logUserInfo("Mandrill API key and template set; sending HTML", __METHOD__ . ',' . __LINE__);
         $view->assign('insights', $insights);
         $view->assign('application_url', Utils::getApplicationURL());
         $view->assign('header_text', $this->getEmailMessageHeaderText());
         if (Utils::isThinkUpLLC()) {
             $logger->logUserInfo("Email via ThinkUpLLC, process welcome / free trial messaging", __METHOD__ . ',' . __LINE__);
             $thinkupllc_endpoint = $config->getValue('thinkupllc_endpoint');
             $view->assign('thinkupllc_endpoint', $thinkupllc_endpoint);
             $view->assign('unsub_url', $thinkupllc_endpoint . 'settings.php');
             $view->assign('install_folder', $config->getValue('install_folder'));
             if (!isset($options['last_daily_email'])) {
                 $logger->logUserInfo("No daily email ever sent before, include welcome message", __METHOD__ . ',' . __LINE__);
                 $view->assign('show_welcome_message', true);
             } else {
                 if ($owner->is_free_trial) {
                     $logger->logUserInfo("Owner is in free trial", __METHOD__ . ',' . __LINE__);
                     $creation_date = new DateTime($owner->joined);
                     $now = new DateTime();
                     $end_of_trial = $creation_date->add(new DateInterval('P15D'));
                     if ($end_of_trial >= $now) {
                         $interval = $now->diff($end_of_trial);
                         $days_left = $interval->format('%a');
                         if ($days_left > 2) {
                             $view->assign('pay_prompt_headline', $days_left . ' days left in your free trial!');
                         } elseif ($days_left == 0) {
                             //Last day
                             $view->assign('pay_prompt_headline', 'Last chance!');
                         } else {
                             //Show hours if it's 24 or 48 hours
                             $view->assign('pay_prompt_headline', 'Only ' . $days_left * 24 . ' hours left!');
                         }
                         $explainer_copy_options = array("Your free trial expires today. Don't lose any of your insights!", "It's time to become a member. We'd love to have you.", "It's just " . ($owner->membership_level == 'Member' ? '16' : '32') . " cents a day to get smarter about the time you spend online.", "Isn't this better than boring \"analytics\"?", "Just wait 'til you see ThinkUp next week.", "We never sell your data and we don't show you ads.", "Get our exclusive book on the future of social media for free.", "ThinkUp gives you social network superpowers.", "The longer you use ThinkUp, the smarter it gets.", "ThinkUp helps you be more thoughtful about your time online.", "ThinkUp works in email, on the web, and on all your devices.", "ThinkUp members can cancel at any time—with no hassles.", 'Wait until you see what ThinkUp has in store tomorrow.', "Your morning ThinkUp email will make your day.");
                         $view->assign('pay_prompt_explainer', $explainer_copy_options[$days_left]);
                         if ($owner->membership_level == 'Member') {
                             $view->assign('pay_prompt_button_label', 'Just $5/month');
                         } elseif ($owner->membership_level == 'Pro') {
                             $view->assign('pay_prompt_button_label', 'Just $10/month');
                         }
                     }
                 } else {
                     //Check subscription status and show a message if Payment failed or due
                     $logger->logUserInfo("User is not in free trial; check subscription status", __METHOD__ . ',' . __LINE__);
                     $thinkupllc_api_accessor = new ThinkUpLLCAPIAccessor();
                     $membership_details = $thinkupllc_api_accessor->getSubscriptionStatus($owner->email);
                     $logger->logUserInfo("Subscription status is " . Utils::varDumpToString($membership_details), __METHOD__ . ',' . __LINE__);
                     if (isset($membership_details->subscription_status) && ($membership_details->subscription_status == 'Payment failed' || $membership_details->subscription_status == 'Payment due')) {
                         $logger->logUserInfo("Owner has payment failure; include alert in email", __METHOD__ . ',' . __LINE__);
                         $payment_failed_copy = array();
                         if ($membership_details->subscription_status == 'Payment failed') {
                             $payment_failed_copy[] = array('headline' => 'Oops! Your account needs attention', 'explainer' => "We had a problem processing your membership payment. " . "But it's easy to fix.");
                             $payment_failed_copy[] = array('headline' => 'Uh oh, problem with your subscription...', 'explainer' => "There was a problem processing your membership payment. " . "To fix it, update your payment info.");
                             $payment_failed_copy[] = array('headline' => 'Your ThinkUp subscription is out of date...', 'explainer' => "We tried to charge your Amazon account for your ThinkUp membership," . " and there was an error. But it's easy to fix.");
                             $payment_failed_copy[] = array('headline' => 'Action required to keep your ThinkUp account active', 'explainer' => "We weren't able to process your last membership payment—maybe your " . "info is out of date? Fixing it just takes a moment.");
                             $payment_failed_copy[] = array('headline' => "Urgent! Keep your ThinkUp account active", 'explainer' => "We tried to process your ThinkUp subscription, but " . "the payment was not successful. Please update your payment information " . "now to make sure your ThinkUp membership stays in good standing.");
                             $payment_failed_button_label = "Update your payment info";
                         } else {
                             //Payment due
                             $payment_failed_copy[] = array('headline' => 'Oops! Your ThinkUp membership needs attention', 'explainer' => "Looks like you've got a membership payment due. " . "But it's easy to make it.");
                             $payment_failed_copy[] = array('headline' => "Uh-oh, don't let your subscription expire", 'explainer' => "Looks like your ThinkUp payment is due. " . "Make it now so your account doesn't expire.");
                             $payment_failed_copy[] = array('headline' => 'Hey, your ThinkUp subscription payment is due', 'explainer' => "Your membership payment isn't up-to-date. " . " But it's easy to fix.");
                             $payment_failed_copy[] = array('headline' => 'Action required: Keep your ThinkUp account active', 'explainer' => "Looks like you've got a membership payment due. " . "Making it just takes a moment.");
                             $payment_failed_copy[] = array('headline' => "Urgent! Keep your ThinkUp account active", 'explainer' => "Your subscription payment is due. " . "Please update your information now to keep your ThinkUp membership " . "in good standing.");
                             $payment_failed_button_label = "Make your payment";
                         }
                         $copy_index = TimeHelper::getDayOfYear() % count($payment_failed_copy);
                         $payment_failed_headline = $payment_failed_copy[$copy_index]['headline'];
                         $payment_failed_explainer = $payment_failed_copy[$copy_index]['explainer'];
                         $view->assign('payment_failed_headline', $payment_failed_headline);
                         $view->assign('payment_failed_explainer', $payment_failed_explainer);
                         $view->assign('payment_failed_button_label', $payment_failed_button_label);
                     }
                 }
             }
             $thinkupllc_email_tout = $config->getValue('thinkupllc_email_tout');
             if (isset($thinkupllc_email_tout)) {
                 $view->assign('thinkupllc_email_tout', $thinkupllc_email_tout);
             }
         } else {
             $logger->logUserInfo("Email is NOT via ThinkUpLLC", __METHOD__ . ',' . __LINE__);
             $view->assign('unsub_url', Utils::getApplicationURL() . 'account/index.php?m=manage#instances');
         }
         // It's a weekly digest if we're going back more than a day or two.
         $daily_or_weekly = $weekly ? 'Weekly' : 'Daily';
         $view->assign('weekly_or_daily', $daily_or_weekly);
         $view->assign('pay_prompt_url', $config->getValue('thinkupllc_endpoint') . 'membership.php');
         if ($config->getValue('image_proxy_enabled') == true) {
             $view->assign('image_proxy_sig', $config->getValue('image_proxy_sig'));
         }
         $insights_markup = $view->fetch(Utils::getPluginViewDirectory($this->folder_name) . '_email.insights_html.tpl');
         $parameters = array();
         $parameters['insights'] = $insights_markup;
         $parameters['app_title'] = $config->getValue('app_title_prefix') . "ThinkUp";
         $parameters['application_url'] = Utils::getApplicationURL();
         $parameters['weekly_or_daily'] = $daily_or_weekly;
         try {
             if (!isset($options['last_daily_email'])) {
                 $subject_line = "Welcome to ThinkUp! Here are your insights.";
             } else {
                 $subject_line = $this->getEmailMessageSubjectLine($daily_or_weekly, $insights);
             }
             $logger->logUserInfo("About to call Mailer::mailHTMLViaMandrillTemplate", __METHOD__ . ',' . __LINE__);
             Mailer::mailHTMLViaMandrillTemplate($owner->email, $subject_line, $options['mandrill_template']->option_value, $parameters);
             return true;
         } catch (Mandrill_Unknown_Template $e) {
             // In this case, we'll fall back to plain text sending and warn the user in the log
             $logger->logUserError("Invalid mandrill template configured:" . $options['mandrill_template']->option_value . ".", __METHOD__ . ',' . __LINE__);
             unset($options['mandrill_template']);
         }
     } else {
         if ($config->getValue('mandrill_api_key') == null) {
             $logger->logUserInfo("Mandrill API key is null", __METHOD__ . ',' . __LINE__);
         }
         if (empty($options['mandrill_template'])) {
             $logger->logUserInfo("Mandrill template is not set", __METHOD__ . ',' . __LINE__);
         }
     }
     $view->assign('app_title', $config->getValue('app_title_prefix') . "ThinkUp");
     $view->assign('application_url', Utils::getApplicationURL());
     $view->assign('insights', $insights);
     $message = $view->fetch(Utils::getPluginViewDirectory($this->folder_name) . $template);
     list($subject, $message) = explode("\n", $message, 2);
     $logger->logUserInfo("About to call Mailer::mail", __METHOD__ . ',' . __LINE__);
     Mailer::mail($owner->email, $subject, $message);
     return true;
 }
 /**
  * Send out insight email digest for a given time period.
  * @param Owner $owner Owner to send for
  * @param str $start When to start insight lookup
  * @param str $template Email view template to use
  * @param array $options Plugin options
  * return bool Whether email was sent
  */
 private function sendDigestSinceWithTemplate($owner, $start, $template, &$options)
 {
     $insights_dao = DAOFactory::GetDAO('InsightDAO');
     $start_time = date('Y-m-d H:i:s', strtotime($start, $this->current_timestamp));
     $insights = $insights_dao->getAllOwnerInstanceInsightsSince($owner->id, $start_time);
     if (count($insights) == 0) {
         return false;
     }
     $config = Config::getInstance();
     $view = new ViewManager();
     $view->caching = false;
     // If we've got a Mandrill key and template, send HTML
     if ($config->getValue('mandrill_api_key') != null && !empty($options['mandrill_template'])) {
         $view->assign('insights', $insights);
         $insights = $view->fetch(Utils::getPluginViewDirectory($this->folder_name) . '_email.insights_html.tpl');
         $parameters = array();
         $parameters['insights'] = $insights;
         $parameters['app_title'] = $config->getValue('app_title_prefix') . "ThinkUp";
         $parameters['app_url'] = Utils::getApplicationURL();
         $parameters['unsub_url'] = Utils::getApplicationURL() . 'account/index.php?m=manage#instances';
         // It's a weekly digest if we're going back more than a day or two.
         $days_ago = ($this->current_timestamp - strtotime($start)) / (60 * 60 * 24);
         $parameters['weekly_or_daily'] = $days_ago > 2 ? 'Weekly' : 'Daily';
         try {
             Mailer::mailHTMLViaMandrillTemplate($owner->email, 'ThinkUp has new insights for you!', $options['mandrill_template']->option_value, $parameters);
             return true;
         } catch (Mandrill_Unknown_Template $e) {
             // In this case, we'll fall back to plain text sending and warn the user in the log
             $logger = Logger::getInstance();
             $logger->logUserError("Invalid mandrill template configured:" . $options['mandrill_template']->option_value . ".", __METHOD__ . ',' . __LINE__);
             unset($options['mandrill_template']);
         }
     }
     $view->assign('apptitle', $config->getValue('app_title_prefix') . "ThinkUp");
     $view->assign('application_url', Utils::getApplicationURL());
     $view->assign('insights', $insights);
     $message = $view->fetch(Utils::getPluginViewDirectory($this->folder_name) . $template);
     list($subject, $message) = explode("\n", $message, 2);
     Mailer::mail($owner->email, $subject, $message);
     return true;
 }
 public function control()
 {
     if ($this->isLoggedIn()) {
         $controller = new DashboardController(true);
         return $controller->go();
     } else {
         $config = Config::getInstance();
         $is_registration_open = $config->getValue('is_registration_open');
         $this->disableCaching();
         $invite_dao = DAOFactory::getDAO('InviteDAO');
         if (isset($_GET['code'])) {
             $invite_code = $_GET['code'];
         } else {
             $invite_code = null;
         }
         $this->addToView('invite_code', $invite_code);
         $is_invite_code_valid = $invite_dao->isInviteValid($invite_code);
         if (!$is_registration_open && !$is_invite_code_valid) {
             $this->addToView('closed', true);
             $this->addErrorMessage('<p>Sorry, registration is closed on this ThinkUp installation.</p>' . '<p><a href="http://thinkupapp.com">Install ThinkUp on your own server.</a></p>');
         } else {
             $owner_dao = DAOFactory::getDAO('OwnerDAO');
             $this->addToView('closed', false);
             $captcha = new Captcha();
             if (isset($_POST['Submit']) && $_POST['Submit'] == 'Register') {
                 foreach ($this->REQUIRED_PARAMS as $param) {
                     if (!isset($_POST[$param]) || $_POST[$param] == '') {
                         $this->addErrorMessage('Please fill out all required fields.');
                         $this->is_missing_param = true;
                     }
                 }
                 if (!$this->is_missing_param) {
                     $valid_input = true;
                     if (!Utils::validateEmail($_POST['email'])) {
                         $this->addErrorMessage("Incorrect email. Please enter valid email address.", 'email');
                         $valid_input = false;
                     }
                     if (strcmp($_POST['pass1'], $_POST['pass2']) || empty($_POST['pass1'])) {
                         $this->addErrorMessage("Passwords do not match.", 'password');
                         $valid_input = false;
                     } else {
                         if (strlen($_POST['pass1']) < 5) {
                             $this->addErrorMessage("Password must be at least 5 characters.", 'password');
                             $valid_input = false;
                         }
                     }
                     if (!$captcha->doesTextMatchImage()) {
                         $this->addErrorMessage("Entered text didn't match the image. Please try again.", 'captcha');
                         $valid_input = false;
                     }
                     if ($valid_input) {
                         if ($owner_dao->doesOwnerExist($_POST['email'])) {
                             $this->addErrorMessage("User account already exists.", 'email');
                         } else {
                             // Insert the details into the database
                             $activation_code = $owner_dao->create($_POST['email'], $_POST['pass2'], $_POST['full_name']);
                             if ($activation_code != false) {
                                 $es = new SmartyThinkUp();
                                 $es->caching = false;
                                 $server = $_SERVER['HTTP_HOST'];
                                 $es->assign('server', $server);
                                 $es->assign('email', urlencode($_POST['email']));
                                 $es->assign('activ_code', $activation_code);
                                 $message = $es->fetch('_email.registration.tpl');
                                 Mailer::mail($_POST['email'], "Activate Your " . $config->getValue('app_title') . " Account", $message);
                                 SessionCache::unsetKey('ckey');
                                 $this->addSuccessMessage("Success! Check your email for an activation link.");
                                 //delete invite code
                                 if ($is_invite_code_valid) {
                                     $invite_dao->deleteInviteCode($invite_code);
                                 }
                             } else {
                                 $this->addErrorMessage("Unable to register a new user. Please try again.");
                             }
                         }
                     }
                 }
                 if (isset($_POST["full_name"])) {
                     $this->addToView('name', $_POST["full_name"]);
                 }
                 if (isset($_POST["email"])) {
                     $this->addToView('mail', $_POST["email"]);
                 }
             }
             $challenge = $captcha->generate();
             $this->addToView('captcha', $challenge);
         }
         $this->view_mgr->addHelp('register', 'userguide/accounts/index');
         return $this->generateView();
     }
 }
Beispiel #25
0
 public function mail($to, $template, $context = array())
 {
     $this->counter++;
     return parent::mail($to, $template, $context);
 }
 /**
  * Step 3 - Populate database and finish
  */
 private function step3()
 {
     $this->setViewTemplate('install.step3.tpl');
     $config_file_exists = false;
     $config_file = THINKUP_WEBAPP_PATH . 'config.inc.php';
     // make sure we are here with posted data
     if (empty($_POST)) {
         $this->step1();
         return;
     }
     // check if we have made config.inc.php
     if (file_exists($config_file) && filesize($config_file) > 0) {
         // this is could be from step 2 is not able writing
         // to webapp dir
         $config_file_exists = true;
         require $config_file;
         $db_config['db_type'] = $THINKUP_CFG['db_type'];
         $db_config['db_name'] = $THINKUP_CFG['db_name'];
         $db_config['db_user'] = $THINKUP_CFG['db_user'];
         $db_config['db_password'] = $THINKUP_CFG['db_password'];
         $db_config['db_host'] = $THINKUP_CFG['db_host'];
         $db_config['db_socket'] = $THINKUP_CFG['db_socket'];
         $db_config['db_port'] = $THINKUP_CFG['db_port'];
         $db_config['table_prefix'] = $THINKUP_CFG['table_prefix'];
         $db_config['GMT_offset'] = $THINKUP_CFG['GMT_offset'];
         $db_config['timezone'] = $THINKUP_CFG['timezone'];
         $email = trim($_POST['site_email']);
     } else {
         // make sure we're not from error of couldn't write config.inc.php
         if (!isset($_POST['db_user']) && !isset($_POST['db_passwd']) && !isset($_POST['db_name']) && !isset($_POST['db_host'])) {
             $this->addErrorMessage("Missing database credentials");
             $this->step2();
             return;
         }
         // trim each posted value
         $db_config['db_type'] = trim(@$_POST['db_type']);
         $db_config['db_name'] = trim($_POST['db_name']);
         $db_config['db_user'] = trim($_POST['db_user']);
         $db_config['db_password'] = trim($_POST['db_passwd']);
         $db_config['db_host'] = trim($_POST['db_host']);
         $db_config['db_socket'] = trim($_POST['db_socket']);
         $db_config['db_port'] = trim($_POST['db_port']);
         $db_config['table_prefix'] = trim($_POST['db_prefix']);
         $db_config['timezone'] = trim($_POST['timezone']);
         $email = trim($_POST['site_email']);
         // get GMT offset in hours
         $db_config['GMT_offset'] = timezone_offset_get(new DateTimeZone($_POST['timezone']), new DateTime('now')) / 3600;
     }
     $db_config['db_type'] = 'mysql';
     //default for now
     $password = $_POST['password'];
     $confirm_password = $_POST['confirm_password'];
     $full_name = $_POST['full_name'];
     $display_errors = false;
     // check email
     if (!Utils::validateEmail($email)) {
         $this->addErrorMessage("Please enter a valid email address.");
         $this->setViewTemplate('install.step2.tpl');
         $display_errors = true;
     } else {
         if ($password != $confirm_password || $password == '') {
             //check password
             if ($password != $confirm_password) {
                 $this->addErrorMessage("Your passwords did not match.");
             } else {
                 $this->addErrorMessage("Please choose a password.");
             }
             $this->setViewTemplate('install.step2.tpl');
             $display_errors = true;
         } elseif (($error = $this->installer->checkDb($db_config)) !== true) {
             //check db
             if (($p = strpos($error->getMessage(), "Unknown MySQL server host")) !== false || ($p = strpos($error->getMessage(), "Can't connect to MySQL server")) !== false || ($p = strpos($error->getMessage(), "Can't connect to local MySQL server through socket")) !== false || ($p = strpos($error->getMessage(), "Access denied for user")) !== false) {
                 $db_error = substr($error->getMessage(), $p);
             } else {
                 $db_error = $error->getMessage();
             }
             $this->addErrorMessage("ThinkUp couldn't connect to your database. The error message is:<br /> " . " <strong>{$db_error}</strong><br />Please correct your database information and try again.");
             $this->setViewTemplate('install.step2.tpl');
             $display_errors = true;
         }
     }
     if ($display_errors) {
         $this->addToView('db_name', $db_config['db_name']);
         $this->addToView('db_user', $db_config['db_user']);
         $this->addToView('db_passwd', $db_config['db_password']);
         $this->addToView('db_host', $db_config['db_host']);
         $this->addToView('db_prefix', $db_config['table_prefix']);
         $this->addToView('db_socket', $db_config['db_socket']);
         $this->addToView('db_port', $db_config['db_port']);
         $this->addToView('db_type', $db_config['db_type']);
         $this->addToView('current_tz', $_POST['timezone']);
         $this->addToView('tz_list', $this->getTimeZoneList());
         $this->addToView('site_email', $email);
         $this->addToView('full_name', $full_name);
         return;
     }
     $admin_user = array('email' => $email, 'password' => $password, 'confirm_password' => $confirm_password);
     // trying to create config file
     if (!$config_file_exists && !$this->installer->createConfigFile($db_config, $admin_user)) {
         $config_file_contents_arr = $this->installer->generateConfigFile($db_config, $admin_user);
         $config_file_contents_str = '';
         foreach ($config_file_contents_arr as $line) {
             $config_file_contents_str .= htmlentities($line);
         }
         $whoami = exec('whoami');
         if (!empty($whoami)) {
             $this->addErrorMessage("ThinkUp couldn't write the <code>config.inc.php</code> file.<br /><br />" . "Use root (or sudo) to create the file manually, and allow PHP to write to it, by executing the " . "following commands:<br /><code>touch " . escapeshellcmd(THINKUP_WEBAPP_PATH . "config.inc.php") . "</code><br /><code>chown {$whoami} " . escapeshellcmd(THINKUP_WEBAPP_PATH . "config.inc.php") . "</code><br /><br />If you don't have root access, create the <code>" . THINKUP_WEBAPP_PATH . "config.inc.php</code> file manually, and paste the following text into it." . "<br /><br />Click the <strong>Next Step</strong> button below once you did either.");
         } else {
             $this->addErrorMessage("ThinkUp couldn't write the <code>config.inc.php</code> file.<br /><br />" . "You will need to create the <code>" . THINKUP_WEBAPP_PATH . "config.inc.php</code> file manually, and paste the following text into it." . "<br /><br />Click the <strong>Next Step</strong> button once this is done.");
         }
         $this->addToView('config_file_contents', $config_file_contents_str);
         $this->addToView('_POST', $_POST);
         $this->setViewTemplate('install.config.tpl');
         return;
     }
     unset($admin_user['confirm_password']);
     // check tables
     $this->installer->checkTable($db_config);
     // if empty, we're ready to populate the database with ThinkUp tables
     $this->installer->populateTables($db_config);
     $owner_dao = DAOFactory::getDAO('OwnerDAO', $db_config);
     if (!$owner_dao->doesAdminExist() && !$owner_dao->doesOwnerExist($email)) {
         // create admin if not exists
         $session = new Session();
         $activation_code = rand(1000, 9999);
         $crypt_pass = $session->pwdcrypt($password);
         //$owner_dao->insertActivatedAdmin($email, $crypt_pass, $full_name);
         $owner_dao->createAdmin($email, $crypt_pass, $activation_code, $full_name);
         // view for email
         $cfg_array = array('site_root_path' => THINKUP_BASE_URL, 'source_root_path' => THINKUP_ROOT_PATH, 'debug' => false, 'app_title' => "ThinkUp", 'cache_pages' => false);
         $email_view = new SmartyThinkUp($cfg_array);
         $email_view->caching = false;
         $email_view->assign('server', $_SERVER['HTTP_HOST']);
         $email_view->assign('email', urlencode($email));
         $email_view->assign('activ_code', $activation_code);
         $message = $email_view->fetch('_email.registration.tpl');
         Mailer::mail($email, "Activate Your New ThinkUp  Account", $message);
     } else {
         $email = 'Use your old email admin';
         $password = '******';
     }
     unset($THINKUP_CFG);
     $this->addToView('errors', $this->installer->getErrorMessages());
     $this->addToView('username', $email);
     $this->addToView('password', $password);
     $this->addToView('login_url', THINKUP_BASE_URL . 'session/login.php');
 }
Beispiel #27
0
 /**
  * Send user email alert about invalid OAuth tokens, at most one message per week.
  * In test mode, this will only write the message body to a file in the application data directory.
  * @param str $email
  * @param str $username
  * @return bool Whether or not email was sent
  */
 private function sendInvalidOAuthEmailAlert($email, $username)
 {
     //Determine whether or not an email about invalid tokens was sent in the past 7 days
     $should_send_email = true;
     $option_dao = DAOFactory::getDAO('OptionDAO');
     $plugin_dao = DAOFactory::getDAO('PluginDAO');
     $plugin_id = $plugin_dao->getPluginId('facebook');
     $last_email_timestamp = $option_dao->getOptionByName(OptionDAO::PLUGIN_OPTIONS . '-' . $plugin_id, 'invalid_oauth_email_sent_timestamp');
     if (isset($last_email_timestamp)) {
         //option exists, a message was sent
         //a message was sent in the past week
         if ($last_email_timestamp->option_value > strtotime('-1 week')) {
             $should_send_email = false;
         } else {
             $option_dao->updateOption($last_email_timestamp->option_id, time());
         }
     } else {
         $option_dao->insertOption(OptionDAO::PLUGIN_OPTIONS . '-' . $plugin_id, 'invalid_oauth_email_sent_timestamp', time());
     }
     if ($should_send_email) {
         $mailer_view_mgr = new ViewManager();
         $mailer_view_mgr->caching = false;
         $mailer_view_mgr->assign('thinkup_site_url', Utils::getApplicationURL());
         $mailer_view_mgr->assign('email', $email);
         $mailer_view_mgr->assign('faceboook_user_name', $username);
         $message = $mailer_view_mgr->fetch(Utils::getPluginViewDirectory('facebook') . '_email.invalidtoken.tpl');
         Mailer::mail($email, "Please re-authorize ThinkUp to access " . $username . " on Facebook", $message);
         return true;
     } else {
         return false;
     }
 }
Beispiel #28
0
 function testSendingMail()
 {
     $result = Mailer::mail("*****@*****.**", "Login Activation", "Thank you for registering an account.");
     $this->assertTrue($result);
 }
 public function control()
 {
     if ($this->isLoggedIn()) {
         $controller = new DashboardController(true);
         return $controller->go();
     } else {
         // register form validation
         $this->addHeaderCSS('assets/css/validate_password.css');
         $this->addHeaderJavaScript('assets/js/jquery.validate.min.js');
         $this->addHeaderJavaScript('assets/js/jquery.validate.password.js');
         $this->addHeaderJavaScript('assets/js/validate_password.js');
         $config = Config::getInstance();
         $is_registration_open = $config->getValue('is_registration_open');
         $this->disableCaching();
         $invite_dao = DAOFactory::getDAO('InviteDAO');
         if (isset($_GET['code'])) {
             $invite_code = $_GET['code'];
         } else {
             $invite_code = null;
         }
         $this->addToView('invite_code', $invite_code);
         $is_invite_code_valid = $invite_dao->isInviteValid($invite_code);
         if ($invite_code != null && $is_invite_code_valid) {
             $this->addSuccessMessage("Welcome, VIP! You've been invited to register on " . $config->getValue('app_title_prefix') . "ThinkUp.");
         }
         $has_been_registered = false;
         if (!$is_registration_open && !$is_invite_code_valid) {
             $this->addToView('closed', true);
             $disable_xss = true;
             $this->addErrorMessage('<p>Sorry, registration is closed on this installation of ' . $config->getValue('app_title_prefix') . "ThinkUp.</p>" . '<p><a href="http://thinkupapp.com">Install ThinkUp on your own server.</a></p>', null, $disable_xss);
         } else {
             $owner_dao = DAOFactory::getDAO('OwnerDAO');
             $this->addToView('closed', false);
             $captcha = new Captcha();
             if (isset($_POST['Submit']) && $_POST['Submit'] == 'Register') {
                 foreach ($this->REQUIRED_PARAMS as $param) {
                     if (!isset($_POST[$param]) || $_POST[$param] == '') {
                         $this->addErrorMessage('Please fill out all required fields.');
                         $this->is_missing_param = true;
                     }
                 }
                 if (!$this->is_missing_param) {
                     $valid_input = true;
                     if (!Utils::validateEmail($_POST['email'])) {
                         $this->addErrorMessage("Incorrect email. Please enter valid email address.", 'email');
                         $valid_input = false;
                     }
                     if (strcmp($_POST['pass1'], $_POST['pass2']) || empty($_POST['pass1'])) {
                         $this->addErrorMessage("Passwords do not match.", 'password');
                         $valid_input = false;
                     } else {
                         if (!preg_match("/(?=.{8,})(?=.*[a-zA-Z])(?=.*[0-9])/", $_POST['pass1'])) {
                             $this->addErrorMessage("Password must be at least 8 characters and contain both numbers " . "and letters.", 'password');
                             $valid_input = false;
                         }
                     }
                     if (!$captcha->doesTextMatchImage()) {
                         $this->addErrorMessage("Entered text didn't match the image. Please try again.", 'captcha');
                         $valid_input = false;
                     }
                     if ($valid_input) {
                         if ($owner_dao->doesOwnerExist($_POST['email'])) {
                             $this->addErrorMessage("User account already exists.", 'email');
                         } else {
                             // Insert the details into the database
                             $activation_code = $owner_dao->create($_POST['email'], $_POST['pass2'], $_POST['full_name']);
                             if ($activation_code != false) {
                                 $es = new ViewManager();
                                 $es->caching = false;
                                 $es->assign('application_url', Utils::getApplicationURL(false));
                                 $es->assign('email', urlencode($_POST['email']));
                                 $es->assign('activ_code', $activation_code);
                                 $message = $es->fetch('_email.registration.tpl');
                                 Mailer::mail($_POST['email'], "Activate Your Account on " . $config->getValue('app_title_prefix') . "ThinkUp", $message);
                                 SessionCache::unsetKey('ckey');
                                 $this->addSuccessMessage("Success! Check your email for an activation link.");
                                 //delete invite code
                                 if ($is_invite_code_valid) {
                                     $invite_dao->deleteInviteCode($invite_code);
                                 }
                                 $has_been_registered = true;
                             } else {
                                 $this->addErrorMessage("Unable to register a new user. Please try again.");
                             }
                         }
                     }
                 }
                 if (isset($_POST["full_name"])) {
                     $this->addToView('name', $_POST["full_name"]);
                 }
                 if (isset($_POST["email"])) {
                     $this->addToView('mail', $_POST["email"]);
                 }
                 $this->addToView('has_been_registered', $has_been_registered);
             }
             $challenge = $captcha->generate();
             $this->addToView('captcha', $challenge);
         }
         $this->view_mgr->addHelp('register', 'userguide/accounts/index');
         return $this->generateView();
     }
 }
Beispiel #30
0
 public function actionTestmail()
 {
     if (Yii::app()->user->isGuest) {
         throw new CHttpException(401, 'You are not authorized to access this page.');
     }
     Mailer::mail(array('*****@*****.**' => 'Loris Tissino'), 'test msg', 'body sample');
     $this->redirect(Yii::app()->homeUrl);
 }