php - Cakephp Auth component behaviour for REST API call -


i trying implement api_login function. have 2 functions in userscontroller logging in 1)login

public function login() {     if($this->request->is('post') && authcomponent::user('id') == null) {         if($this->auth->login()) {             return $this->redirect(array('controller' => 'users', 'action' => 'index'));         }         $this->session->setflash(__('invalid username or password'));     }     else if(authcomponent::user('id') != null){         $this->redirect(array('action' => 'controls'));     } } 

and 2) api_login

public function api_login() {         if($this->request->is('post')) {             if($this->auth->login()) {                 $message = 'success';                 $this->set(array('message' => $message, '_serialize' => 'message'));             }             else {                 $message = 'fail';                 $this->set(array('message' => $message, '_serialize' => 'message'));             }         }     } 

the login function works fine. have issues api_login when use rest client postman, post requests http://myproject/api/users/login.json, cannot log in(shows 'fail' everytime) try post , log in using correct credentials.

the fileds post username: , password:. dont understand doing wrong. appreciated. if missing describe problem fully, please ask.

you need pass post data in login check username , password

if ($this->auth->login($this->request->data)) 

hope helps you


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -