Auth($ this-> auth-> login())在cakephp 2.5.6中返回false

时间:2014-12-11 12:26:53

标签: cakephp authentication cakephp-2.5

$ this-> auth-> login()始终返回false。

我必须使用PintiplanAutore模型

在我的视图中

正确显示sql查询

选择PintiplanAutoreidautorPintiplanAutoreidfacebookPintiplanAutorenombrePintiplanAutore。{{1} },correoPintiplanAutorepasswordPintiplanAutoretokenPintiplanAutoreimagenPintiplanAutore FROM rolpintiplan AS pintiplan_autores WHERE PintiplanAutorePintiplanAutore =' aa@aa.com'限制1

correo

appController.php

<?php 
    echo $this->Form->create('PintiplanAutore',array('action'=>'login'));
    echo $this->Form->input('correo');
    echo $this->Form->input('password');
    echo $this->Form->end('Login');

?>
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->element('sql_dump'); ?>

}

PintiplanAutoresController.php

<?php App::uses('Controller', 'Controller');
class AppController extends Controller {
public $components=array(
'Session',
'Auth' => array(


        'authenticate'=>array(
            'Form'=>array(
                'userModel'=>'PintiplanAutore',
                'fields' => array(
                    'username' => 'correo',
                    'passwordHasher' => 'Blowfish'
                    )
                )
            )

        )
);


public function beforeFilter(){
    $this->Auth->allow('index','verSitio','sitiosPublicos','verSitiosPlan','planesPublicos');
    $this->Auth->loginAction = array('controller' => 'PintiplanAutores','action'=>'login');
    $this->Auth->loginRedirect = array('controller' => 'Nosotros', 'action' => 'index');
}

Model PintiplanAutore:

<?php
   App::uses('AppController', 'Controller');
   class PintiplanAutoresController extends AppController {
      public $components = array('Paginator', 'Session');
      public function beforeFilter() {
        parent::beforeFilter();
        // Allow users to register and logout.
        $this->Auth->allow('add','logout','login');
    }

public function add() {
    if ($this->request->is('post')) {
        $this->PintiplanAutore->create();
        if ($this->PintiplanAutore->save($this->request->data)) {
            $this->Session->setFlash(__('The pintiplan autore has been saved.'));
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The pintiplan autore could not be saved. Please, try again.'));
        }
    }
}
public function login(){

        if ($this->request->is('post')){
            //echo debug($this->request->data['PintiplanAutore']['password']);
            debug($this->Auth->login()); die();


        if ($this->Auth->login()) {
            return $this->redirect(array('controller' => 'Nosotros', 'action' => 'index'));
            //return $this->redirect($this->Auth->redirectUrl());
        }

        $this->Session->setFlash(__('Invalid username or password, try again'));

        }
    }
 ?>

为我的用户添加操作添加

我希望有人可以帮助我

2 个答案:

答案 0 :(得分:1)

尝试用它

$user=$this->PintiplanAutore->findByCorreoAndPassword($yourCorreo_field_getting_from_form);

if($this->Auth->login($user)){

}

答案 1 :(得分:0)

这对我有用而无需查询:

if($this->Auth->login($this->request->data)) { ... }
相关问题