1

I want to check the user table for status=1 as extra validation. My getAuthAdapter() method looks like this:

private function getAuthAdapter (){
    $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
    $authAdapter->setTableName('vi_users')
                ->setIdentityColumn('email')
                ->setCredentialColumn('password');
    return $authAdapter;
}

How would I alter this to include the extra validation?

Owen
  • 7,347
  • 12
  • 54
  • 73

2 Answers2

2

I ran across this problem myself, and I'm not sure it is possible to check another column at the sametime. So I do it straight aftwerwards, with something like this:

$auth = Zend_Auth::getInstance();

....

if (process($form->getValues())) {
    // login credentials are correct, so we now need to check if their account is activated
    if ($auth->getIdentity()->active != 1) {
        // if not, log them out and tell them to activate
        Zend_Auth::getInstance()->clearIdentity();
        $output .= "Your account has not yet been activated, please check your email (including spam bin) for the activation link.";
    } else {
        // if they're active then login is successful
        $output .= "You are now logged in";
    }
} else {
   // username/password wrong
   $output .= "Credentials invalid";
}

Update: Given Orlando's answer, it looks like what you've asked for originally is possible. You could use my solution though if you would like to distinguish between status value being 'wrong' and user/pass being wrong.

ChrisA
  • 2,091
  • 1
  • 14
  • 23
  • I did it this way too, and yes, it's sometimes useful to know if the login succeed anyway. – Owen Aug 24 '11 at 14:02
1

You could do something like:

$adapter = new Zend_Auth_Adapter_DbTable(
    $db,
    'users',
    'username',
    'password',
    'MD5(?) AND status = 1'
);

where $db would be Zend_Db_Table::getDefaultAdapter()

Taken from http://framework.zend.com/manual/en/zend.auth.adapter.dbtable.html

Orlando
  • 368
  • 2
  • 9