Ejemplo n.º 1
0
 /**
  * \brief Constructor of a form class
  * \param string	$zone Zone where you want to go
  * \param string	$page Page related to the zone where you wanna go
  * \param string	$method A get or post statement
  */
 public function __construct($zone, $page, $vars = array(), $method = 'post')
 {
     $method = strtolower($method);
     $allowedSendingMethod = array('get', 'post');
     if (!in_array($method, $allowedSendingMethod, true)) {
         throw new \Exception('From sending method ' . $method . ' isn\'t allowed.');
     }
     $this->attributes['action'] = \Kazoo\Page::to($zone, $page, $vars);
     $this->attributes['method'] = $method;
     $this->inputs = array();
     $this->errors = array();
     $this->data = array();
     // Token generation
     $token = new Input('hidden', '_token');
     $token->setValue(\Kazoo\Secure::generateToken(sha1($zone . $page . serialize($vars))));
     $token->addClosure(function ($data) use($zone, $page, $vars) {
         return \Kazoo\Secure::checkToken($data, sha1($zone . $page . serialize($vars)));
     });
     $this->addInput($token);
 }
Ejemplo n.º 2
0
 /**
  * \brief Method used to register new people
  * \param array		$assoc An associative array containing data
  */
 public function register(array $assoc)
 {
     if (!isset($assoc['_pw'])) {
         throw new \Exception('Associative array needs a password.');
     }
     if (!isset($assoc['_email'])) {
         throw new \Exception('Associative array needs an email.');
     }
     foreach ($this->attributes as $field => $value) {
         if (isset($assoc[$field])) {
             $this->attributes[$field] = $assoc[$field];
         }
     }
     unset($this->attributes['_id'], $this->attributes['_active'], $this->attributes['_banned']);
     $this->attributes['_http'] = serialize(self::getUserHttpInfo());
     $this->attributes['_pw'] = \Kazoo\Secure::hash($this->attributes['_pw']);
     $this->attributes['_key'] = \Kazoo\Secure::uniqueCode(10);
     $date = new \DateTime('now');
     $this->attributes['_lastlog'] = $date->format('Y-m-d H:i:s');
     unset($date);
     $this->attributes['_regdate'] = $this->attributes['_lastlog'];
     self::$_db->insert('_kusers', $this->attributes);
     $this->attributes['_id'] = (int) self::$_db->lastInsertId();
 }
Ejemplo n.º 3
0
 public function getHTML()
 {
     $data = '';
     // Any HTML Before ?
     if ($this->HTMLBefore) {
         $data .= $this->HTMLBefore;
     }
     // Creating a label?
     if ($this->label !== null) {
         if ($this->attributes['id'] === null) {
             $this->attributes['id'] = microtime();
         }
         $data .= '<label for="' . $this->attributes['id'] . '">' . $this->label . '</label>';
     }
     // If there's value in $_POST and note in the attribute, fill it after securization
     if ($this->attributes['value'] === null && isset($_POST[$this->attributes['name']])) {
         $this->attributes['value'] = \Kazoo\Secure::sanitize($_POST[$this->attributes['name']]);
     }
     if ($this->attributes['type'] !== 'select' && $this->attributes['type'] !== 'textarea') {
         $data .= '<input';
         // In case of checkbox & radio, all data come from $this->options
         foreach ($this->attributes as $attribute => $value) {
             if ($this->attributes['list'] !== null && $this->attributes['id'] === null) {
                 $this->attributes['id'] = uniqid('dl', true);
             }
             if ($value !== null) {
                 if ($this->attributes['type'] === 'checkbox' && $attibute === 'name') {
                     $data .= ' name="' . $value . '[]"';
                 } else {
                     $data .= ' ' . $attribute . '="' . $value . '"';
                 }
             }
         }
         foreach ($this->customAttributes as $attribute => $value) {
             $data .= ' ' . $attribute . '="' . $value . '"';
         }
         $data .= ' />';
         // Do we need to place a datalist ?
         if ($this->attributes['list'] !== null) {
             $data .= '<datalist id="' . $this->attributes['id'] . '">';
             foreach ($this->options as $value => $label) {
                 $data .= '<option value="' . $value . '">';
             }
             $data .= '</datalist>';
         }
         // Any HTML after ?
         if ($this->HTMLAfter) {
             $data .= $this->HTMLAfter;
         }
         return $data;
     } elseif ($this->attributes['type'] === 'select') {
         $data .= '<select';
         foreach ($this->attributes as $attribute => $value) {
             if ($value !== null && $attribute !== 'type') {
                 $data .= ' ' . $attribute . '="' . $value . '"';
             }
         }
         foreach ($this->customAttributes as $attribute => $value) {
             $data .= ' ' . $attribute . '="' . $value . '"';
         }
         $data .= '>';
         foreach ($this->options as $value => $label) {
             $data .= '<option value="' . $value . '"' . ($this->attributes['value'] == $value ? ' selected' : '') . '>' . $label . '</option>';
         }
         $data .= '</select>';
         // Any HTML after ?
         if ($this->HTMLAfter) {
             $data .= $this->HTMLAfter;
         }
         return $data;
     }
     // And that's a textarea
     $data .= '<textarea';
     foreach ($this->attributes as $attribute => $value) {
         if ($value !== null & $attribute !== 'type') {
             $data .= ' ' . $attribute . '="' . $value . '"';
         }
     }
     foreach ($this->customAttributes as $attribute => $value) {
         $data .= ' ' . $attribute . '="' . $value . '"';
     }
     $data .= '</textarea>';
     // Any HTML after ?
     if ($this->HTMLAfter) {
         $data .= $this->HTMLAfter;
     }
     return $data;
 }