CakePHP: Can't login when using Members Controller instead of Users Controller -


i have strange issue cannot figure out anymore. setup cakephp project , using users controller handle authentication , working perfectly, 100%. however, decided drop users controller, model , views , replace members 1 because members primary users 1 or 2 admin's need login.

what have in members model, controllers , views identical had in users default cakephp wants use users model , users table. did lot of debugging , got cakephp use members instead of users cannot login keep getting your username , password incorrect, please try again error message.

here's have way of code, i'm hoping can point me in right direction.

appcontroller.php

function beforefilter() {     $this->auth->usermodel = 'member';     $this->auth->authorize = array('member');     $this->auth->allow(array('view', 'index', 'add', 'edit', 'delete')); }  public $helpers = array ('html', 'form', 'session', 'time');   public $components = array(     'debugkit.toolbar',     'session',     'cookie',     'auth' => array(         'loginaction' => array(             'controller' => 'members',             'action' => 'login'         ),         'autherror' => 'your username , password incorrect, please try again.',         'authenticate' => array(             'form' => array(                 'fields' => array('username' => 'username', 'password' => 'password',                 'scope' => array('member.deleted' => '0')),                 'passwordhasher' => 'blowfish'             )         )     ) ); 

what's important note beforefilter() i've tried plural , singular of member , added $this-auth->allow() function edit user's password in members table make sure password being hashed correctly.

as note, everywhere have seen when using loginaction should this:

'loginaction' => array(     'controller' => 'members',     'action' => 'login',     'plugin' => 'members' ), 

the problem using above url structure ends looking /members/members/login hence have omitted plugin key-value pair in appcontroller i'm guessing error lies.

member.php

public function isauthorized($user) {     if (!empty($this->request->params['admin'])) {             return $user['role'] === 'admin';     }     return !empty($user); }  public function beforesave($options = array()) {     if (isset($this->data['member']['password'])) {         $this->data['member']['password'] = authcomponent::password($this->data['member']['password']);     }     return true; } 

memberscontroller.php

public function login() { if ($this->request->is('post')) {     if ($this->auth->login()){         return $this->redirect($this->auth->redirecturl());         } else {             $this->session->setflash(__('your username , password incorrect, please try again.'));         } // end if cannot log in     } // end if no form submitted } // end login  public function logout() {     $this->session->destroy();     $this->redirect($this->auth->logout()); } 

/members/login.ctp

<div id="page-content" class="span9">     <div class="users form">         <?php echo $this->form->create('member', array('inputdefaults' => array('label' => false), 'class' => 'form form-horizontal')); ?>             <fieldset>                 <h2><?php echo __('member login'); ?></h2>                 <div class="control-group">                     <?php echo $this->form->label('username', 'username', array('class' => 'control-label'));?>                     <div class="controls">                         <?php echo $this->form->input('username', array('class' => 'span12')); ?>                     </div><!-- .controls -->                 </div><!-- .control-group -->                 <div class="control-group">                     <?php echo $this->form->label('password', 'password', array('class' => 'control-label'));?>                     <div class="controls">                         <?php echo $this->form->input('password', array('class' => 'span12')); ?>                     </div><!-- .controls -->                 </div><!-- .control-group -->                 <?php echo $this->form->input('auto_login', array('type' => 'checkbox', 'label' => 'remember me?')); ?>             </fieldset>         <?php echo $this->form->submit('submit', array('class' => 'btn btn-large btn-primary')); ?>         <?php echo $this->form->end(); ?>     </div>   </div> 

as say, amazing i've gone through know try , work...

foreach type of group want login (eg. administrator, user or other type) have write next things in controller , models:

lets have 2 types of users different platform access, administrators , users

in controller/appcontroller.php

public $components = array(         'acl',         'auth' => array(             'authorize' => array(                 'actions' => array('actionpath' => 'controllers/')             )         ),         'session'); 

in model/administrator.php

 public function beforesave() {         if (isset($this->data['administrator']['password'])):             $this->data['administrator']['password'] = authcomponent::password($this->data['administrator']['password']);             return true;         endif;     }   public $actsas = array('acl' => array('type' => 'requester'));   public function parentnode() {     if (!$this->id && empty($this->data)) {         return null;     }     if (isset($this->data['administrator']['group_id'])) {         $groupid = $this->data['administrator']['group_id'];     } else {         $groupid = $this->field('group_id');     }     if (!$groupid) {         return null;     } else {         return array('group' => array('id' => $groupid));     } } 

in controller/administratorscontroller.php beforefilter()

$this->auth->authorize = array('actions' => array('actionpath' => 'controllers/', 'usermodel' => 'administrator')); $this->auth->authenticate = array('form' => array('usermodel' => 'administrator'));  $this->auth->loginaction = array(/*your path here*/); $this->auth->logoutredirect = array(/*your path here*/); $this->auth->loginredirect = array(/*your path here*/); 

if have groups should work great!
have 3 types of groups: administrators, shops , users , works me!


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -