2.4.2中的登录脚本不工作 [英] Login Script in 2.4.2 is not working

查看:102
本文介绍了2.4.2中的登录脚本不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是cakephp的新人。我有一个problom,而登录。使用错误的名称和密码重定向到登录主页。

I am new to cakephp. I have a problom while login. With wrong name and password redirects to login home page.

public function login() {
    $this->layout = 'admin-login';
    if ($this->request->is('post')) {
        if ($this->Auth->login($this->request->data)) {
            return $this->redirect($this->Auth->redirectUrl())
        } else {
            $this->Session->setFlash(__('Username or password is incorrect'), 'default', array(), 'auth');
        }
    }
}



AppController.php



AppController.php

 public $components = array(
    'Session',
    'Auth' => array(
        'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
        'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
        'loginAction' => array('controller' => 'users', 'action' => 'login')
    )
);

 public function beforeFilter() {
    $this->Auth->allow("login");
    //$this->Auth->authorize = array('Controller');
    $this->Auth->authenticate = array(
        'Form' => array (
            'scope'  => array(
                'User.is_active' => 1
            ) 
        )
    );   
}
public function isAuthorized($user) {
    return true;
}



login.ctp



login.ctp

echo $this->Form->create('User');
echo $this->Form->input('username');
echo $this->Form->input('password'); 
echo $this->Form->submit(__('Submit');
echo $this->Form->end();

当我填写错误的用户名和密码并点击提交按钮,它会重定向到首页,谢谢。

When i fill the wrong username & password & click on submit button it redirect to home page, Thanks.

推荐答案

您使用 AuthComponent :: login()错误,

如果您要使用组件认证功能,只需调用 $ this - > Auth-> login()

If you want to use the components authentication functionality just call $this->Auth->login()

另请参阅: http://book.cakephp.org/2.0/en/core-libraries/ components / authentication.html#identifying-users-and-logging-them-in


在2.x $ this-> Auth-> login($ this-> request-> data)将记录用户的任何数据,而在1.3 $ this-> Auth-> login($ this-> data)会尝试首先识别用户,并且只有成功登录。

In 2.x $this->Auth->login($this->request->data) will log the user in with whatever data is posted, whereas in 1.3 $this->Auth->login($this->data) would try to identify the user first and only log in when successful.

这篇关于2.4.2中的登录脚本不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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