CSRF : Allow to get the CSRF token from the CSRF or FORM classes
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2790 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
8
csrf.php
8
csrf.php
@@ -68,4 +68,12 @@ class csrf
|
|||||||
$res .= "value='$this->csrfToken'/>\n";
|
$res .= "value='$this->csrfToken'/>\n";
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return the token if exists or create a new one if needed */
|
||||||
|
public function getToken ()
|
||||||
|
{
|
||||||
|
if ($this->csrfToken === "")
|
||||||
|
$this->createToken ();
|
||||||
|
return $this->csrfToken;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
form.php
11
form.php
@@ -24,6 +24,8 @@ class form
|
|||||||
public $csrf=TRUE;
|
public $csrf=TRUE;
|
||||||
/** Name of the CSRF hidden field in HTML page */
|
/** Name of the CSRF hidden field in HTML page */
|
||||||
public $csrfField = "CSRF_TOKEN";
|
public $csrfField = "CSRF_TOKEN";
|
||||||
|
/** The CSRF token value */
|
||||||
|
private $csrfToken = "";
|
||||||
|
|
||||||
/** The method used to send the values */
|
/** The method used to send the values */
|
||||||
private $method = "post";
|
private $method = "post";
|
||||||
@@ -193,6 +195,7 @@ class form
|
|||||||
$csrf = new csrf ();
|
$csrf = new csrf ();
|
||||||
$csrf->field = $this->formName."[".$this->csrfField."]";
|
$csrf->field = $this->formName."[".$this->csrfField."]";
|
||||||
$res .= $csrf->displayFormCSRF ();
|
$res .= $csrf->displayFormCSRF ();
|
||||||
|
$this->csrfToken = $csrf->getToken ();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manage the focus. On the first visible element if there is no error, on
|
// Manage the focus. On the first visible element if there is no error, on
|
||||||
@@ -225,6 +228,14 @@ class form
|
|||||||
$csrf->checkToken ($tokenFromUser);
|
$csrf->checkToken ($tokenFromUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return the token generated in form */
|
||||||
|
public function getToken ()
|
||||||
|
{
|
||||||
|
if ($this->csrfToken === "")
|
||||||
|
$this->createToken ();
|
||||||
|
return $this->csrfToken;
|
||||||
|
}
|
||||||
|
|
||||||
/** Check if the parameters are correct with the defined fields
|
/** Check if the parameters are correct with the defined fields
|
||||||
* Need the session !
|
* Need the session !
|
||||||
* @return array containing the errors
|
* @return array containing the errors
|
||||||
|
|||||||
Reference in New Issue
Block a user