volf
volf

Reputation: 819

Zend_Auth_Adapter_DbTable identity not unique

For authentication on a website i use Zend_Auth_Adapter_DbTable. Everything work's fine, but Zend Framework only allow unique Identitys in the table.

As an identity i use the mail-address from my users. The problem is, that there are more items in the table with this mail-adress. User can delete there account and so i don't delete the whole row, i only change the status to -2 or something else. active user has the status 1.

i try to use it like so:

    $authAdapter = new Zend_Auth_Adapter_DbTable($db, 'user', 'email', 'password', "? AND `status`='1'");
    $authAdapter->setIdentity($email);
    $authAdapter->setCredential($password);

But it doesn't work. If i delete the inactive user with the same mail-address, everything work's. Why is that?

Upvotes: 3

Views: 864

Answers (1)

Venu
Venu

Reputation: 7279

You can do like this

$authAdapter->setIdentity($email);
$authAdapter->setCredential($password);

$select = $authAdapter->getDbSelect();
$select->where('status = 1'); 

Try this full code

 $authAdapter = new Zend_Auth_Adapter_DbTable($db, 'user', 'email', 'password');
     $authAdapter->setIdentity($email);
    $authAdapter->setCredential($password);
    $select = $authAdapter->getDbSelect();
            $select->where('status = "1"');

OR

$authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());

       $authAdapter->setTableName('user')
            ->setIdentityColumn('email')
            ->setCredentialColumn('password');     

        $select = $authAdapter->getDbSelect();
        $select->where('status = "1"');

[EDIT]
OR

$authAdapter = new Zend_Auth_Adapter_DbTable($db, 'user', 'email', 'password');
         $authAdapter->setIdentity($email);
        $authAdapter->setCredential($password);
$authAdapter->setCredentialTreatment('? and status = "1"');

FYI: zend.auth.adapter.dbtable

Upvotes: 2

Related Questions