lauriys
lauriys

Reputation: 4792

How can I use different model for Auth component in CakePHP 2.0.4?

It looks like trivial thing, but I really can't find where I can change it. I want to use my "Player" model instead of User, but every time I go on /players/login it redirects me to "Missing Controller" page and link changes to /users/login.

I tried:

public $components = array(
    'Session',
    'Auth' => array(
        'authenticate' => array('all' => array('userModel' => 'Player'))
     )
);

and

function beforeFilter() {
    $this->Auth->authenticate = array('all' => array('userModel' => 'Player'));
}

EDIT: SOLVED

'loginAction' => array('controller' => 'players', 'action' => 'login')

in $components array helped, I think :D

Upvotes: 2

Views: 6172

Answers (3)

Sujay
Sujay

Reputation: 11

Use this code within controller :

public $components = array(
    'Auth' => array(
    'loginRedirect' => array(
        'controller' => 'applications',
        'action' => 'index'
    ),

    'logoutRedirect' => array(
        'controller' => 'applications',
        'action' => 'login'
    ),

    'authenticate' => array(
            'Form' => array(
                'passwordHasher' => 'Blowfish',
                'userModel' => 'Application'
            )
        ),      
    )
);

Do not needed to add any code for beforeFilter() function. $components load the Auth conponent.

Thanks Sujay

Upvotes: 0

Ash
Ash

Reputation: 11

You should do so

public $components=array(
    'Session',
    'Auth'=>array(
        'authenticate'=>array(
            'Form'=>array(
                'userModel'=>'Player',
             )
        ),
        'loginAction'=>array('controller'=>'Players', 'action'=>'login'),

Upvotes: 0

entropid
entropid

Reputation: 6239

I guess the problem is that you aren't providing an authenticating system. You're providing some settings to be used in all the authenticating system that will be chosen, but you haven't chosen one yet (you have to provide at least one like Form, Basic, Digest, ecc..).

$this->Auth->authenticate = array(
    'all' => array('userModel' => 'Member'),
    'Form',
    'Basic'
);

(or the same in the $components array)

Upvotes: 4

Related Questions