コード例 #1
0
ファイル: DataTableSnippet.php プロジェクト: jivoo/jivoo
 /**
  * {@inheritdoc}
  */
 public function before()
 {
     parent::before();
     if (isset($this->request->cookies['data-table-per-page'])) {
         $this->object->rowsPerPage = intval($this->request->cookies['data-table-per-page']);
     }
     if (isset($this->request->cookies['data-table-density'])) {
         $this->object->density = $this->request->cookies['data-table-density'];
     } else {
         $this->object->density = 'medium';
     }
     $tableSettings = new Form('tableSettings');
     $tableSettings->addField('perPage', DataType::integer(DataType::UNSIGNED));
     $tableSettings->__set('perPage', $this->object->rowsPerPage);
     $tableSettings->addField('density', DataType::enum(array('low', 'medium', 'high')));
     $tableSettings->__set('density', $this->object->density);
     $this->viewData['tableSettings'] = $tableSettings;
 }
コード例 #2
0
ファイル: AppController.php プロジェクト: jivoo/jivoo
 public function settings()
 {
     if (!$this->Auth->isLoggedIn()) {
         $this->Auth->authenticationError();
     }
     $this->title = tr('Settings');
     $form = new Form('Settings');
     $form->addString('title', tr('Title'));
     $form->addString('username', tr('Username'));
     $form->addString('password', tr('Password'));
     $form->addString('confirmPassword', tr('Confirm password'));
     $form->title = $this->config['title'];
     $form->username = $this->config['username'];
     if ($this->request->hasValidData('Settings')) {
         $form->addData($this->request->data['Settings']);
         $this->config['title'] = $form->title;
         $this->config['username'] = $form->username;
         if (!empty($form->password)) {
             if ($form->password === $form->confirmPassword) {
                 $this->config['password'] = $this->Auth->passwordHasher->hash($form->password);
                 if ($this->config->save()) {
                     $this->Notify->success = tr('Password changed.');
                     return $this->refresh();
                 } else {
                     $this->Notify->error = tr('Could not save configuration file.');
                 }
             } else {
                 $form->addError('password', tr('The two passwords are not identical.'));
             }
         } else {
             if ($this->config->save()) {
                 $this->Notify->success = tr('Settings saved.');
                 return $this->refresh();
             } else {
                 $this->Notify->error = tr('Could not save configuration file.');
             }
         }
     }
     $this->settings = $form;
     return $this->render();
 }
コード例 #3
0
ファイル: LockInstaller.php プロジェクト: jivoo/jivoo
 /**
  * Set up maintenance user and install lock.
  * @param string $data POST data if any.
  * @return \Jivoo\Routing\Response|string Response.
  */
 public function configure($data = null)
 {
     $this->viewData['title'] = tr('Configure maintenance user');
     $form = new Form('user');
     $form->addField('username', DataType::string(), tr('Username'));
     $form->addField('password', DataType::string(), tr('Password'));
     $form->addField('confirmPassword', DataType::string(), tr('Confirm password'));
     $form->username = '******';
     if (isset($data)) {
         $form->addData($data['user']);
         if ($form->isValid()) {
             if ($form->password !== $form->confirmPassword) {
                 $form->addError('password', tr('The two passwords are not identical.'));
             } else {
                 $auth = $this->m->Setup->getAuth();
                 $password = $auth->passwordHasher->hash($form->password);
                 $this->m->Setup->lock($form->username, $password);
                 return $this->next();
             }
         }
     }
     $this->viewData['user'] = $form;
     return $this->render();
 }
コード例 #4
0
ファイル: DatabaseInstaller.php プロジェクト: jivoo/jivoo
 /**
  * Installer step: Configure database driver.
  * @param array $data POST data.
  * @return \Jivoo\Routing\Response|string Response.
  */
 public function configure($data = null)
 {
     if (!isset($this->config['driver'])) {
         return $this->back();
     }
     $driver = $this->DatabaseDrivers->checkDriver($this->config['driver']);
     if (!isset($driver) or $driver['isAvailable'] !== true) {
         unset($this->config['driver']);
         if ($this->config->save()) {
             return $this->back();
         } else {
             return $this->saveConfig();
         }
     }
     $this->viewData['title'] = tr('Configure %1', $driver['name']);
     $form = new Form('driver');
     foreach ($driver['requiredOptions'] as $option) {
         $form->addString($option, $this->getOptionLabel($option));
     }
     foreach ($driver['optionalOptions'] as $option) {
         $form->addString($option, $this->getOptionLabel($option), false);
     }
     if (isset($data)) {
         $form->addData($data['driver']);
         if ($form->isValid()) {
             $class = 'Jivoo\\Databases\\Drivers\\' . $driver['driver'] . '\\' . $driver['driver'] . 'Database';
             try {
                 new $class(new DatabaseSchemaBuilder(), $form->getData());
                 $options = array_flip(array_merge($driver['requiredOptions'], $driver['optionalOptions']));
                 foreach ($form->getData() as $key => $value) {
                     if (isset($options[$key])) {
                         $this->config[$key] = $value;
                     }
                 }
                 unset($this->config['migration']);
                 return $this->saveConfigAndContinue();
             } catch (ConnectionException $exception) {
                 $this->Notify->error = tr('An error occured: %1', $exception->getMessage());
             }
         }
     } else {
         $form->addData($this->config->toArray());
     }
     $this->viewData['driver'] = $driver;
     $this->viewData['driverForm'] = $form;
     return $this->render();
 }