1
我有一個名爲「userinformations」的表。我想使用emailid和密碼字段作爲我的網站的登錄憑據。 已在相應的文件中添加了以下代碼。但是,當我登錄時,我在同一登錄頁面上顯示一條消息「您無權訪問該位置。」CakePHP Auth組件:無法登錄「您無權訪問該位置。」消息顯示
應用程序/ app_controller.php
類AppController的延伸控制器{
var $components = array('Auth','Session');
function beforeFilter() {
$this->Auth->userModel = 'Userinformation';
Security::setHash("md5");
$this->Auth->fields = array('username' => 'emailid', 'password' => 'password');
$this->Auth->loginAction = array('controller' => 'Userinformations', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'Userinformations', 'action' => 'updateuserprofile');
//sign up is a page which don't requires to login
$this->Auth->allow('signup');
$this->Auth->authorize = 'controller';
$this->Auth->logoutRedirect = '/';
}
function isAuthorized() {
return true;
}
}
型號:userinformation
class Userinformation extends Appmodel
{
var $name='Userinformation';
var $primaryKey = 'userid';
.
.
.
.
.
.
.
function hashPasswords($data){
if(isset($this->data['Userinformation']['password'])){
$this->data['Userinformation']['password']= md5($this->data['Userinformation']['password']);
return $data;
}
return $data;
}
function beforeSave() {
$this->hashPasswords(NULL,TRUE);
return TRUE;
}
}
控制器:UserinformationsController
function login(){
}
function logout() {
$this->redirect($this->Auth->logout());
}
觀點:userinformations/login.ctp
<?php
echo $this->Session->flash('auth');
echo $form->create('userinformation', array('action' => 'login'));
echo $form->input('user.username');
echo $form->input('user.password');
echo $form->end('Login');
?>