Exemplo n.º 1
0
 /**
  * Return a CSRF token.
  *
  *
  * @return string
  */
 public function token()
 {
     if ($this->app['Session']->has('disco-csrf-token')) {
         return $this->app['Session']->get('disco-csrf-token');
     }
     //if
     $this->app['Session']->set('disco-csrf-token', \Disco\manage\Manager::genRand(32));
     return $this->app['Session']->get('disco-csrf-token');
 }
Exemplo n.º 2
0
 /**
  * Create a model or a record. Use the special keyword `all` in place of a table name to generate records or 
  * models for all tables.
  *
  * eg: `create model user`
  * eg: `create model user /app/config/model.format /app/model/`
  *
  * eg: `create record user`
  * eg: `create record user /app/config/record.format /app/record/`
  *
  * @param array $args The arguements.
  */
 public function create($args)
 {
     if ($args[0] == 'model') {
         if (!isset($args[1])) {
             echo 'You must specify a table to build the model from' . PHP_EOL;
             exit;
         }
         //if
         $table = $args[1];
         $templatePath = isset($args[2]) ? $args[2] : 'app/config/model.format';
         $outputPath = isset($args[3]) ? $args[3] : 'app/model';
         if ($table == 'all') {
             $result = $this->getDBSchema();
             while ($row = $result->fetch()) {
                 $model = \Disco\manage\Manager::buildModel($row['table_name']);
                 \Disco\manage\Manager::writeModel($row['table_name'], $model, $templatePath, $outputPath);
             }
             //while
         } else {
             $model = \Disco\manage\Manager::buildModel($table);
             \Disco\manage\Manager::writeModel($table, $model, $templatePath, $outputPath);
         }
         //el
     } else {
         if ($args[0] == 'record') {
             if (!isset($args[1])) {
                 echo 'You must specify a table to build the record from' . PHP_EOL;
                 exit;
             }
             //if
             $table = $args[1];
             $templatePath = isset($args[2]) ? $args[2] : 'app/config/record.format';
             $outputPath = isset($args[3]) ? $args[3] : 'app/record';
             if ($table == 'all') {
                 $result = $this->getDBSchema();
                 while ($row = $result->fetch()) {
                     $record = \Disco\manage\Manager::buildRecord($row['table_name']);
                     \Disco\manage\Manager::writeRecord($row['table_name'], $record, $templatePath, $outputPath);
                 }
                 //while
             } else {
                 $record = \Disco\manage\Manager::buildRecord($table);
                 \Disco\manage\Manager::writeRecord($table, $record, $templatePath, $outputPath);
             }
             //el
         }
     }
     //elif
 }
Exemplo n.º 3
0
 /**
  * Hash with sha512.
  * Generate a new salt and hash the value with it, returning both the salt and hash.
  *
  * 
  * @param string $value The value to hash using sha512. 
  * @param int $saltLength The length of the salt to generate, defaults to 128.
  *
  * @return array An array with two keys, `salt` and `hash`, containing the salt and hash value respectivly.
  *
  */
 public function hashAndGenerateNewSalt($value, $saltLength = 128)
 {
     $salt = \Disco\manage\Manager::genRand($saltLength);
     return array('salt' => $salt, 'hash' => $this->hash($value, $salt));
 }