hi every one
i use cakephp in back end and when i try to login in my application ionic Knowing when i use method POST i get : Response for preflight has invalid HTTP status code 500 in console of my browser.
but when i use method GET all things are working but i noticed when i check data requeste i found that array is void nothing inside.
i don’t know why when i use post is not working where is problem
thanks.
var config = {
headers : {'Access-Control-Allow-Origin' : '*',
'Access-Control-Allow-Methods' : 'POST, GET, OPTIONS, PUT',
'Content-Type': 'application/json',
'Accept': 'application/json',
'Access-Control-Allow-Headers':'X-Requested-With',
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
}
}
$http.post(link, {"data.User.password": pw,"data.User.username": email},config).then(function(response){
//console.info(response);
deferred.resolve(response.data);
}, function(errResponse){
deferred.reject(errResponse);
});
return promise;
}
}
})
public function login() {
if ($this->Session->read('Auth.User')) {
$this->set(array(
'message' => array(
'text' => __('You are logged in!'),
'type' => 'error',
'status'=> 200,
'success'=>1
),
'_serialize' => array('message')
));
}
if ($this->request->is('post')) {
//debug($this->request->data);
//die;
if ($this->Auth->login()) {
//debug($this->Session->read('Auth.User'));
//die;
//return $this->redirect($this->Auth->redirect());
//debug('if**********************************');
//die;
$this->set(array(
'user' => $this->Session->read('Auth.User'),
'_serialize' => array('user')
));
} else {
//debug('else *************************');
//die;
$array_data = array_keys($this->request->data);
$this->set(array(
'message' => array(
'text' => __('Invalid username or password, try again'),
'type' => 'error',
'status'=> 200,
'success'=>0,
'data_0'=>$this->request->data
//'data_1'=>$_GET['password']
),
'_serialize' => array('message')
));
// $this->response->statusCode(401);
}
}
}