Ejemplo n.º 1
0
 public function __construct()
 {
     parent::__construct();
     $this->isRequired();
     $this->setValidator('NotEmpty');
     $this->initCsrfValidator();
 }
Ejemplo n.º 2
0
 /**
  * Constructor
  *
  * Instantiate the CSRF input form element
  *
  * @param  string $name
  * @param  string $value
  * @param  string $indent
  * @param  int    $expire
  * @return Csrf
  */
 public function __construct($name, $value = null, $indent = null, $expire = 300)
 {
     // Start a session.
     if (session_id() == '') {
         session_start();
     }
     // If token does not exist, create one
     if (!isset($_SESSION['pop_csrf'])) {
         $this->token = ['value' => sha1(rand(10000, getrandmax()) . $value), 'expire' => (int) $expire, 'start' => time()];
         $_SESSION['pop_csrf'] = serialize($this->token);
         // Else, retrieve existing token
     } else {
         $this->token = unserialize($_SESSION['pop_csrf']);
         // Check to see if the token has expired
         if ($this->token['expire'] > 0) {
             if ($this->token['expire'] + $this->token['start'] < time()) {
                 $this->token = ['value' => sha1(rand(10000, getrandmax()) . $value), 'expire' => (int) $expire, 'start' => time()];
                 $_SESSION['pop_csrf'] = serialize($this->token);
             }
         }
     }
     parent::__construct($name, $this->token['value'], $indent);
     $this->setRequired(true);
     $this->setValidator();
 }
Ejemplo n.º 3
0
 /**
  * Constructor
  *
  * @param string|array $name    name attribute or array of all attributes
  * @param integer      $timeout timeout in seconds for generated token
  */
 public function __construct($name = 'XOOPS_TOKEN', $timeout = 0)
 {
     if (is_array($name)) {
         parent::__construct($name);
     } else {
         parent::__construct([]);
         $this->set('name', $name);
         $this->set(':timeout', $timeout);
     }
     $name = $this->get('name', 'XOOPS_TOKEN');
     if (substr($name, -8) !== '_REQUEST') {
         $this->set('name', $name . '_REQUEST');
     }
     $this->set('value', \Xoops::getInstance()->security()->createToken($this->get(':timeout', 0), $name));
 }
Ejemplo n.º 4
0
 /**
  * @param string $name
  * @param string $value
  */
 public function __construct(string $name, string $value = null)
 {
     parent::__construct($name, $value);
     $this->setRenderable(false);
 }
Ejemplo n.º 5
0
 /**
  * Create instance
  *
  * @param string $name The name of the field
  * @param array  $data The data to construct the field
  */
 public function __construct($name, array $data)
 {
     parent::__construct($name, $data);
 }
Ejemplo n.º 6
0
 /**
  * Constructor
  *
  * @param string  $name    name
  * @param integer $timeout timeout in seconds for generated token
  */
 public function __construct($name = 'XOOPS_TOKEN', $timeout = 0)
 {
     $xoops = \Xoops::getInstance();
     parent::__construct($name . '_REQUEST', $xoops->security()->createToken($timeout, $name));
 }