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