removed checkToken for admin ajax

This commit is contained in:
Jonathan Labreuille
2016-10-11 16:33:16 +02:00
parent cc523a3c0b
commit 5d0ee43921

View File

@ -13,12 +13,6 @@ class API {
private $_data = array(); private $_data = array();
function init() { function init() {
// security token
add_action(
'admin_head',
array($this, 'setToken')
);
// Admin API (Ajax only) // Admin API (Ajax only)
add_action( add_action(
'wp_ajax_mailpoet', 'wp_ajax_mailpoet',
@ -34,7 +28,6 @@ class API {
function setupAdmin() { function setupAdmin() {
$this->getRequestData(); $this->getRequestData();
$this->checkToken();
$this->checkPermissions(); $this->checkPermissions();
$this->processRoute(); $this->processRoute();
} }
@ -46,15 +39,17 @@ class API {
} }
function getRequestData() { function getRequestData() {
$this->_endpoint = isset($_POST['endpoint']) ? trim($_POST['endpoint']) : null; $this->_endpoint = isset($_POST['endpoint'])
$this->_method = (isset($_POST['method'])) ? trim($_POST['endpoint'])
: null;
$this->_method = isset($_POST['method'])
? trim($_POST['method']) ? trim($_POST['method'])
: null; : null;
$this->_token = (isset($_POST['token'])) $this->_token = isset($_POST['token'])
? trim($_POST['token']) ? trim($_POST['token'])
: null; : null;
if(!$this->_endpoint || !$this->_method || !$this->_token) { if(!$this->_endpoint || !$this->_method) {
// throw exception bad request // throw exception bad request
$error_response = new ErrorResponse( $error_response = new ErrorResponse(
array( array(
@ -109,7 +104,10 @@ class API {
if($has_permission === false) { if($has_permission === false) {
$error_response = new ErrorResponse( $error_response = new ErrorResponse(
array( array(
Error::FORBIDDEN => __('You do not have the required permissions.', 'mailpoet') Error::FORBIDDEN => __(
'You do not have the required permissions.',
'mailpoet'
)
), ),
array(), array(),
Response::STATUS_FORBIDDEN Response::STATUS_FORBIDDEN
@ -134,11 +132,4 @@ class API {
$error_response->send(); $error_response->send();
} }
} }
function setToken() {
$global = '<script type="text/javascript">';
$global .= 'var mailpoet_token = "'.Security::generateToken().'";';
$global .= '</script>';
echo $global;
}
} }