Esempio n. 1
0
 public function get()
 {
     $message_id = Request::get('message_id', 'int');
     if (empty($message_id)) {
         Output::error('Message Not Found');
     }
     JS::set('chart.' . $this->id . '.params.message_id', ['value' => $message_id]);
     parent::get();
 }
Esempio n. 2
0
 public function postReset()
 {
     if (!($email = Request::get('email', 'email'))) {
         Output::error('Invalid email');
     } elseif (!($user = UserModel::loadByEmail($email))) {
         Output::error('User does not exist.');
     }
     $user->sendResetLink();
 }
Esempio n. 3
0
 public static function getAccessToken()
 {
     self::loadAutoLoader();
     session_start();
     $request_token['oauth_token'] = $_SESSION['oauth_token'];
     $request_token['oauth_token_secret'] = $_SESSION['oauth_token_secret'];
     if (isset($_REQUEST['oauth_token']) && $request_token['oauth_token'] !== $_REQUEST['oauth_token']) {
         // Abort! Something is wrong.
         Output::error('invalid request');
     }
     // Convert to access token (this should be done on the client side)
     $appId = Configuration::get('twitter.key');
     $secret = Configuration::get('twitter.secret');
     $connection = new TwitterOAuth($appId, $secret, $request_token['oauth_token'], $request_token['oauth_token_secret']);
     return $connection->oauth("oauth/access_token", array("oauth_verifier" => $_REQUEST['oauth_verifier']));
 }
Esempio n. 4
0
 public function get()
 {
     $page = Request::getLocation();
     $template_page = Configuration::get('splash.pages.' . $page);
     // No template found.
     if (empty($template_page) || is_array($template_page) && empty($template_page['template'])) {
         Output::error('Page not found.');
     } else {
         $this->page = is_array($template_page) ? $template_page['template'] : $template_page;
     }
     // Add any CSS or JS files.
     if (is_array($template_page)) {
         if (!empty($template_page['css'])) {
             CSS::add($template_page['css']);
         }
         if (!empty($template_page['js'])) {
             JS::add($template_page['js']);
         }
     }
 }
Esempio n. 5
0
 protected function requestForbidden($status_code)
 {
     if (!empty($_POST) > 0) {
         // Temporary redirect to a page where there is no POST data.
         Navigation::redirect($_SERVER['REQUEST_URI'], 307);
     } else {
         // Output the access denied message.
         Output::error($this->results['errors'][0], $status_code);
     }
 }
Esempio n. 6
0
    /**
     * Determine which handler in the page to run. This will automatically
     * determine if there is a form based on the submitted action variable.
     * If no action variable, it will call get() or post() or any other
     * rest method.
     */
    public function execute() {
        $request_type = strtolower(Request::type());

        if (!$this->hasAccess()) {
            Output::accessDenied();
        }

        if (!$this->validateToken()) {
            Navigation::redirect('/message?err=invalid_token');
        }

        // If there is a requested action.
        if ($action = Request::get('action')) {
            $method = Request::convertFunctionName($request_type, $action);
            if (method_exists($this, $method)) {
                $this->{$method}();
                $this->output();
            }
            else {
                Output::error('There was an error processing your submission.');
            }
        } else {
            if (method_exists($this, $request_type)) {
                $this->$request_type();
                $this->output();
            } else {
                // TODO: show 302
                Output::error('Method not available');
            }
        }
    }
Esempio n. 7
0
 /**
  * Send a temporary password.
  *
  * @todo This is not secure. There should be a security question and email should just be a link.
  */
 public function postReset()
 {
     if (!($email = Request::get('email', 'email'))) {
         Output::error('Invalid email');
     } elseif (!($user = UserModel::loadByEmail($email))) {
         Output::error('User does not exist.');
     }
     if ($user->sendResetLink()) {
         Navigation::redirect('message', array('msg' => 'reset'));
     }
 }
Esempio n. 8
0
 /**
  * Process the data and import it based on alignment fields.
  */
 protected function importDataFile()
 {
     $cache = new FileCache();
     $cache->loadReference(Request::post('cache'));
     if (!$cache->isValid()) {
         Output::error('Invalid reference. Please try again.');
     }
     // Load the CSV, skip the first row if it's a header.
     $csv = new CSVIterator($cache->getFile());
     if (Request::post('header', 'int')) {
         $csv->next();
     }
     // Process the alignment so we know which fields to import.
     $alignment = Request::get('alignment', 'keyed_array', 'int');
     $fields = array();
     foreach ($alignment as $field => $column) {
         if ($column != -1) {
             $fields[$field] = $column;
         }
     }
     $database = Database::getInstance();
     $values = array();
     while ($csv->valid()) {
         $row = $csv->current();
         foreach ($fields as $field => $column) {
             $values[$field][] = $row[$column];
         }
         if (count($values[$field]) >= 100) {
             // Insert what we have so far and continue.
             $last_id = $database->insertSets($this->table, array_keys($fields), $values, true);
             if (method_exists($this, 'customImportPostProcess')) {
                 $ids = $last_id ? range($last_id - $database->affectedRows() + 1, $last_id) : [];
                 $this->customImportPostProcess($values, $ids);
             }
             $values = array();
         }
         $csv->next();
     }
     if (!empty($values)) {
         $last_id = $database->insertSets($this->table, array_keys($fields), $values, true);
         if (method_exists($this, 'customImportPostProcess')) {
             $ids = $last_id ? range($last_id - $database->affectedRows() + 1, $last_id) : [];
             $this->customImportPostProcess($values, $ids);
         }
     }
 }