Example #1
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;
 }
 public function auth()
 {
     $this->helpers[] = 'JsValidate.Validation';
     $this->set('title', __t('StarLight installation: Administrator profile'));
     if (!SlExtensions::loaded('Auth')) {
         $this->Session->setFlash(__t('Auth extension is disabled. All security settings will be ignored.'));
         $this->redirect(array('action' => 'done'));
     }
     //        $this->loadModel('Auth.AuthUser');
     $user = $this->AuthUser->read(null, 1);
     if ($user) {
         $this->Session->setFlash(__t('Administrator profile step skipped. A root user (<b>{$username}</b>) is already registered.', array('username' => $user['AuthUser']['username'])), array('class' => 'message'));
         $this->redirect(array('action' => 'done'));
     }
     if ($this->data) {
         $success = $this->data['AuthUser']['password'] == $this->data['AuthUser']['confirm_password'];
         if (!$success) {
             $this->AuthUser->invalidate('password', __t('Passwords do not match'));
             return;
         }
         $password = $this->data['AuthUser']['password'];
         $this->data['AuthGroup']['AuthGroup'] = array(1, 2);
         $this->data['AuthUser']['password'] = SlAuth::password($this->data['AuthUser']['password']);
         $this->data['AuthUser']['active'] = true;
         // force loading of associated model
         $this->AuthUser->AuthGroup;
         if ($this->AuthUser->saveAll($this->data)) {
             SlAuth::login($this->data['AuthUser']['username'], $password);
             $this->redirect(array('action' => 'done'));
         }
     }
 }