Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've trying to login a user to 2 differents tables tmp_users, active_users, inside UsersController.

I've created two custom Auth components one for each.

App::uses('FormAuthenticate', 'Controller/Component/Auth');

class TmpUserAuthenticate extends FormAuthenticate {  
}

and

App::uses('FormAuthenticate', 'Controller/Component/Auth');

class ActiveAuthenticate extends FormAuthenticate {
}

In my controller I have this: Components:

public $components = array(
        'Cookie',
        'Session',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'home', 'action' => 'index'),
            'logoutRedirect' => array('controller' => 'home', 'action' => 'index'),
            'authenticate' => array(
                'TmpUser' => array(
                    'userModel' => 'User',
                    'fields' => array(
                        'username' => 'email',
                        'password' => 'password'
                    )
                ),
                'Active' => array(
                    'userModel' => 'ActiveUser',
                    'fields' => array(
                        'username' => 'email',
                        'password' => 'password'
                    ),
                    'scope' => array('crma' => 1)
                )
            )
        )
);

login action: this is what I what. first check if it's a tmp_user; if not, then check if it's an activer_user. finally sent the flash message if it's none of before.

public function login(){
        if ($this->request->is('post')) {
            if ($this->Auth->login()) {
                $this->Session->write('logged', 'true');
                $this->Session->write('verified', 'false');
                $this->redirect($this->Auth->redirectUrl());
            }else{
                if($this->Auth->login()){
                    $this->Session->write('logged', 'true');
                    $this->Session->write('verified', 'true');
                    $this->redirect($this->Auth->redirectUrl());
                }else{
                    $this->Session->setFlash('Invalid username or password, try again');
                }
            }
        }
    }

First: thanks for your time and help. 2. I don't even know if this is the right way to do it 3. if this is right what am i doing wrong? 4. I need to use the same login form I hope someone can help me.

Best regards

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
348 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...