views:

790

answers:

1

CakePHP's AuthController assumes you have a Users table that contains a username and password. I'd like to find a way to override the default tablename from Users to Accounts.

Background Information:

The way I have designed my database is to have a Users table and an Accounts table.

Accounts :

  • id

  • user_id

  • username

  • password

  • authentication service (e.g. my site, facebook, google, openid, etc)

Users:

  • simply has all the personal info of the user (age, gender, etc)

The reason for this is so that (a) each user can have multiple accounts they can login from so they are not locked into one (b) I can connect the 3rd party services to an account for more awesomeness

Now back to the problem....

CakePHP has documentation on changing the default field name, but I can't find anything on changing the default table name, but assume it would be similar in nature...

Example of changing the default field name:

function beforeFilter() {
     $this->Auth->fields = array(
        'username' => 'username', 
        'password' => 'secretword'
        );
 }

Is there a way to accomplish this or should I restructure the tables keeping with CakePHP convention and still accomplish the same thing?

+6  A: 

In app_controller.php:

function beforeFilter() {
    $this->Auth->userModel = 'Account';
}