cakephp auth组件无法正常工作

时间:2014-12-09 10:24:38

标签: cakephp authentication login

class UsersController extends AppController {

    var $uses = array('User', 'Feed', 'Author', 'Comment', 'Tag', 'SingleArticle', 'Category');
    var $helpers = array('Html', 'Form');

    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow('signup');
    }

    public $components = array('Session', 'RequestHandler',
        'Auth' => array(

            'logoutRedirect' => array('controller' => 'users', 'action' => 'index'),
            'authError' => "you can't access that page",
            'authenticate' => array(

                'Form' => array(// THIS IS WHERE YOU CHANGE THE DEFAULT FIELDS
                    'fields' => array('email' => 'email', 'pwd' => 'pwd'),
                      'passwordHasher' => 'Blowfish'
                )
            )
        )
    );

    public function isAuthorized($user) {
        return true;
    }  
 public function login() {
        if ($this->request->is('post')) {
            if ($this->Auth->login()) {
                $this->redirect(array('controller'=>'users','action'=>'mind'));
            } else {
                $this->Session->setFlash('login failed');
            }
}
    }

    public function logout() {
        $this->redirect($this->Auth->logout());
    }
}
this is my userscontroller.php.    

my appcontroller.php 
  public $components = array('Auth', 'RequestHandler');
    public $pageTitle;

    public function beforeFilter() {
        $this->Auth->allow('index');
        parent::beforeFilter();
    }
my user.php 

<?php

App::uses('AppModel', 'Model');
App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');

class User extends AppModel {

    public $name = 'User';
    var $useTable = 'fvf_users';

    public function beforeSave($options = array()) {
        if (isset($this->data['User']['pwd'])) {
            $passwordHasher = new BlowfishPasswordHasher();
            $this->data['User']['pwd'] = $passwordHasher->hash(
                    $this->data['User']['pwd']
            );
        }
        return true;
    }

}

请帮助我,我的登录页面没有工作。它将仅重定向到同一个登录页面。 我用了河豚方法的密码。请帮帮我。谢谢。 哪个部分在我的代码中是错误的。在cakephp中,默认的密码加密方法是什么。

Cakephp LOGIN无效...... :(

1 个答案:

答案 0 :(得分:0)

配置中的fields数组不正确。假设您的数据库字段为emailpwd。该数组必须为'fields' => array('username' => 'email', 'password' => 'pwd')。您的登录表单字段名称也是emailpwd