cakephp:$ this-> Auth-> user()登录不在生产服务器上工作?

时间:2012-01-30 06:49:03

标签: cakephp login components authentication production-environment

我在生产服务器上遇到Auth组件问题。当我输入用户名和密码并单击登录时,除密码文本框清除之外没有任何反应。我正在'我正在登录失败'。我根本不知道它为什么不进入'if($ this-> Auth-> user())'。

早在我的开发服务器上,这个Auth组件工作得很好。我能够登录用户,一旦用户登录,将显示他/她孩子的报告卡pdf文件。

有谁可以指出我犯的是什么错误?谢谢。

merry_parents_controller.php

class MerryParentsController extends AppController{

var $name='MerryParents';
function beforeFilter(){
    parent::beforeFilter();
    $this->Auth->autoRedirect=false;
                        //$this->redirect($this->Auth->redirect());
}

function login(){
    echo "i'm in login";
    if ($this->Auth->user()){
        debug($this->Auth->user());
        $this->data=$this->Auth->user();
        if (!empty($this->data)){

                    $student_info=$this->MerryParent->Student->getStudents($this->data['MerryParent']['id']);
                    $this->set('student_info',$student_info);
                    print_r($student_info); 
                    $this->redirect(array('controller'=>'aptitudes','action'=>'viewpdf',$student_info['Student']['id']));
                    //$this->render('/aptitudes/viewpdf');  
            }
        else{
            echo 'Auth user has not been set';
            }

    }
    else
        echo "Failure";

}
}

login.ctp

<?php
//var_dump($this->data);
$this->Session->flash('auth');
echo $this->Form->create('MerryParent',array('action'=>'login'));
echo $this->Form->input('MerryParent.username',array('label'=>'Name'));
echo $this->Form->input('MerryParent.password', array('value'=>''));
echo $this->Form->end('Login');
?>

app_controller.php

class AppController extends Controller {
var $components=array('Auth','Session','Cookie','Email','Security','RequestHandler','Cookie');
var $helpers = array('Html','Form','Ajax','Javascript','Session');

function beforeFilter(){
  if (isset($this->Auth)){
        $this->Auth->userModel='MerryParent';
        $this->Auth->loginAction=array('controller'=>'merry_parents','action'=>'login');
                    /*var_dump($this->data);
                    debug($this->Auth->user);*/
        $this->Auth->allow('*');
        $this->Auth->loginRedirect=array('controller'=>'aptitudes','action'=>'viewpdf');
        $this->Auth->logoutRedirect=array('controller'=>'merry_parents','action'=>'register');
        $this->Auth->authorize='controller';
      }
   else
        $this->Session->setFlash('Auth has not been set');  

}

function isAuthorized(){
    return true;
}

4 个答案:

答案 0 :(得分:2)

试试这个:

<?php
//var_dump($this->data);
$this->Session->flash('auth');
echo $this->Form->create('MerryParent',array('action'=>'login'));
echo $this->Form->input('username',array('label'=>'Name'));
echo $this->Form->input('password', array('value'=>''));
echo $this->Form->end('Login');
?>

尝试此登录功能:

function login(){
    echo "i'm in login";
    if (!empty($this->data)){
        if($this->Auth->login($this->data)) {
            debug($this->Auth->user());
            $this->data=$this->Auth->user();
            if (!empty($this->data)){
                $student_info=$this->MerryParent->Student->getStudents($this->data['MerryParent']['id']);
                $this->set('student_info',$student_info);
                print_r($student_info); 
                $this->redirect(array('controller'=>'aptitudes','action'=>'viewpdf',$student_info['Student']['id']));
                //$this->render('/aptitudes/viewpdf');  
            } else {
                echo 'Auth user has not been set';
            }
        }
    } else echo "Failure";
}

答案 1 :(得分:1)

有2个问题。按照CodeParadox的答案修改登录功能后,在我修改core.php的Security.salt和Security.cipherSeed之前,它仍然没有工作。我只是从我的开发服务器的core.php复制了salt和cipherSeed的值,它工作正常! :)

谢谢。

答案 2 :(得分:1)

删除控制器最后一行或其他使用php文件中的额外空间,如“config”,“components”和“helpers”

&lt;?php?&gt;&lt;删除空格&gt;

答案 3 :(得分:0)

您的Author.authorize控制器应该是大写字母大小写,如下所示:

$this->Auth->authorize='Controller';