存儲之前散列這是AppController
代碼:密碼沒有在數據庫
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'dashboard', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'admins', 'action' => 'index'),
'authorize' => array('Controller')
)
);
public function beforeFilter()
{
$this->Auth->loginAction = array('controller' => 'admins', 'action' => 'login');
}
public function beforeSave()
{
if(isset($this->data['Admin']['password']))
{
$this->data['Admin']['password'] = AuthComponent::password($this->data['Admin']['password']);
}
return true;
}
這是AdminsController
代碼:
public $name = 'Admins';
public function beforeFilter()
{
parent::beforeFilter();
$this->Auth->fields = array('username' => 'email', 'password' => 'password');
$this->Auth->allow('signup');
}
public function index()
{
$this->Admin->recursive = 0;
$this->set('admins', $this->Admin->find('all'));
}
public function login()
{
$this->set('title_for_layout', 'Polkadot - Admin Login');
if($this->request->is('post'))
{
if($this->Auth->login())
{
$this->Session->setFlash('Login successfull!');
$this->redirect($this->Auth->redirect());
}
else
{
$this->Session->setFlash('Login failed!');
}
}
}
public function signup()
{
$this->set('title_for_layout', 'Polkadot - Admin Sign Up');
if($this->request->is('post'))
{
if($this->Admin->save($this->request->data))
{
$this->Session->setFlash('Account created successfully!');
$this->redirect(array('action' => 'index'));
}
else
{
$this->Session->setFlash('Account could not be created, please try again!');
}
}
}
我可以看到帳戶創建,但在密碼數據庫是純文本。當我嘗試登錄時,它失敗。我做錯了什麼?
我想在管理員登錄時打開Dashboard
控制器的index
操作。帳戶註冊使用四個輸入字段:名稱(文本),電子郵件(文本),密碼(密碼)和密碼確認(密碼)。因此,登錄表單使用兩個字段:電子郵件(文本)和密碼(密碼)。
使用的CakePHP版本是2.3.1
所有幫助表示感謝!
[編輯]:以下是錯誤日誌
2013-04-10 19:31:13 Error: [MissingControllerException] Controller class CssController could not be found.
Exception Attributes: array (
'class' => 'CssController',
'plugin' => NULL,
)
Request URL: /polkapanel/css/cake.generic.css
Stack Trace:
#0 C:\wamp\www\polkapanel\app\webroot\index.php(109): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#1 {main}
2013-04-10 19:31:13 Error: [MissingControllerException] Controller class ImgController could not be found.
Exception Attributes: array (
'class' => 'ImgController',
'plugin' => NULL,
)
Request URL: /polkapanel/img/cake.power.gif
Stack Trace:
#0 C:\wamp\www\polkapanel\app\webroot\index.php(109): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#1 {main}
2013-04-10 19:31:25 Error: [MissingControllerException] Controller class CssController could not be found.
Exception Attributes: array (
'class' => 'CssController',
'plugin' => NULL,
)
Request URL: /polkapanel/css/cake.generic.css
Stack Trace:
#0 C:\wamp\www\polkapanel\app\webroot\index.php(109): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#1 {main}
2013-04-10 19:31:25 Error: [MissingControllerException] Controller class ImgController could not be found.
Exception Attributes: array (
'class' => 'ImgController',
'plugin' => NULL,
)
Request URL: /polkapanel/img/cake.power.gif
Stack Trace:
#0 C:\wamp\www\polkapanel\app\webroot\index.php(109): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#1 {main}
控制器中沒有beforeSave()函數,它應該放在模型上(AppModel或User.ctp,取決於你想要的位置管理密碼) – Nunser 2013-04-10 18:49:32