Login application


#1

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.

 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.

service.js
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;
            }			
	}
    })
`usercontroller.php`
 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);
            }
        }
    }


#2

Your server responds with an error 500 to an OPTIONS request (not GET or POST). It shouldn’t do that.
Yes, you don’t want to do an OPTIONS request in the app - but for security reasons the browser does before doing the actual request.


#3

iOS mandates use of TLS, so make all your requests to https:// URLs, not http://. The whole “GET works, but POST silently has blank body” is symptomatic of this issue.


#5

exactly when i exucted this command :“chrome.exe --user-data-dir=“C:/Chrome dev session” --disable-web-security”. it working.
thanks for all.