public function control()
 {
     $this->redirectToSternIndiaEndpoint('forgot.php');
     $config = Config::getInstance();
     //$this->addToView('is_registration_open', $config->getValue('is_registration_open'));
     // if (isset($_POST['email']) && $_POST['Submit'] == 'Send Reset') {
     // /$_POST['email'] = '*****@*****.**';
     if (isset($_POST['email'])) {
         $this->disableCaching();
         $dao = DAOFactory::getDAO('UserDAO');
         $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('first_name', $user->first_name);
             $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');
             $subject = $config->getValue('app_title_prefix') . "Stern India Password Recovery";
             //Will put the things in queue to mail the things.
             Resque::enqueue('user_mail', 'Mailer', array($_POST['email'], $subject, $message));
             $this->addToView('link_sent', true);
         } 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();
 }
 /**
  * Get fully-rendered HTML markup for this insight.
  * @param  Insight $insight Test insight to render in HTML.
  * @return str Insight HTML with this insight
  */
 protected function getRenderedInsightInHTML(Insight $insight)
 {
     if ($insight->related_data !== null && is_string($insight->related_data)) {
         $insight->related_data = Serializer::unserializeString($insight->related_data);
     }
     $view = new ViewManager();
     $view->caching = false;
     $view->assign('insights', array($insight));
     $view->assign('expand', true);
     $view->assign('tpl_path', THINKUP_WEBAPP_PATH . 'plugins/insightsgenerator/view/');
     $view->assign('enable_bootstrap', true);
     $view->assign('thinkup_application_url', Utils::getApplicationURL());
     $view->assign('site_root_path', 'https://thinkup.thinkup.com/');
     $html_insight = $view->fetch(THINKUP_WEBAPP_PATH . '_lib/view/insights.tpl');
     return $html_insight;
 }
 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();
     }
 }
 /**
  * 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);
         }
     }
 }
Пример #6
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;
     }
 }
 /**
  * Generates plugin page options markup - Calls parent::generateView()
  *
  * @return str view markup
  */
 protected function generateView()
 {
     // if we have some p[lugin option elements defined
     // render them and add to the parent view...
     if (count($this->option_elements) > 0) {
         $this->setValues();
         $view_mgr = new ViewManager();
         $view_mgr->disableCaching();
         // assign data
         $view_mgr->assign('option_elements', $this->option_elements);
         $view_mgr->assign('option_elements_json', json_encode($this->option_elements));
         $view_mgr->assign('option_headers', $this->option_headers);
         $view_mgr->assign('option_not_required', $this->option_not_required);
         $view_mgr->assign('option_not_required_json', json_encode($this->option_not_required));
         $view_mgr->assign('option_required_message', $this->option_required_message);
         $view_mgr->assign('option_required_message_json', json_encode($this->option_required_message));
         $view_mgr->assign('option_select_multiple', $this->option_select_multiple);
         $view_mgr->assign('option_select_visible', $this->option_select_visible);
         $view_mgr->assign('plugin_id', $this->plugin_id);
         $view_mgr->assign('user_is_admin', $this->isAdmin());
         $options_markup = '';
         if ($this->profiler_enabled) {
             $view_start_time = microtime(true);
             $options_markup = $view_mgr->fetch(self::OPTIONS_TEMPLATE);
             $view_end_time = microtime(true);
             $total_time = $view_end_time - $view_start_time;
             $profiler = Profiler::getInstance();
             $profiler->add($total_time, "Rendered view (not cached)", false);
         } else {
             $options_markup = $view_mgr->fetch(self::OPTIONS_TEMPLATE);
         }
         $this->addToView('options_markup', $options_markup);
     }
     return parent::generateView();
 }
Пример #8
0
 /**
  * Generates web page markup
  *
  * @return str view markup
  */
 protected function generateView()
 {
     // add header javascript if defined
     if (count($this->header_scripts) > 0) {
         $this->addToView('header_scripts', $this->header_scripts);
     }
     // add header CSS if defined
     if (count($this->header_css) > 0) {
         $this->addToView('header_css', $this->header_css);
     }
     // add CSRF token if enabled and defined
     if ($this->view_csrf_token) {
         $csrf_token = Session::getCSRFToken();
         if (isset($csrf_token)) {
             $this->addToView('csrf_token', $csrf_token);
         }
     }
     $this->sendHeader();
     if (isset($this->view_template)) {
         if ($this->view_mgr->isViewCached()) {
             $cache_key = $this->getCacheKeyString();
             if ($this->profiler_enabled && !isset($this->json_data) && strpos($this->content_type, 'text/javascript') === false) {
                 $view_start_time = microtime(true);
                 $cache_source = $this->shouldRefreshCache() ? "DATABASE" : "FILE";
                 $results = $this->view_mgr->fetch($this->view_template, $cache_key);
                 $view_end_time = microtime(true);
                 $total_time = $view_end_time - $view_start_time;
                 $profiler = Profiler::getInstance();
                 $profiler->add($total_time, "Rendered view from " . $cache_source . ", cache key: <i>" . $this->getCacheKeyString(), false) . '</i>';
                 return $results;
             } else {
                 return $this->view_mgr->fetch($this->view_template, $cache_key);
             }
         } else {
             if ($this->profiler_enabled && !isset($this->json_data) && strpos($this->content_type, 'text/javascript') === false) {
                 $view_start_time = microtime(true);
                 $results = $this->view_mgr->fetch($this->view_template);
                 $view_end_time = microtime(true);
                 $total_time = $view_end_time - $view_start_time;
                 $profiler = Profiler::getInstance();
                 $profiler->add($total_time, "Rendered view (not cached)", false);
                 return $results;
             } else {
                 return $this->view_mgr->fetch($this->view_template);
             }
         }
     } else {
         if (isset($this->json_data)) {
             $this->setContentType('application/json');
             if ($this->view_mgr->isViewCached()) {
                 if ($this->view_mgr->is_cached('json.tpl', $this->getCacheKeyString())) {
                     return $this->view_mgr->fetch('json.tpl', $this->getCacheKeyString());
                 } else {
                     $this->prepareJSON();
                     return $this->view_mgr->fetch('json.tpl', $this->getCacheKeyString());
                 }
             } else {
                 $this->prepareJSON();
                 return $this->view_mgr->fetch('json.tpl');
             }
         } else {
             throw new Exception(get_class($this) . ': No view template specified');
         }
     }
 }
 /**
  * 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;
 }
Пример #10
0
 /**
  * @return str Object definition
  */
 public function makeModel()
 {
     //show full columns from table;
     $columns = array();
     try {
         $stmt = self::$pdo->query('SHOW FULL COLUMNS FROM ' . $this->table_name);
         while ($row = $stmt->fetch()) {
             $row['PHPType'] = $this->converMySQLTypeToPHP($row['Type']);
             $columns[$row['Field']] = $row;
         }
     } catch (Exception $e) {
         throw new Exception('Unable to show columns from "' . $this->table_name . '" - ' . $e->getMessage());
     }
     //instantiate Smarty, assign results to view
     $view_mgr = new ViewManager();
     $view_mgr->assign('fields', $columns);
     $view_mgr->assign('object_name', $this->object_name);
     //$view_mgr->assign('parent_name', $this->parent_name);
     $tpl_file = EFC_ROOT_PATH . 'makemodel/view/model_object.tpl';
     //output results
     $results = $view_mgr->fetch($tpl_file);
     return $results;
 }
 /**
  * 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');
 }
 /**
  * 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;
 }
Пример #13
0
 /**
  * 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 ViewManager();
     $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);
 }
Пример #14
0
 public function userRegisterMail($send = true, $activation_code = null)
 {
     $config = Config::getInstance();
     $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['activation_code']);
     $es->assign('password', $activation_code['password']);
     $message = $es->fetch('_email.registration.tpl');
     $subject = "Activate your account on " . $config->getValue('app_title_prefix') . " | Registeration !";
     $args = array('queue' => 'user_mail', 'control' => 'UserController', 'args' => array('userRegisterMail', $message, $subject));
     $this->enqueueResque($args);
     /*
     Mailer::mail($_POST['email'], "Activate Your Account on ".
     $config->getValue('app_title_prefix')." | Registeration !", $message);
     */
 }
Пример #15
0
 public function makeSendMailQueue($tpl, $args)
 {
     $config = Config::getInstance();
     $es = new ViewManager();
     $es->caching = false;
     foreach ($args['data'] as $key => $value) {
         $es->assign($key, $value);
     }
     $email = $args['data']['email'];
     $message = $es->fetch($tpl);
     $subject = "Activate your account on " . $config->getValue('app_title_prefix') . " | Registeration !";
     $args = array('queue' => 'user_mail', 'control' => 'ResqueController', 'args' => array('sendUserMail', $email, $message, $subject));
     $this->enqueueResque($args);
 }