简体   繁体   中英

Cakephp 2.4 Ajax Login

Not sure which part went wrong and tried to search through google for tutorial but no luck with the source out there. Basically whenever I try to submit the form, it check through chrome network and does the redirection to google.com even though the password is wrong. Anyone has clearer understand on cakephp auth to guide me through?

Here is what I did

AppController.php

public $components = array('DebugKit.Toolbar',
                           'Session',
                           'Auth');

UsersController.php

public function login()
{
    if ($this->request->is('post')) 
    {
        $this->request->data['User']['username'] = $_POST['email'];
        $this->request->data['User']['password'] = $_POST['password'];

        if ($this->Auth->login()) 
        {
            $this->redirect('http://www.google.com');
        }
    }
}

I find out the reason redirecting keeps going through is that the previous user already logged in successfully. So what I do is providing the logout link and try again.

public function logout() {
   return $this->redirect($this->Auth->logout());
}

Thanks again everyone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM