0
votes

I'm getting Error: Call to undefined function login() when i debug($this->Auth-login());

when i click login in my members login it goes to "user/login" page I once had UserController but now i deleted it.

Member model:

    App::uses( 'AppModel' , 'Model' );
App::uses('SimplePasswordHasher','Controller/Component/Auth');
class Member extends AppModel {

public function beforeSave( $options = array() ) {
if( isset( $this->data[$this->alias]['password'] ) ) {
$passwordhasher = new SimplePasswordHasher();
$this->data[$this->alias]['password'] = $passwordhasher->hash( $this->data[$this->alias]['password'] );
}
return true;
}
}

MembersController:

public function login() {
if( $this->request->is('post') ) {
debug($this->Auth-login());

if( $this->Auth->login() ) {
return $this->redirect( $this->Auth->redirect() );
}
$this->Session->setFlash( __( 'Invalid username/password' ) );
}
}

login.ctp

<div class="users form">
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('Member'); ?>
<fieldset>
<legend>
<?php echo __('Please enter your username and password'); ?>
</legend>
<?php
echo $this->Form->input('username');
echo $this->Form->input('password');
?>
</fieldset>
<?php echo $this->Form->end(__('Login')); ?>
</div>

Here is my AppController:

public $components = array(
'Session',

'Auth' => array( 
'loginRedirect' => array(
'controller' => 'members',
'action' => 'profile'
),
'logoutRedirect' => array(
'controller' => 'members',
'action' => 'index'
)
),

'DebugKit.Toolbar'

);

I want to redirect to members/profile page after members/login

1
Form->create('Member') You cannot use the namespace "Member" when the Auth component still expects the default "User" etc. You need either stick to "User" or make all involved components aware of the changed Model name. - mark

1 Answers

0
votes

As you are trying to use Member model rather then default User model, you should let Cakephp know about that like-

public $components = array(
                        'Session',
                        'Auth' => array(    
                            'loginRedirect' => array(
                                'controller' => 'members',
                                'action' => 'profile'
                            ),
                            'logoutRedirect' => array(
                                'controller' => 'members',
                                'action' => 'index'
                            ),
                            'authenticate' => array(
                                'Form' => array(
                                    'userModel' => 'Member'
                                )
                            )
                        ),
                'DebugKit.Toolbar'
);