CakePHP的验证组件使用$这个 - &GT当登录不可; Auth->登录(); [英] CakePHP Auth Component Not logging in when using $this->Auth->login();

查看:193
本文介绍了CakePHP的验证组件使用$这个 - &GT当登录不可; Auth->登录();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来CakePHP的,我看了他们的文档,我跟随他们简单的身份验证的例子。我还搜查甚广(包括在本网站的答案)的答案,我的问题。

I'm new to cakePHP and I have read their documentation and I'm following their simple authentication example. I've also searched far and wide (including answers on this site) for an answer to my problem.

我使用CakePHP 2.0和我UsersController的登录功能是这样的:

I'm using cakePHP 2.0 and my UsersController's login function looks like this:

function login() {
    if ($this->request->is('post')) {
        if ($this->Auth->login(/*$this->request->data*/)) {
            $this->redirect($this->Auth->redirect());
        }else {
            $this->Session->setFlash(__('Invalid username or password, try again'));
        }
    }
}

我AppController的是这样的:

My AppController looks like this:

public $components = array(
                    'Session',
                    'Auth' => array(
                            'loginRedirect' => array('controller' => 'pages', 'action' => 'display'),
                            'logoutRedirect' => array('controller' => 'pages', 'action' => 'display')
                    )
        );

public function beforeFilter() {
    $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
}

我的用户模型:

class User extends AppModel {

public $name = "User";

}

和登录表单:

echo $this->Session->flash('auth');
echo $this->Form->create('User', array('action' => 'login'));
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end('Login');

问题是,它没有登录的用户。当$这个 - > Auth->登录()被调用,而不$这个 - >请求 - 作为一个参数没有被写在会议上,只是网页>数据refreshes.However当您​​提供它的工作原理$这个 - >请求 - >数据,凭据被写入了会议,我正确地重定向。不过我注意到,你可以'登录'人与$这个 - > Auth->登录($这个 - >请求 - >数据),即使它们不是在数据库present。除此之外,如果我输错的凭据没有任何反应,则不会显示任何提示信息。

The problem is it doesn't log a user in. When $this->Auth->login() is called without $this->request->data as a parameter nothing is written in the session and the page just refreshes.However when you supply the $this->request->data it works, credentials are written to the session and I'm redirected correctly. However I've noticed that you can 'log in' anyone with $this->Auth->login($this->request->data) even if they are not present in the database. In addition to this, if I enter wrong credentials nothing happens, no flash messages are displayed.

我不想做任何特别的,我要的是在登录用户的能力。我有一个用户名和密码字段一个简​​单的用户表,我也跟着他们的榜样,阅读他们的文档,但仍没有我曾尝试工作过。

I'm not trying to do anything special, all I want is the ability to log a user in. I have a simple users table with username and password fields and I have followed their example and read their documentation, but still nothing I have tried has worked.

我道歉,如果我没有提供需要提供响应的所有信息。任何帮助是极大的AP preciated。

I apologise if I have not supplied all the information needed to provide a response. Any help is greatly appreciated.

推荐答案

我有相同的经历。发生了什么事我的是,在一个点上,我能够成功登录使用一些用户名和密码,但我从来没有在这给我看,我登陆,我也真的很困惑的任何视图code,当我随后登录随机用户名和密码,但它仍然给了我一个成功的登录通知。

I had the exact same experience. What happened to me was, at one point, I was able to log in successfully using some username and password, but I never had any code in the view that showed me I was logged in. I was also really confused that when I subsequently logged in with random usernames and passwords, it still gave me a successful login notification.

我觉得发生了什么事,如果你是在一个登录的状态,那么 $这个 - > Auth->登录()将返回真正不管你输入什么用户名和密码。该解决方案可能会以某种方式调用 $这个 - > Auth->注销()在你的程序,或清空你的cookies这样程序不指定如被记录在了。然后 $这个 - > Auth-方式>登录()将工作重新恢复正常。

I think what happened was, if you are in a logged-in state, then $this->Auth->login() will return true no matter what username and password you enter. The solution would probably be to somehow call $this->Auth->logout() in your program, or empty your cookies so that the program doesn't specify you as being logged in anymore. Then $this->Auth->login() will work as normal again.

这篇关于CakePHP的验证组件使用$这个 - &GT当登录不可; Auth->登录();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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