Ejemplo n.º 1
0
 public function index()
 {
     $id = SlAuth::user('id');
     if (!$id) {
         $this->cakeError('error403');
     }
     $this->AuthUser->id = $id;
     if (isset($this->data['AuthUser']['password'])) {
         if ($this->_passwordMatch()) {
             if ($this->AuthUser->saveField('password', SlAuth::password($this->data['AuthUser']['password']), true)) {
                 $this->Session->setFlash(__t('Password changed'), array('class' => 'success'));
             }
         }
     } elseif (isset($this->data['AuthUser']['email'])) {
         // email validation
     } else {
         // security
         unset($this->data['AuthUser']['id']);
         unset($this->data['AuthUser']['password']);
         unset($this->data['AuthUser']['email']);
         $this->AuthUser->save($this->data);
     }
     $this->set('user', $user = $this->AuthUser->read());
     $this->set('title', __t('Welcome, {$name}', array('name' => h($user['AuthUser']['fullname']))));
 }
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
 public function beforeFilter()
 {
     // allow root user creation
     if ($this->action == 'auth') {
         $this->loadModel('Auth.AuthUser');
         if ($this->AuthUser->find('count') == 0) {
             SlConfigure::write('Auth.acl.everyone.actionAuth', true);
         }
     }
     // security check
     if (!Configure::read() && SlConfigure::read('Mirror.version')) {
         if ($this->action == 'migrate') {
             return;
         }
         if (SlExtensions::loaded('Auth') && SlAuth::user('id') == 1) {
             return;
         }
         $this->cakeError();
     }
     parent::beforeFilter();
 }
Ejemplo n.º 5
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;
 }