Beispiel #1
0
 public static function started()
 {
     if (self::$_started === null) {
         $options = SlConfigure::read('Sl.session');
         session_write_close();
         foreach ($options as $option => $value) {
             if (isset($value)) {
                 ini_set("session.{$option}", $value);
             }
         }
         self::$_started = session_start();
         if (!self::$_started) {
             return false;
         }
         self::$data =& $_SESSION;
         // prevent proxy-jumping and session hijacks
         $ip = self::read('Security.remoteAddr');
         if ($ip && env('REMOTE_ADDR') != $ip) {
             session_write_close();
             session_regenerate_id(true);
             self::$_started = session_start();
         }
         if (empty($ip)) {
             self::write('Security.remoteAddr', env('REMOTE_ADDR'));
         }
     }
     return self::$_started;
 }
 public function oauth()
 {
     if (isset($this->params['url']['code'])) {
         $code = $this->params['url']['code'];
     }
     SlSession::write('Api.facebook.accessToken', r('access_token=', '', $this->Facebook->graph("oauth/access_token", array('client_id' => SlConfigure::read('Api.facebook.appId'), 'redirect_uri' => Sl::url(true), 'client_secret' => SlConfigure::read('Api.facebook.secret'), 'code' => $code, 'decode' => false))));
     $this->redirect(SlConfigure::read('Api.facebook.oauthSuccess'));
 }
Beispiel #3
0
 function parse($html = null, $blockName = 'document', $blockParams = null, $noCycle = false)
 {
     $messages = SlConfigure::read2('Message');
     if ($messages) {
         SlSession::delete('Message');
     } else {
         $messages = array();
     }
     $this->vars['bufferedOutput'] = SlConfigure::read('View.bufferedOutput');
     SlConfigure::delete('View.bufferedOutput');
     if ($messages || $this->vars['bufferedOutput']) {
         $this->blocks["loop"]->params[0] = $messages;
         return parent::parse($html, $blockName);
     }
 }
 public function login()
 {
     $this->helpers[] = 'JsValidate.Validation';
     $this->AuthUser;
     $this->set('title', __t('Login'));
     if (!empty($this->data['AuthUser']['username'])) {
         if (SlAuth::login($this->data['AuthUser']['username'], $this->data['AuthUser']['password'], array('remember' => $this->data['AuthUser']['remember']))) {
             $key = empty($this->params['admin']) ? 'Auth.url.afterLogin' : 'Auth.url.afterAdminLogin';
             $url = SlConfigure::read2($key);
             SlSession::delete($key);
             $this->redirect($url);
         } else {
             $this->Session->setFlash(__t('Login error. Check username and password'));
         }
     }
 }
Beispiel #5
0
 public function getSession($scope = null)
 {
     $this->accessToken = SlSession::read('Api.facebook.accessToken');
     if ($this->accessToken) {
         return;
     }
     if (is_array($scope)) {
         $scope = implode(',', $scope);
     }
     $appId = SlConfigure::read('Api.facebook.appId');
     $redirectUrl = array('plugin' => 'api', 'controller' => 'facebook', 'action' => 'oauth');
     if (!empty($this->params['prefix'])) {
         $redirectUrl += array($this->params['prefix'] => false);
     }
     $redirectUrl = urlencode(Sl::url($redirectUrl, true));
     $this->controller->redirect("https://graph.facebook.com/oauth/authorize?client_id={$appId}&redirect_uri={$redirectUrl}&scope={$scope}");
 }
Beispiel #6
0
 /**
  * For compatibility with Cake
  */
 function flash($key = 'flash')
 {
     $out = false;
     $flash = SlSession::read('Message.' . $key);
     if ($flash['element'] == 'default') {
         if (!empty($flash['params']['class'])) {
             $class = $flash['params']['class'];
         } else {
             $class = 'message';
         }
         $out = '<div id="' . $key . 'Message" class="' . $class . '">' . $flash['message'] . '</div>';
     } elseif ($flash['element'] == '' || $flash['element'] == null) {
         $out = $flash['message'];
     } else {
         $view =& ClassRegistry::getObject('view');
         $tmpVars = $flash['params'];
         $tmpVars['message'] = $flash['message'];
         $out = $view->element($flash['element'], $tmpVars);
     }
     SlSession::delete('Message.' . $key);
     return $out;
 }
 /**
  * Redirects to given $url, after turning off $this->autoRender.
  * Script execution is halted after the redirect.
  *
  * @param mixed $url A string or array-based URL pointing to another location within the app, or an absolute URL
  * @param integer $status Optional HTTP status code (eg: 404)
  * @access public
  * @link http://book.cakephp.org/view/425/redirect
  */
 public function redirect($url, $status = null, $useReferer = true)
 {
     if ($useReferer) {
         $ref = SlSession::read('Routing.ref');
         if ($ref) {
             SlSession::delete('Routing.ref');
             if (Sl::url($ref) !== Sl::url()) {
                 $url = $ref;
             }
         }
     }
     // cyclic check
     if (Sl::url($url) === Sl::url()) {
         die('Infinite redirection loop detected.');
     }
     // code inspired from RequestHandlerComponent
     if ($this->RequestHandler->isAjax()) {
         foreach ($_POST as $key => $val) {
             unset($_POST[$key]);
         }
         echo Sl::requestAction($url, array('requested' => false));
         $this->_stop();
     }
     // show a human readable redirect message allowing debug output to be read
     if (headers_sent() || $this->output && Configure::read()) {
         $url = h(SL::url($url));
         if (empty($status)) {
             $status = 'null';
         }
         echo "<p style='background: #ff7; color: #000; padding: 1em;'>Redirect to <a href='{$url}'>{$url}</a> (code: {$status}) cancelled.</p>";
         while (ob_get_level()) {
             ob_end_flush();
         }
         $this->_stop();
     }
     parent::redirect(Sl::url($url, true), $status);
 }
Beispiel #8
0
 public function started()
 {
     return SlSession::started();
 }
Beispiel #9
0
 /**
  * Set the list of active collections
  *
  * @param array $collections names
  * @param bool $setDefault
  *
  * @return string Key to be used in restoreColections(...)
  */
 public static function setCollections($collections = array(), $setDefault = true)
 {
     if ($setDefault) {
         if (self::$_collections && SlExtensions::loaded('Auth')) {
             $user = SlAuth::user();
             if (isset($user['id'])) {
                 $groups = SlSession::read('Auth.groups');
                 $collections["users"] = 200;
                 if ($groups) {
                     foreach ($groups as $i => $group) {
                         $collections["Group{$group['id']}"] = 201 + $i;
                         $collections[$group['name']] = 201 + $i;
                     }
                 }
                 $collections["User{$user['id']}"] = 299;
             } else {
                 $collections["guest"] = 299;
             }
         }
         $controller = Sl::getInstance()->controller;
         if ($controller) {
             $collections["{$controller->name}Controller"] = 50;
             if (!empty($controller->params['home'])) {
                 $collections['home'] = 70;
             }
             if (!empty($controller->params['plugin'])) {
                 $plugin = Inflector::camelize($controller->params['plugin']);
                 $collections["{$plugin}Plugin"] = 60;
                 //                    $collections["{$plugin}{$controller->name}"] = 61;
             }
         }
         $collections = am(array('important' => 1000, 'cookie' => 10, 'session' => 20, 'global' => 0), $collections);
     }
     $collections = Set::normalize($collections);
     arsort($collections);
     self::$_collectionsNoLocale = $collections;
     $localizedCollections = array();
     foreach ($collections as $collection => $priority) {
         if (self::$_locale) {
             $localizedCollections[] = $collection . "." . self::$_locale;
         }
         $localizedCollections[] = $collection;
     }
     $key = self::rememberCollections();
     self::$_collections = $localizedCollections;
     self::_refresh();
     return $key;
 }
Beispiel #10
0
 public static function logout()
 {
     $guest = SlConfigure::read('Auth.guest');
     $guest['fullname'] = __t($guest['fullname']);
     //$guest['roles'] = Set::normalize($guest['roles']);
     SlSession::write('Auth.user', $guest);
     SlSession::write('Auth.groups', array());
 }
Beispiel #11
0
 public function actionLink($action, $url = null, $options = array())
 {
     $options += array('title' => __t(Inflector::humanize($action)), 'url' => array());
     switch ($action) {
         case 'back':
             $ref = SlSession::read('Routing.ref');
             if (empty($ref)) {
                 $ref = env('HTTP_REFERER');
             }
             if (Sl::url($ref, true) == Sl::url(true)) {
                 $ref = null;
             }
             if ($ref) {
                 $options['url'] = $ref;
             } else {
                 $url2 = array('action' => 'index');
             }
             break;
         case 'clone':
             $url2 = array('action' => 'add');
             break;
         case 'preview':
             $url2 = array('admin' => false, 'action' => 'view');
             break;
         default:
             $url2 = array('action' => $action);
     }
     $url2['ref'] = isset($this->params['named']['ref_override']) ? $this->params['named']['ref_override'] : base64_encode(Sl::getInstance(true)->url(false));
     if ($url !== null) {
         if (is_array($url)) {
             $url2 = $url + $url2;
         } else {
             $url2[] = $url;
         }
     } else {
         // automagically pass filtering params
         foreach ($this->params['named'] as $param => $value) {
             if (preg_match('/_id$/', $param) || $param == 'skin') {
                 $url2[$param] = $value;
             }
         }
     }
     if (is_array($options['url'])) {
         $options['url'] += $url2;
     }
     switch ($action) {
         case 'add':
         case 'clone':
             $options += array('class' => 'add');
             break;
         case 'edit':
             $options += array('class' => 'edit');
             break;
         case 'preview':
             $options += array('target' => '_blank');
             break;
         case 'delete':
             $options += array('confirm' => __t('Delete?'), 'class' => 'remove');
             break;
     }
     $title = $options['title'];
     $url = $options['url'];
     unset($options['title']);
     unset($options['url']);
     return $this->link($title, $url, $options);
 }