public function control()
 {
     $session = new Session();
     $dao = DAOFactory::getDAO('OwnerDAO');
     $this->setViewTemplate('session.resetpassword.tpl');
     $this->disableCaching();
     if (!isset($_GET['token']) || !preg_match('/^[\\da-f]{32}$/', $_GET['token']) || !($user = $dao->getByPasswordToken($_GET['token']))) {
         // token is nonexistant or bad
         $this->addErrorMessage('You have reached this page in error.');
         return $this->generateView();
     }
     if (!$user->validateRecoveryToken($_GET['token'])) {
         $this->addErrorMessage('Your token is expired.');
         return $this->generateView();
     }
     if (isset($_POST['password'])) {
         if ($_POST['password'] == $_POST['password_confirm']) {
             if ($dao->updatePassword($user->email, $session->pwdcrypt($_POST['password'])) < 1) {
                 echo "not updated";
             }
             $login_controller = new LoginController(true);
             $login_controller->addSuccessMessage('You have changed your password.');
             return $login_controller->go();
         } else {
             $this->addErrorMessage("Passwords didn't match.");
         }
     } else {
         if (isset($_POST['Submit'])) {
             $this->addErrorMessage('Please enter a new password.');
         }
     }
     return $this->generateView();
 }
 protected function buildData()
 {
     $session = new Session();
     $cryptpass = $session->pwdcrypt("oldpassword");
     $builder = FixtureBuilder::build('owners', array('id' => 1, 'full_name' => 'ThinkUp J. User', 'email' => '*****@*****.**', 'pwd' => $cryptpass, 'activation_code' => 8888, 'is_activated' => 1));
     return $builder;
 }
    protected function buildData() {
        $builders = array();

        //Add owner
        $session = new Session();
        $cryptpass = $session->pwdcrypt("oldpassword");
        $builders[] = FixtureBuilder::build('owners', array('id'=>1, 'full_name'=>'ThinkUp J. User',
        'email'=>'*****@*****.**', 'is_activated'=>1, 'pwd'=>$cryptpass));

        $builders[] = FixtureBuilder::build('owners', array('id'=>2, 'full_name'=>'ThinkUp J. Admin',
        'email'=>'*****@*****.**', 'is_activated'=>1, 'is_admin'=>1));

        //Add instance_owner
        $builders[] = FixtureBuilder::build('owner_instances', array('owner_id'=>1, 'instance_id'=>1));
        $builders[] = FixtureBuilder::build('owner_instances', array('owner_id'=>2, 'instance_id'=>1));

        //Insert test data into test table
        $builders[] = FixtureBuilder::build('users', array('user_id'=>13, 'user_name'=>'ev',
        'full_name'=>'Ev Williams'));

        //Make public
        //Insert test data into test table
        $builders[] = FixtureBuilder::build('instances', array('id'=>1, 'network_user_id'=>13,
        'network_username'=>'ev', 'is_public'=>1, 'network'=>'twitter'));

        return $builders;
    }
 protected function buildData()
 {
     $session = new Session();
     $cryptpass = $session->pwdcrypt("oldpassword");
     $builder = FixtureBuilder::build('owners', array('id' => 1, 'full_name' => 'ThinkUp J. User', 'email' => '*****@*****.**', 'pwd' => $cryptpass, 'activation_code' => '8888', 'is_activated' => 1));
     $dao = DAOFactory::getDAO('OwnerDAO');
     $this->owner = $dao->getByEmail('*****@*****.**');
     $this->token = $this->owner->setPasswordRecoveryToken();
     return $builder;
 }
 public function setUp()
 {
     parent::setUp();
     $webapp = Webapp::getInstance();
     $webapp->registerPlugin('twitter', 'TwitterPlugin');
     $session = new Session();
     $cryptpass = $session->pwdcrypt("secretpassword");
     $owner = array('id' => 1, 'email' => '*****@*****.**', 'pwd' => $cryptpass, 'is_activated' => 1);
     $this->builder1 = FixtureBuilder::build('owners', $owner);
     $instance = array('id' => 1);
     $this->builder2 = FixtureBuilder::build('instances', $instance);
     $owner_instance = array('owner_id' => 1, 'instance_id' => 1);
     $this->builder3 = FixtureBuilder::build('owner_instances', $owner_instance);
 }
 public function testAlreadyLoggedIn()
 {
     $session = new Session();
     $cryptpass = $session->pwdcrypt("secretpassword");
     $owner = array('id' => 1, 'email' => '*****@*****.**', 'pwd' => $cryptpass, 'is_activated' => 1);
     $builder1 = FixtureBuilder::build('owners', $owner);
     $instance = array('id' => 1, 'network_username' => 'thinkupapp');
     $builder2 = FixtureBuilder::build('instances', $instance);
     $owner_instance = array('owner_id' => 1, 'instance_id' => 1);
     $builder3 = FixtureBuilder::build('owner_instances', $owner_instance);
     $this->simulateLogin('*****@*****.**');
     $controller = new RegisterController(true);
     $results = $controller->go();
     $this->assertPattern("/thinkupapp's Dashboard | ThinkUp/", $results);
 }
Example #7
0
 public function setUp()
 {
     parent::setUp();
     //Add owner
     $session = new Session();
     $cryptpass = $session->pwdcrypt("secretpassword");
     $q = "INSERT INTO tu_owners (id, email, pwd, is_activated) VALUES (1, '*****@*****.**', '" . $cryptpass . "', 1)";
     $this->db->exec($q);
     //Add instance
     $q = "INSERT INTO tu_instances (id, network_user_id, network_username, is_public) VALUES (1, 1234,\n        'thinkupapp', 1)";
     $this->db->exec($q);
     //Add instance_owner
     $q = "INSERT INTO tu_owner_instances (owner_id, instance_id) VALUES (1, 1)";
     $this->db->exec($q);
 }
    public function setUp()
    {
        parent::setUp();
        $session = new Session();
        $cryptpass = $session->pwdcrypt("oldpassword");
        $q = <<<SQL
INSERT INTO #prefix#owners SET
    id = 1,
    full_name = 'ThinkUp J. User',
    email = '*****@*****.**',
    pwd = '{$cryptpass}',
    activation_code='8888',
    is_activated =1
SQL;
        $this->testdb_helper->runSQL($q);
    }
 public function setUp()
 {
     parent::setUp();
     new ExportMySQLDAO();
     $this->config = Config::getInstance();
     $this->pdo = ExportMySQLDAO::$PDO;
     $this->export_test = THINKUP_WEBAPP_PATH . BackupDAO::CACHE_DIR . '/thinkup_user_export_test.zip';
     $session = new Session();
     $cryptpass = $session->pwdcrypt("secretpassword");
     $owner = array('id' => 1, 'email' => '*****@*****.**', 'pwd' => $cryptpass, 'is_activated' => 1, 'is_admin' => 1);
     $this->builders[] = FixtureBuilder::build('owners', $owner);
     $instance = array('id' => 1, 'network_username' => 'test_user', 'network' => 'twitter');
     $this->builders[] = FixtureBuilder::build('instances', $instance);
     $owner_instance = array('owner_id' => 1, 'instance_id' => 1);
     $this->builders[] = FixtureBuilder::build('owner_instances', $owner_instance);
     $this->builders[] = FixtureBuilder::build('users', array('user_id' => 10, 'network' => 'twitter', 'user_name' => 'test_user'));
 }
    public function setUp()
    {
        parent::setUp();
        $config = Config::getInstance();
        $config->setValue('debug', true);
        $session = new Session();
        $cryptpass = $session->pwdcrypt("oldpassword");
        $q = <<<SQL
INSERT INTO #prefix#owners SET
    id = 1,
    full_name = 'ThinkUp J. User',
    email = '*****@*****.**',
    pwd = '{$cryptpass}',
    activation_code='8888',
    is_activated =1
SQL;
        $this->db->exec($q);
        $dao = DAOFactory::getDAO('OwnerDAO');
        $this->owner = $dao->getByEmail('*****@*****.**');
        $this->token = $this->owner->setPasswordRecoveryToken();
    }
 public function setUp()
 {
     parent::setUp();
     $webapp = Webapp::getInstance();
     $webapp->registerPlugin('twitter', 'TwitterPlugin');
     //Add owner
     $session = new Session();
     $cryptpass = $session->pwdcrypt("oldpassword");
     $q = "INSERT INTO tu_owners SET id=1, full_name='ThinkUp J. User', email='*****@*****.**', is_activated=1,\n        pwd='" . $cryptpass . "', activation_code='8888'";
     $this->db->exec($q);
     $q = "INSERT INTO tu_owners SET id=2, full_name='ThinkUp J. Admin', email='*****@*****.**',\n        is_activated=1, is_admin=1, pwd='XXX', activation_code='8888'";
     $this->db->exec($q);
     //Add instance_owner
     $q = "INSERT INTO tu_owner_instances (owner_id, instance_id, oauth_access_token, oauth_access_token_secret)\n        VALUES (1, 1, 'xxx', 'yyy')";
     $this->db->exec($q);
     $q = "INSERT INTO tu_owner_instances (owner_id, instance_id, oauth_access_token, oauth_access_token_secret)\n        VALUES (2, 1, 'xxx', 'yyy')";
     $this->db->exec($q);
     //Insert test data into test table
     $q = "INSERT INTO tu_users (user_id, user_name, full_name, avatar, last_updated) VALUES (13, 'ev',\n        'Ev Williams', 'avatar.jpg', '1/1/2005');";
     $this->db->exec($q);
     //Make public
     $q = "INSERT INTO tu_instances (id, network_user_id, network_username, is_public, network)\n        VALUES (1, 13, 'ev', 1, 'twitter');";
     $this->db->exec($q);
 }
Example #12
0
     $errormsg = "Incorrect email. Please enter valid email address.";
 }
 if (strcmp($_POST['pass1'], $_POST['pass2']) || empty($_POST['pass1'])) {
     if (!isset($errormsg)) {
         $errormsg = "Password does not match or empty.";
     }
 } elseif (!$captcha->check()) {
     //Captcha not valid, captcha handles message...
 } else {
     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"]);
 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();
     }
 }
 /**
  * Insert some test data to navigate the app
  */
 protected function buildData()
 {
     $builders = array();
     //Add owner
     $session = new Session();
     $cryptpass = $session->pwdcrypt("secretpassword");
     $builders[] = FixtureBuilder::build('owners', array('id' => 1, 'email' => '*****@*****.**', 'pwd' => $cryptpass, 'is_activated' => 1, 'is_admin' => 1));
     $builders[] = FixtureBuilder::build('owners', array('id' => 2, 'email' => '*****@*****.**', 'pwd' => $cryptpass, 'is_activated' => 1, 'is_admin' => 0));
     //Add instances
     $builders[] = FixtureBuilder::build('instances', array('id' => 1, 'network_user_id' => 17, 'network_username' => 'thinkupapp', 'is_public' => 1, 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('instances', array('id' => 2, 'network_user_id' => 13, 'network_username' => 'ev', 'is_public' => 1, 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('instances', array('id' => 3, 'network_user_id' => 18, 'network_username' => 'shutterbug', 'is_public' => 1, 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('instances', array('id' => 4, 'network_user_id' => 19, 'network_username' => 'linkbaiter', 'is_public' => 1, 'network' => 'twitter'));
     //Add instance_owner
     $builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => 1, 'instance_id' => 1));
     //Insert test data into test table
     $builders[] = FixtureBuilder::build('users', array('user_id' => 12, 'user_name' => 'jack', 'full_name' => 'Jack Dorsey', 'avatar' => 'avatar.jpg', 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('users', array('user_id' => 13, 'user_name' => 'ev', 'full_name' => 'Ev Williams', 'avatar' => 'avatar.jpg', 'last_updated' => '1/1/2005', 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('users', array('user_id' => 16, 'user_name' => 'private', 'full_name' => 'Private Poster', 'avatar' => 'avatar.jpg', 'is_protected' => 1, 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('users', array('user_id' => 17, 'user_name' => 'thinkupapp', 'full_name' => 'ThinkUpers', 'avatar' => 'avatar.jpg', 'is_protected' => 0, 'follower_count' => 10, 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('users', array('user_id' => 18, 'user_name' => 'shutterbug', 'full_name' => 'Shutter Bug', 'avatar' => 'avatar.jpg', 'is_protected' => 0, 'follower_count' => 10, 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('users', array('user_id' => 19, 'user_name' => 'linkbaiter', 'full_name' => 'Link Baiter', 'avatar' => 'avatar.jpg', 'is_protected' => 0, 'follower_count' => 10, 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('user_errors', array('user_id' => 15, 'error_code' => 404, 'error_text' => 'User not found', 'error_issued_to_user_id' => 13));
     $builders[] = FixtureBuilder::build('follows', array('user_id' => 13, 'follower_id' => 12));
     $builders[] = FixtureBuilder::build('follows', array('user_id' => 13, 'follower_id' => 14));
     $builders[] = FixtureBuilder::build('follows', array('user_id' => 13, 'follower_id' => 15));
     $builders[] = FixtureBuilder::build('follows', array('user_id' => 13, 'follower_id' => 16));
     $builders[] = FixtureBuilder::build('follows', array('user_id' => 16, 'follower_id' => 12));
     $builders[] = FixtureBuilder::build('follows', array('user_id' => 19, 'follower_id' => 13));
     $builders[] = FixtureBuilder::build('follows', array('user_id' => 18, 'follower_id' => 13));
     $counter = 0;
     while ($counter < 40) {
         $reply_or_forward_count = $counter + 200;
         $pseudo_minute = str_pad($counter, 2, "0", STR_PAD_LEFT);
         $builders[] = FixtureBuilder::build('posts', array('post_id' => $counter, 'author_user_id' => 13, 'author_username' => 'ev', 'author_fullname' => 'Ev Williams', 'author_avatar' => 'avatar.jpg', 'source' => 'web', 'pub_date' => '2006-01-01 00:$pseudo_minute:00', 'reply_count_cache' => $reply_or_forward_count, 'retweet_count_cache' => $reply_or_forward_count, 'post_text' => 'This is post ' . $counter, 'network' => 'twitter'));
         $counter++;
     }
     $counter = 0;
     while ($counter < 40) {
         $post_id = $counter + 40;
         $pseudo_minute = str_pad($counter, 2, "0", STR_PAD_LEFT);
         $builders[] = FixtureBuilder::build('posts', array('post_id' => $post_id, 'author_user_id' => 18, 'author_username' => 'shutterbug', 'author_fullname' => 'Shutter Bug', 'author_avatar' => 'avatar.jpg', 'source' => 'web', 'pub_date' => '2006-01-02 00:$pseudo_minute:00', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'post_text' => 'This is image post ' . $counter, 'network' => 'twitter'));
         $builders[] = FixtureBuilder::build('links', array('url' => 'http://example.com/' . $counter, 'expanded_url' => 'http://example.com/' . $counter . 'jpg', 'title' => '', 'clicks' => 0, 'post_id' => $post_id, 'is_image' => 1));
         $counter++;
     }
     $counter = 0;
     while ($counter < 40) {
         $post_id = $counter + 80;
         $pseudo_minute = str_pad($counter, 2, "0", STR_PAD_LEFT);
         $builders[] = FixtureBuilder::build('posts', array('post_id' => $post_id, 'author_user_id' => 19, 'author_username' => 'linkbaiter', 'author_fullname' => 'Link Baiter', 'author_avatar' => 'avatar.jpg', 'post_text' => 'This is link post ' . $counter, 'source' => 'web', 'pub_date' => '2006-03-01 00:$pseudo_minute:00', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'network' => 'twitter'));
         $builders[] = FixtureBuilder::build('links', array('url' => 'http://example.com/' . $counter, 'expanded_url' => 'http://example.com/' . $counter . 'html', 'title' => 'Link ' . $counter, 'clicks' => 0, 'post_id' => $post_id, 'is_image' => 0));
         $counter++;
     }
     $counter = 0;
     while ($counter < 10) {
         $post_id = $counter + 120;
         $pseudo_minute = str_pad($counter, 2, "0", STR_PAD_LEFT);
         $builders[] = FixtureBuilder::build('posts', array('post_id' => $post_id, 'author_user_id' => 1234, 'author_username' => 'thinkupapp', 'author_fullname' => 'thinkupapp', 'author_avatar' => 'avatar.jpg', 'post_text' => 'This is test post ' . $counter, 'source' => 'web', 'pub_date' => '2006-03-01 00:$pseudo_minute:00', 'reply_count_cache' => 0, 'retweet_count_cache' => 0, 'network' => 'twitter'));
         $counter++;
     }
     return $builders;
 }
Example #15
0
 function setUp()
 {
     parent::setUp();
     //Add owner
     $session = new Session();
     $cryptpass = $session->pwdcrypt("secretpassword");
     $q = "INSERT INTO tt_owners (id, user_email, user_pwd, user_activated) VALUES (1, '*****@*****.**', '" . $cryptpass . "', 1)";
     $this->db->exec($q);
     //Add instance
     $q = "INSERT INTO tt_instances (id, network_user_id, network_username, is_public) VALUES (1, 1234, 'thinktankapp', 1)";
     $this->db->exec($q);
     //Add instance_owner
     $q = "INSERT INTO tt_owner_instances (owner_id, instance_id) VALUES (1, 1)";
     $this->db->exec($q);
     //Insert test data into test table
     $q = "INSERT INTO tt_users (user_id, user_name, full_name, avatar) VALUES (12, 'jack', 'Jack Dorsey', 'avatar.jpg');";
     $this->db->exec($q);
     $q = "INSERT INTO tt_users (user_id, user_name, full_name, avatar, last_updated) VALUES (13, 'ev', 'Ev Williams', 'avatar.jpg', '1/1/2005');";
     $this->db->exec($q);
     $q = "INSERT INTO tt_users (user_id, user_name, full_name, avatar, is_protected) VALUES (16, 'private', 'Private Poster', 'avatar.jpg', 1);";
     $this->db->exec($q);
     $q = "INSERT INTO tt_users (user_id, user_name, full_name, avatar, is_protected, follower_count) VALUES (17, 'thinktankapp', 'ThinkTankers', 'avatar.jpg', 0, 10);";
     $this->db->exec($q);
     $q = "INSERT INTO tt_users (user_id, user_name, full_name, avatar, is_protected, follower_count) VALUES (18, 'shutterbug', 'Shutter Bug', 'avatar.jpg', 0, 10);";
     $this->db->exec($q);
     $q = "INSERT INTO tt_users (user_id, user_name, full_name, avatar, is_protected, follower_count) VALUES (19, 'linkbaiter', 'Link Baiter', 'avatar.jpg', 0, 10);";
     $this->db->exec($q);
     $q = "INSERT INTO tt_user_errors (user_id, error_code, error_text, error_issued_to_user_id) VALUES (15, 404, 'User not found', 13);";
     $this->db->exec($q);
     $q = "INSERT INTO tt_follows (user_id, follower_id, last_seen) VALUES (13, 12, '1/1/2006');";
     $this->db->exec($q);
     $q = "INSERT INTO tt_follows (user_id, follower_id, last_seen) VALUES (13, 14, '1/1/2006');";
     $this->db->exec($q);
     $q = "INSERT INTO tt_follows (user_id, follower_id, last_seen) VALUES (13, 15, '1/1/2006');";
     $this->db->exec($q);
     $q = "INSERT INTO tt_follows (user_id, follower_id, last_seen) VALUES (13, 16, '1/1/2006');";
     $this->db->exec($q);
     $q = "INSERT INTO tt_follows (user_id, follower_id, last_seen) VALUES (16, 12, '1/1/2006');";
     $this->db->exec($q);
     $q = "INSERT INTO tt_instances (network_user_id, network_username, is_public) VALUES (13, 'ev', 1);";
     $this->db->exec($q);
     $q = "INSERT INTO tt_instances (network_user_id, network_username, is_public) VALUES (18, 'shutterbug', 1);";
     $this->db->exec($q);
     $q = "INSERT INTO tt_instances (network_user_id, network_username, is_public) VALUES (19, 'linkbaiter', 1);";
     $this->db->exec($q);
     $counter = 0;
     while ($counter < 40) {
         $reply_or_forward_count = $counter + 200;
         $pseudo_minute = str_pad($counter, 2, "0", STR_PAD_LEFT);
         $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache) VALUES ({$counter}, 13, 'ev', 'Ev Williams', 'avatar.jpg', 'This is post {$counter}', 'web', '2006-01-01 00:{$pseudo_minute}:00', {$reply_or_forward_count}, {$reply_or_forward_count});";
         $this->db->exec($q);
         $counter++;
     }
     $counter = 0;
     while ($counter < 40) {
         $post_id = $counter + 40;
         $pseudo_minute = str_pad($counter, 2, "0", STR_PAD_LEFT);
         $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache) VALUES ({$post_id}, 18, 'shutterbug', 'Shutter Bug', 'avatar.jpg', 'This is image post {$counter}', 'web', '2006-01-02 00:{$pseudo_minute}:00', 0, 0);";
         $this->db->exec($q);
         $q = "INSERT INTO tt_links (url, expanded_url, title, clicks, post_id, is_image) VALUES ('http://example.com/" . $counter . "', 'http://example.com/" . $counter . ".jpg', '', 0, {$post_id}, 1);";
         $this->db->exec($q);
         $counter++;
     }
     $counter = 0;
     while ($counter < 40) {
         $post_id = $counter + 80;
         $pseudo_minute = str_pad($counter, 2, "0", STR_PAD_LEFT);
         $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache) VALUES ({$post_id}, 19, 'linkbaiter', 'Link Baiter', 'avatar.jpg', 'This is link post {$counter}', 'web', '2006-03-01 00:{$pseudo_minute}:00', 0, 0);";
         $this->db->exec($q);
         $q = "INSERT INTO tt_links (url, expanded_url, title, clicks, post_id, is_image) VALUES ('http://example.com/" . $counter . "', 'http://example.com/" . $counter . ".html', 'Link {$counter}', 0, {$post_id}, 0);";
         $this->db->exec($q);
         $counter++;
     }
 }
 /**
  * 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');
 }
Example #17
0
    public function testFailedLoginLockout() {
        $session = new Session();
        $cryptpass = $session->pwdcrypt("blah");

        $owner = array('id'=>2, 'email'=>'*****@*****.**', 'pwd'=>$cryptpass, 'is_activated'=>1);
        $builder = FixtureBuilder::build('owners', $owner);

        //force login lockout by providing the wrong password more than 10 times
        $i = 1;
        while ($i <= 15) {
            $_POST['Submit'] = 'Log In';
            $_POST['email'] = '*****@*****.**';
            $_POST['pwd'] = 'blah1';
            $controller = new LoginController(true);
            $results = $controller->go();

            $v_mgr = $controller->getViewManager();
            $this->assertEqual($v_mgr->getTemplateDataItem('controller_title'), 'Log in');
            if ($i <= 11) {
                $this->assertPattern("/Incorrect password/", $v_mgr->getTemplateDataItem('errormsg'));
                $owner_dao = new OwnerMySQLDAO();
                $owner = $owner_dao->getByEmail('*****@*****.**');
                $this->assertEqual($owner->failed_logins, $i);
            } else {
                $this->assertEqual("Inactive account. Account deactivated due to too many failed logins. ".
                '<a href="forgot.php">Reset your password.</a>', $v_mgr->getTemplateDataItem('errormsg'));
                $owner_dao = new OwnerMySQLDAO();
                $owner = $owner_dao->getByEmail('*****@*****.**');
                $this->assertEqual($owner->account_status, "Account deactivated due to too many failed logins");
            }
            $i = $i + 1;
        }
    }
Example #18
0
// set up
chdir("..");
require_once 'init.php';
require_once 'model/class.Mailer.php';
$session = new Session();
if ($session->isLoggedIn()) {
    header("Location: ../index.php");
}
$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";
    }
}
 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 {
                             $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);
                             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);
                             }
                         }
                     }
                 }
                 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();
     }
 }