CakePHP的登录页面不会去任何地方 [英] cakephp login page doesn't go anywhere

查看:188
本文介绍了CakePHP的登录页面不会去任何地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个登录页面,但是当我尝试登录,即使有错误的用户名/密码,蛋糕重定向到登录页面(注销功能正确重定向)。即使我插上了错误的信息,我没有得到任何错误闪烁可言,我不明白这一点。这里是我的控制器code:

I have tried to set up a login page, but when I try to log in, even with a wrong username/password, cake redirects to the login page (the logout function redirects correctly). Even if I plug in the wrong info, I get no error flashes at all, I don't get it. Here is my controller code:

class UsersController extends AppController {
public $name='Users';
public $layout='pagelayout';
public $uses=array('User');



public function beforeFilter() {
    parent::beforeFilter();
    $this->Auth->allow('add', 'logout', 'overview');
}

public function login() {
$this->set('title', 'Log in to your Gulf Shores 4 Less account');
if ($this->request->is('post')) {
    if ($this->Auth->login()) {
        return $this->redirect($this->Auth->redirect());
    } else {
        $this->Session->setFlash(__('Username or password is incorrect'), 'default', array(), 'auth');
    }
}

}

和这里是我的模型:

<?php
App::uses('AuthComponent', 'Controller/Component');
class User extends AppModel {
public $name='User';
public $hasMany=array('Unit', 'Complex', 'Coupon', 'Location', 'Image', 'Charter', 'Course', 'Nightclub', 'Store');

public function beforeSave() {
if (isset($this->data[$this->alias]['password'])) {
    $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}
public $validate = array(
    'username' => array(
        'required' => array(
            'rule' => array('notEmpty'),
            'message' => 'A username is required'
        )
    ),
    'password' => array(
        'required' => array(
            'rule' => array('notEmpty'),
            'message' => 'A password is required'
        )
    ),
    'role' => array(
        'valid' => array(
            'rule' => array('inList', array('admin', 'advertiser')),
            'message' => 'Please enter a valid role',
            'allowEmpty' => false
        )
    )
  );
}

?>

下面是从AppController中的code:

Here is the code from AppController:

<?php
class AppController extends Controller {
 public $components = array(
    'Session',
    'Auth' => array(
        'loginRedirect' => array('controller' => 'users', 'action' => 'overview'),
        'logoutRedirect' => array('controller' => 'pages', 'action' => 'index')
    )
);


function beforeFilter() {
    $this->Auth->allow('login','index', 'view', 'condos', 'houses', 'hotels_and_motels', 'print_all_coupons', 'print_coupon', 'search', 'golf', 'charters', 'events', 'nightlife', 'shopping', 'visitors_info', 'contact_us');
}
}
?>

和这里的景色code:

and here is the view code:

<div class="users form">
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('User');?>
<fieldset>
    <legend><?php echo __('Please enter your username and password'); ?></legend>
<?php
    echo $this->Form->input('username');
    echo $this->Form->input('password');
?>
</fieldset>
<?php echo $this->Form->end(__('Login'));?>
</div>

正如你所看到的,我pretty多拷贝并粘贴什么是CakePHP的-2.0手动这一点。我的db表和说明书的之间的唯一区别是,我的密码存储在我的用户表中的MD5哈希值。我无法揣摩出这已经出轨。

As you can see, I pretty much copy and pasted what was in the Cakephp-2.0 manual for this. The only difference between my db table and the manual's is that my password is stored as an MD5 hash in my users table. i can't figure out where this has derailed.

推荐答案

请确保您的密码使用验证分量散列存储。据我所知,有一个'纯'MD5密码不支持。蛋糕产生的哈希值比MD5更加复杂。

Make sure that your passwords are stored using the Auth component hash. AFAIK, there is no support for 'plain' md5 passwords. The hashes Cake generates are more complex than md5.

查看<一个href=\"http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#hashing-passwords\"相对=nofollow>有关如何散列密码信息文档。如果你是从使用MD5哈希应用程序迁移,你必须将所有密码的东西随机重置为所有用户。

See the documentation for info on how to hash your passwords. If you are migrating from an app that used md5 hashing, you'll have to reset all the passwords to something random for all your users.

这篇关于CakePHP的登录页面不会去任何地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆