Cakephp Auth login REST response

S. M. Sakil Imran
public function login()
{
    if($this->request->is('post')){
        if($this->Auth->login()){
            var_dump('Logged in successfully');

        }else{
            var_dump('Log in failed');
        }
    }
}

When I'm writing the above code, I'm getting output as following in browser view:

string(22) "Logged in successfully"

But when I'm rewriting the code as following to use as REST api:

public function login()
{
    if($this->request->is('post')){
        if($this->Auth->login()){
            $message = 'Logged in successfully';

        }else{
            $message = 'Error. Log in failed. Please, try again.';
        }
        $this->set(array(
            'message' => $message,
            '_serialize' => array('message')
        ));
    }
}

Now I'm getting response like the following:

{
   message: "Error. Log in failed. Please, try again."
}

I'm using 'Advanced Rest Client' extension for Chrome to check the REST response.

S. M. Sakil Imran

I've tried to login as following:

Wrong way to get the right response

But it worked fine and gave me the expected response when I've done as following:

Right way to get the right response

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Cakephp Auth multiple login redirect

CakePHP Auth login non sense

Cakephp Auth always generates same hash at login

CakePHP 1.3 Auth component not hashing password on login

CakePHP 3 - Multiple field Auth login

Auth login doesn't work in cakephp

CakePHP - Cannot login user using Blowfish Auth

Cakephp auth login issue. Can I use ClientController for login?

Send REST response on data using CakePhp

failed to configure axios with django rest auth to login and get auth token

Login [ Auth->identify() ] always false on CakePHP 3

CakePHP 2.4 Auth->login() always return TRUE

CakePHP 3 Rest Api JWT plugin Form login Not working

Cakephp 3.0 REST API add conditions in API response

Is there any way to change view of Django-rest-auth of login?

Spring Security basic auth for REST Api single login needed?

Django REST Framework and python-social-auth for registration/login user

After login the `rest-auth`, how to return more information?

vTiger REST login error: "INVALID_AUTH_TOKEN" (php and/or python)

how to create custom login view with Django rest_auth?

How to loop through the error response from django rest-auth

Spring Boot Rest response returning login.jsp

swift JSON login REST with post and get response example

Cakephp 2.9.0 Authentication not working,$this->Auth->login always return false

How to add the last_login_ip, when the user login if using `rest-auth`?

How can I do my logic in `http://127.0.0.1:8000/rest-auth/login/` of `django-rest-auth`?

Mock auth cakephp 3

CakePHP role based auth

wried cakephp auth behavior