Ejemplo n.º 1
0
 public function admin_edit()
 {
     $this->helpers[] = 'JsValidate.Validation';
     if ($this->data) {
         if ($this->_passwordMatch()) {
             $data = $this->data;
             if ($data['AuthUser']['password']) {
                 $data['AuthUser']['password'] = SlAuth::password($data['AuthUser']['password']);
             } else {
                 unset($data['AuthUser']['password']);
             }
             if ($this->AuthUser->saveAll($data)) {
                 $this->redirect(array('action' => 'index'));
             }
         }
     } elseif ($this->id) {
         $this->data = $this->AuthUser->read(null, $this->id);
         if (empty($this->data)) {
             $this->cakeError();
         }
         unset($this->data['AuthUser']['password']);
     }
     $this->_admin_edit();
     $this->set('authGroups', $this->AuthUser->AuthGroup->find('list'));
 }
Ejemplo n.º 2
0
 public function admin_index($activeSection = null)
 {
     $this->set('sections', $sections = SlConfigure::read2("Config.sections"));
     foreach ($sections as $section => $settings) {
         if (!SlAuth::isAuthorized('config' . Inflector::camelize($section))) {
             unset($sections[$i]);
         }
     }
     if (isset($this->data['_section'])) {
         $activeSection = $this->data['_section'];
     }
     if (empty($activeSection) || !isset($sections[$activeSection])) {
         $activeSection = reset(array_keys($sections));
     }
     $settings = $this->_getSettings($activeSection);
     $this->set('title', __t(SlConfigure::read2("Config.sections.{$activeSection}")));
     if ($this->data) {
         $locales = SlConfigure::read('I18n.locales');
         foreach ($settings as $name => &$setting) {
             if (is_int($name)) {
                 $name = "setting_{$name}";
             }
             if ($setting['collection'] == 'user') {
                 $setting['collection'] = 'User' . SlAuth::user('id');
             }
             if (empty($setting['translate'])) {
                 if (isset($this->data[$name])) {
                     $value = $this->data[$name];
                     if (isset($setting['type']) && $setting['type'] == 'json') {
                         $value = json_decode($value, true);
                     } elseif (isset($setting['type']) && $setting['type'] == 'array') {
                         $value = Set::normalize($value, false);
                     }
                     SlConfigure::write($setting['name'], $value, true, $setting['collection']);
                 }
             } else {
                 foreach ($locales as $locale) {
                     if (isset($this->data["{$name}_{$locale}"])) {
                         $value = $this->data["{$name}_{$locale}"];
                         if (isset($setting['type']) && $setting['type'] == 'json') {
                             $value = json_decode($value, true);
                         } elseif (isset($setting['type']) && $setting['type'] == 'array') {
                             $value = Set::normalize($value, false);
                         }
                         SlConfigure::write($setting['name'], $value, true, "{$setting['collection']}.{$locale}");
                     }
                 }
             }
         }
         $settings = $this->_getSettings($activeSection);
         $this->Session->setFlash(__t('Configuration saved'), array('class' => 'success'));
     }
     $this->data['_section'] = $activeSection;
     $this->set('settings', $settings);
 }
Ejemplo n.º 3
0
 function saveAll($data = null, $options = array())
 {
     $controller = Sl::getInstance()->controller;
     $isNew = !$controller->id;
     // set associated model info
     if ($controller->modelClass != 'CmsNode') {
         $data['CmsNode'] += array('model' => $controller->modelClass, 'plugin' => $controller->plugin);
     }
     // remove empty Images, Attachments from data to be saved
     if (!empty($data['CmsImage'])) {
         if (empty($data['CmsImage']['id']) && empty($data['CmsImage']['filename']['name'])) {
             unset($data['CmsImage']);
         }
     }
     if (!empty($data['CmsAttachment'])) {
         foreach ($data['CmsAttachment'] as $i => $image) {
             if (empty($image['id']) && empty($image['filename']['name'])) {
                 unset($data['CmsAttachment'][$i]);
             }
         }
     }
     if (!empty($data['ImageGallery'])) {
         foreach ($data['ImageGallery'] as $i => $image) {
             if (empty($image['id']) && empty($image['filename']['name'])) {
                 unset($data['ImageGallery'][$i]);
             }
         }
     }
     if ($isNew) {
         $data['CmsNode']['auth_user_id'] = SlAuth::user('id');
     }
     if (!empty($data['CmsNode']['model'])) {
         if (empty($options['validation']) || $options['validation'] != 'only') {
             if (!parent::saveAll($data, array('validate' => 'only', 'atomic' => true) + $options)) {
                 return false;
             }
         }
         $modelObject = ClassRegistry::init("{$data['CmsNode']['plugin']}.{$data['CmsNode']['model']}");
         if (!$modelObject->saveAll($data, $options)) {
             return false;
         }
         $data['CmsNode'] += array('foreign_key' => $modelObject->id);
     }
     $result = parent::saveAll($data, $options);
     if ($result && $isNew && $this->CmsImage->id) {
         $this->CmsImage->saveField('cms_node_id', $this->id);
     }
     return $result;
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
0
 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'));
         }
     }
 }
Ejemplo n.º 6
0
 public function startup($controller)
 {
     if (!SlAuth::isAuthorized('action' . Inflector::camelize($controller->action))) {
         $controller->cakeError('error403');
     }
 }