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'顯示響應。
我知道驗證正在工作,但是如果我輸入應該能夠登錄的人的信息,只顯示「登錄失敗」。謝謝你的時間。