2011-11-30 29 views
0

这是一个相当长的问题,但我知道它出错的地方。我正在使用CakePHP 2.0制作ajax登录脚本,但它仍然失败。我将发布我的所有代码,我希望有人有时间来完成它。很多登录代码

这是我的SQL数据库

AccountID AccountEmail AccountPassword AccountActive 
1 [email protected]  pass   0 
2 [email protected]   pass   1 

这是我的相关标准守则

class Account extends AppModel { 

public $name = 'Account'; 
public $validate = array(
    'AccountEmail' => array(
     'required' => array(
      'rule' => array('notEmpty'), 
      'message' => 'Please Enter A Valid Email.' 
     ), 
     'email' => array(
      'rule' => array('email', true), 
      'message' => 'Please supply a valid email address.' 
     ) 
    ), 
    'AccountPassword' => array(
     'required' => array(
      'rule' => array('notEmpty'), 
      'message' => 'Please Enter A Valid Password.' 
     ) 
    ) 
); 
} 

这是我的相关控制器代码

class AppController extends Controller { 

/** 
* Class Variables 
*/ 
public $helpers = array('Js', 'Html', 'Session', 'Form'); 
public $components = array(
    'Session', 
    'RequestHandler', 
    'Auth' => array(
     'logoutRedirect' => array(
      'controller' => 'Accounts', 
      'action' => 'login' 
     ), 
     'authError' => 'You can\'t Access That Page', 
     'authorize' => array('Controller'), 
     'authenticate' => array(
      'Form' => array(
       'fields' => array(
        'username' => 'AccountEmail', 
        'password' => 'AccountPassword' 
       ), 
       'scope' => array('AccountActive' => '1') 
      ) 
     ) 
    ) 
); 
} 

class AccountsController extends AppController { 

/** 
* Class Variables 
*/ 
public $name = 'Accounts'; 
public $layout = 'Accounts'; 

/** 
* Class Functions 
*/ 
public function login() 
{ 
    if ($this->request->is('ajax')) { 
     $this->Account->set($this->data); 
     if ($this->Account->validates()) { 
      if($this->Auth->login()) { 
       echo "logged In"; 
       exit; 
      } else { 
       echo "Login Failed"; 
       exit; 
      } 
     } else { 
      echo 'validation/' . json_encode($this->Account->invalidFields()); 
      exit; 
     } 
    } 
} 

我不认为还有别的。我再次为大量的代码感到抱歉,但我只是不知道你需要什么。
这些信息全部通过'echo'传递给jquery,目前只是通过'alert'显示响应。
我知道验证正在工作,但是如果我输入应该能够登录的人的信息,只显示“登录失败”。谢谢你的时间。

回答

0

您在数据库中的密码需要以散列形式存在。使用Cake的默认设置'pass'将是:1c31af5bd9913ff511fe780f506e6fab68979b90