Esempio n. 1
0
 public function postSave()
 {
     $user = ClientUser::getInstance();
     // Update the user name.
     $user->update(array('first' => Request::get('first'), 'last' => Request::get('last')));
     // Update the password.
     $password = Request::post('password');
     $new_password = Request::post('new_password');
     $new_password_confirm = Request::post('new_password_confirm');
     if (!empty($password) && $user->checkPass($password)) {
         if (false) {
             Messenger::error('Your password did not meet the required criteria.');
         } elseif ($new_password != $new_password_confirm) {
             Messenger::error('You did not enter the same password twice.');
         } else {
             $user->setPass($new_password);
         }
     } elseif (!empty($new_password) || !empty($new_password)) {
         Messenger::error('You did not enter your correct current password.');
     }
     // Update mailing list preferences.
     $new_lists = Request::get('subscribed', 'array', 'int', array());
     $new_lists = array_combine($new_lists, $new_lists);
     $all_lists = Subscription::getLists();
     $user_id = ClientUser::getInstance()->id;
     $user_lists = Subscription::getUserLists($user_id);
     $remove_lists = array();
     foreach ($user_lists as $list) {
         if (empty($new_lists[$list['message_list_id']]) && !empty($list['visible'])) {
             $remove_lists[$list['message_list_id']] = $list['message_list_id'];
         }
     }
     $add_lists = $new_lists;
     unset($add_lists[0]);
     if (!isset($new_lists[0])) {
         foreach ($all_lists as $list) {
             if (empty($list['visible'])) {
                 $remove_lists[$list['message_list_id']] = $list['message_list_id'];
             }
         }
     }
     $db = Database::getInstance();
     if (!empty($remove_lists)) {
         $db->delete('message_list_user', array('message_list_id' => array('IN', $remove_lists), 'user_id' => $user_id));
     }
     if (!empty($add_lists)) {
         $db->insertMultiple('message_list_user', array('message_list_id' => $add_lists, 'user_id' => $user_id), true);
     }
     if (count(Messenger::getErrors()) == 0) {
         Navigation::redirect(null, array('msg' => 'saved'));
     }
 }
Esempio n. 2
0
    /**
     * Prepare the output and tell the template to render.
     */
    public function output() {
        // Send globals to the template.
        $template = Template::getInstance();

        if (!empty($this->page)) {
            $template->set('content', $this->page);
        }

        $template->set('google_analytics_id', Configuration::get('google_analytics_id'));

        // TODO: These should be called directly from the template.
        $template->set('errors', Messenger::getErrors());
        $template->set('messages', Messenger::getMessages());

        $template->set('site_name', Configuration::get('site.name'));
        $template->set('blog', Blog::getInstance());
        JS::set('active_nav', $this->nav);
        $template->render($this->template);
    }
Esempio n. 3
0
    /**
     * Die on an error with a message in json format.
     *
     * @param string $error
     *   The error message.
     *
     * @deprecated
     *   The error() function will determine if json should be output based on the headers.
     */
    public static function jsonError($error = '') {
        $data = array(
            'errors' => Messenger::getErrors(),
            'messages' => Messenger::getMessages(),
            'status' => 'error',
        );

        if (!empty($error)) {
            $data['errors'][] = $error;
        }

        // Output the data.
        header('Content-type: application/json');
        echo json_encode($data);

        // Terminate the script.
        exit;
    }
Esempio n. 4
0
 /**
  * Output the data.
  */
 public function output()
 {
     Output::json(array('data' => $this->data, 'messages' => Messenger::getMessages(), 'errors' => Messenger::getErrors()));
 }
Esempio n. 5
0
<?php

use Lightning\Tools\Messenger;
use Lightning\Tools\Request;
use Lightning\Tools\Router;
define('HOME_PATH', __DIR__);
require_once 'Lightning/bootstrap.php';
$handler = Router::getRoute();
if (empty($handler)) {
    // TODO: show 404;
    echo "No handler found.\n";
    exit;
}
try {
    $page = new $handler();
    $page->execute();
} catch (Exception $e) {
    $errors = Messenger::getErrors();
    array_unshift($errors, $e->getMessage());
    echo implode("\n", $errors);
}