1

我在生产服务器上的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; 
} 
+1

事情是真的错了你'login'功能。您正在通过执行$ this-> data = $ this-> Auth-> user()来清除传递给此函数的数据。这只会在你已经登录时才起作用。你应该首先通过将这个 - >数据传递给Auth登录函数来登录... – 2012-01-30 18:08:29

回答

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"; 
} 
+0

我试过你的解决方案,结果和上面一样。什么都没发生。 – vaanipala 2012-01-30 08:37:28

+0

是的,它现在有效。但是有两个问题:1)登录功能中的代码。 2)Security.salt&Security.cipherSeed在core.php中。 – vaanipala 2012-01-31 05:23:58

1

有2个问题。按照CodeParadox的回答修改登录函数后,直到我修改了core.php的Security.salt和Security.cipherSeed后,它仍然无法正常工作。我刚从我的开发服务器的core.php中复制salt和cipherSeed的值,它工作正常! :)

谢谢。

1

在控制器等为“配置”,“组件”和“助手”

<?PHP删除多余的空格最后一行或其他使用PHP文件? > <除去空间>

0

您Author.authorize控制器应该是一个大写字母情况如下图所示:

$this->Auth->authorize='Controller'; 
相关问题