0

I have the following tables:

People
Users
Emails

The user's password is stored in the Users table and I want them to use their default email address which is stored in the Emails table to authenticate. The email is indicated as their default by a boolean column in the Emails table.

How do I use CakePHP's Authentication component in this setup?

freshest
  • 6,229
  • 9
  • 35
  • 38

3 Answers3

1

I think you shoulnd't split the info in separate tables. Put everything in your Users table, and then make one-to-one relationships.

Anyway, if you want to do it this way you should override the login() method in the UsersController.

Here you have an example: http://bakery.cakephp.org/articles/SeanCallan/2007/04/17/simple-form-authentication-in-1-2-x-x

This is the method you need to override:

http://api13.cakephp.org/class/auth-component#method-AuthComponentlogin

EDIT:

Make your auth data depends on Users only. I mean, put email, username (if you have one), and password there. After that, if you have, for example, People table to record other info (first name, addres, phone, etc), make an one-to-one relationship with that table. If you have your Customer table, and your customer can be users, make a one-to-one relationship.

I ran into this troubles some time ago, and was useful to solve it as Django do, and is with this one-to-one solution.

santiagobasulto
  • 11,320
  • 11
  • 64
  • 88
0

This answer should be enough evidence that you will not be able to use multiple models for your Auth component. It only supports a string, not an array. But if you keep reading, there might be a work around for you.

Community
  • 1
  • 1
Tim Joyce
  • 4,487
  • 5
  • 34
  • 50
0

Create a /app/Controller/Component/Auth/MyFormAuthenticate.php file, and setup Auth to use MyForm instead of Form for authentication.

In this file include the authenticate function and the _findUser function.

You then need to override the _findUser function to suit your needs.

Thanks to Ceeram on the CakePHP freenode channel for this solution.

freshest
  • 6,229
  • 9
  • 35
  • 38