我試圖創建一個簡單的登錄頁面。我希望在該頁面上進行驗證,這樣當用戶單擊登錄時,站點會檢查激活的用戶數據庫中是否設置爲1,如果不是,則無法登錄。我對cakephp仍然很陌生,並且正在努力快速提取,所以我很抱歉如果這是一個簡單的初學者問題。CakePHP 2.0帳戶驗證
這裏是我的用戶模型
public $checkActive = array(
'activated'=>array(
'rule'=>array('equalTo', '0'),
'message'=>'The account must be activated, please check your email.'
));
這裏的驗證是在我usersController登錄功能
public function login() {
$this->set('title_for_layout', 'Individual Registration');
$this->set('stylesheet_used', 'style');
$this->set('image_used', 'eBOXLogo.jpg');
if ($this->request->is('post')){
if ($this->request->data['User']['password'] == 'qazwsx'){
if ($this->Auth->login()){
if (0 === $this->User->find('count',array('conditions'=>array('enabled'=>1,'login'=> $username)))) {
$this->Session->setFlash('Sorry, your account is not validated yet.');
}
$this->Auth->user('id');
$this->redirect($this->Auth->redirect('eboxs/home'));
}
}
else {
$this->Session->setFlash('Username or password is incorrect');
}
}else{
$this->Session->setFlash('Welcome, please login');
}
}
這裏是在usersController
public function beforeLogin(){
if(isset($this->data['User']['password'])){
$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
}
return true;
}
App我beforeLogin功能控制器
class AppController extends Controller {
public $components = array(
'DebugKit.Toolbar',
'Session',
'Auth'=>array(
'loginRedirect'=>array('controller'=>'users', 'action'=>'login'),
'logoutRedirect'=>array('controller'=>'users', 'action'=>'login'),
'authError'=>"You can't access this page",
'authorize'=>array('Controller')
)
);
public function isAuthorized($user){
return true;
}
public function beforeFilter(){
$this->Auth->allow('index','view');
$this->set('logged_in', $this->Auth->loggedIn());
$this->set('current_user',$this->Auth->user());
}
我意識到在我的控制器中沒有調用驗證,但與我的其他驗證,如用戶名是唯一的,我沒有必要調用它。
總之現在任何人都可以登錄到我的頁面,我試圖讓它只有那些在users表中的激活字段中有1的人才能登錄。
你爲什麼手動檢查密碼?請發佈您的Auth組件設置(應該在您的AppController中) – Dunhamzzz
發佈應用程序控制器 – user1393064