cakephp - Authentication not works when users are stored in alternative table -
i have problems development of cakephp2's authentication system, users stored in database table participants
(not users
, usual).
it not authenticate participant.
table participants
have next structure:
create table if not exists `participants` ( `id` int(11) not null auto_increment, `confirmed` tinyint(1) not null default '0', `name` varchar(255) collate utf8_unicode_ci default null, `password` char(40) collate utf8_unicode_ci default null, `token` char(32) collate utf8_unicode_ci default null, primary key (`id`) )
file appcontroller.php have content this:
app::uses('controller', 'controller'); class appcontroller extends controller { public $components = array('cookie', 'session', 'auth'); function beforefilter() { $this->auth->usermodel = 'participant'; $this->auth->fields = array('username' => 'name', 'password' => 'password'); $this->auth->loginaction = array('controller' => 'participants', 'action' => 'login'); //$this->auth->logoutredirect = array('controller' => 'participants', 'action' => 'logout'); // use later //$this->auth->loginredirect = array('controller' => 'participants', 'action' => 'index'); } }
file participantscontroller.php have content like:
app::uses('appcontroller', 'controller'); class participantscontroller extends appcontroller { function beforefilter() { parent::beforefilter(); $this->auth->allowedactions = array('registration', 'login', 'forgotten', 'recreate', 'confirm'); } function login() { if ($this->auth->login()) { $this->redirect(array('controller' => 'participants', 'action'=>'view')); } else { // end-up here //pr($this->data); //pr(authcomponent::password($this->data['participant']['password'])); //exit; $this->session->setflash( __('error, please try again.', true) ); } }
i don't know wrong here, can please me i'm missing here?
i think might configuration of fields , usermodel
$this->auth->fields
my working code closer :
$this->auth->authenticate = array( 'form' => array('usermodel' => 'participant' , 'fields' => array('username' => 'name', 'password' => 'password') ) );
Comments
Post a Comment