Monday, September 21, 2015

Re: if($this->Auth->login($this->request->data)) Return true with right or wrong password and iden

Read the documentation.
You are never supposed to pass anything to login() in this case.

mark


Am Samstag, 19. September 2015 22:11:47 UTC+2 schrieb abdessamad kassasse:
i will show my code
utilisateurcontroller
    public function login()
    {
            debug($this->Session->read());
        if($this->request->is('post'))
        {
            print_r($this->request->data);
            if($this->Auth->login($this->request->data))
            {
                debug($this->Auth->login($this->request->data));
                debug($this->Auth->user());
                    echo "**************************";
                //return $this->redirect($this->Auth->redirectUrl());
            }
else{

        echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
        $this->Session->setFlash(__('Invalid name_U or password'));

    }
}
           
            /*if ($this->Session->read('Auth.Utilisateur')) {
        $this->Session->setFlash('Vous êtes connecté!');
        return $this->redirect('/');
        echo $this->Session->flash('auth');
    }*/

}
    public function logout()
    {
        $this->Auth->logout();
         $this->Session->destroy();
        $this->redirect('/clients/index');
    }
-------------------------------------------------------------------------------------------------------------------------------------
model
<?php
App::uses('AppModel', 'Model');
/**
 * Utilisateur Model
 *
 * @property Group $Group
 */
App::uses('AuthComponent', 'Controller/Component');
class Utilisateur extends AppModel {

/**
 * Display field
 *
 * @var string
 */
    public $displayField = 'id';


    //The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
    public $belongsTo = array(
        'Group' => array(
            'className' => 'Group',
            'foreignKey' => 'group_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );

  
    public $actsAs = array('Acl' => array('type' => 'requester', 'enabled' => false));

    public function parentNode() {
        if (!$this->id && empty($this->data)) {
            return null;
        }
        if (isset($this->data['Utilisateur']['group_id'])) {
            $groupId = $this->data['Utilisateur']['group_id'];
        } else {
            $groupId = $this->field('group_id');
        }
        if (!$groupId) {
            return null;
        }
        return array('Group' => array('id' => $groupId));
    }
        public function beforeSave($options = array()) {
        $this->data['Utilisateur']['password'] = AuthComponent::password($this->data['Utilisateur']['password']);
        return true;
    }
    public function bindNode($utilisateur) {

    return array('model' => 'Group', 'foreign_key' => $utilisateur['Utilisateur']['group_id']);
}

}
---------------------------------------------------------------------------------------------
app controller
<?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 */

App::uses('Controller', 'Controller');

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package        app.Controller
 * @link        http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
 */
class AppController extends Controller {
    public $helpers =array('Html','Form','Session');

    public $components = array('Session','Acl',
        'Auth' => array(
            'authorize' => array(
                'Actions' => array('actionPath' => 'controllers',
                  'userModel' => 'Utilisateur'),
                'authenticate'=>array('Form'=>array('fields'=>array('username'=>'name_U','password'=>'password')))
            
            )

          
       )
         
               
         );

     public function beforeFilter() {
     $this->Auth->allow('display');
         $this->Auth->userModel = 'Utilisateur';
       

   $this->Auth->loginAction = array(
          'controller' => 'Utilisateurs',
          'action' => 'login'
        );
        $this->Auth->logoutRedirect = array(
          'controller' => 'Utilisateurs',
          'action' => 'login'
        );
      /*  $this->Auth->loginRedirect = array(
          'controller' => 'Utilisateurs',
          'action' => 'add'
        );*/
        $this->Auth->fields = array(
            'username' => 'name_U',
            'password' => 'password'
        );
    

 }
}
?>
------------------------------------------------------------------------------------------------
login.ctp

<div class="col-md-9 col-sm-9 col-xs-12">
                               
<div style="width: 100%;">
    <div class="x_panel">
 
                                <div class="x_title">
                                    <h2>Login <small></small></h2>
                                 
                                    <div class="clearfix"></div>
                                </div>
   <div class="x_content">
<?php
echo $this->Form->create('Utilisateur',array('class'=>'form-horizontal form-label-left'));
?>
<div class="form-group">
<?php
echo $this->Form->input("name_U",array('div'=>'col-md-6 col-sm-6 col-xs-12','label'=>array('text'=>'Name','class'=>'control-label col-md-1 col-sm-1 col-xs-12'),'class'=>'form-control col-md-7 col-xs-12'));
?>
</div>
<div class="form-group">
<?php
echo $this->Form->input("password",array('div'=>'col-md-6 col-sm-6 col-xs-12','label'=>array('text'=>'Password','class'=>'control-label col-md-1 col-sm-1 col-xs-12'),'class'=>'form-control col-md-7 col-xs-12'));
?>
</div>
      <div class="ln_solid"></div>
    <div class="form-group">
   <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
      
<?php echo $this->Form->submit(__('Submit'),array('class' =>'btn btn-success')); ?>
</div>
</div>
</div>
</div>
</div>
</div>
*---------------------------------------------------------------------------------------------------------------------------------------------------------------
i need your help





--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: