0

据我所知,使用用户名和密码创建用户(在我的情况下为人)工作正常。当我查看 db 表时,密码被散列并且用户名被保存。出现以下问题的天气我是否对密码进行了哈希处理,所以我认为问题出在 AppController 或 PeopleController

应用控制器

class AppController extends Controller {
    public $components = array(
        'DebugKit.Toolbar',
        'Session',
        'Auth'=>array(
            'loginAction'=>array(
                'controller'=> 'people',
                'action'=> 'login'),
            'loginRedirect'=>array(
                'controller'=>'people', 'action'=>'index'),
            'logoutRedirect'=>array(
                'controller'=>'people', 'action'=>'index'),
            'authError'=>"You can't access that page",
            'authorize'=>array('Controller')
            )
        );

    public function isAuthorized($people)
    {
        return true;
    }

    public function beforeFilter()
    {
        $this->Auth->allow('index','view');
    }
}

和人员控制器

class PeopleController extends AppController
    {

        public $helpers = array('Html', 'form', 'Js');
        public $components = array('RequestHandler');


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

        public function login()
        {
            if ($this->request->is('post')) {
                if ($this->Auth->login()) {
                    return $this->redirect($this->Auth->redirectURL());
                }
                else {
                    $this->Session->setFlash('Your username/password combination was incorrect');
                }
            }
        }

        public function logout()
        {
            $this->redirect($this->Auth->logout());
        }

         public function index() {


            }

当我尝试登录时,即使我确定我输入了正确的详细信息,我仍然不断收到用户名和密码不匹配的闪烁消息,感谢任何有关如何解决此问题的想法

登录.ctp

<h2>Login</h2>
<?php

echo $this->Form->create();
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end('Login');

?>
4

1 回答 1

1
'Auth' => array(
                'loginAction' => array('controller'=>'Admin', 'action'=>'login'),
                'loginRedirect' => array('contoller'=>'Admin', 'action'=>'login'),
                'logoutRedirect' => array('controller'=>'Admin', 'action'=>'logout'),
                'authError' => '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">&times;</button>
                                    You are not authorized to access this location</div>',
                'authenticate' => array(
                    'Form' => array(
                        'userModel' => 'User',
                        'fields' => array(
                            'username' => 'email',
                            'password'=>'password')
                    )
                )
            )

试试这个。

于 2013-10-16T12:37:50.520 回答