1
votes

I am allowing two types of login on the website Site Account and Facebook User..

For the facebook user the password field will be empty.

so i do a query like this in the login action to find out if the user is a facebook user.

    if(!empty($this->data)){
        $this->User->recursive = -1;
        $facebook_user = $this->User->find('count', array('conditions' => array('email' => $this->data['User']['email'], 'password' => null)));

        if($facebook_user == 1){
            $this->Auth->loginError = "Looks like you have used Facebook connect to Login to the website.";
        }
    }

if the $facebook_user == 1 then i want the particular LoginError to be displayed.

As default i am setting LoginError in the before Filter to

$this->Auth->loginError = "Please check the Username and Passwords";

But the facebook LoginError doesnt get assigned even if $facebook_user is set to 1

BeforeFilter in Users Controller

function beforeFilter() {
    $this->Auth->fields = array('username' => 'email', 'password' => 'password');
$this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'harsha');
    $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'killer');
$this->Auth->loginError = "Please check the Username and Passwords";
$this->Auth->authError = "You are not authorized to be here Bitch.";

    $this->Auth->allow('*');
}

BeforeFilter() in App Controller

function beforeFilter() {
    $this->Auth->allow('*');
    //$this->Auth->userScope = array('User.status' => 'active');


    // Setting Admin Template
    if(isset($this->params['admin'])) {
        $this->layout = 'admin';
    }
}
1
This could be because your AppController is called when a redirect happens, which subsequently clears your facebook message. Might want to just move it to the session and pull from there - JohnP
try assigning a value out of the if statement,at the start of the login action and see if it works. - Headshota
@John doesnt BeforeFilter run before the Methods in a controller ? - Harsha M V
@Shota i tried that.. same problem :( - Harsha M V
@harsha, it does. But the problem here may be that you are redirecting to the loginAction once this code is run. That means of course that the default beforeFilter is the one that gets set - JohnP

1 Answers