默認登錄過程需要電子郵件,而不是用戶名。CakeDC用戶以用戶名登錄
我已經添加了這AppController.php
上beforeFilter()
,這是在CakePHP's Docs Authentication還提到:
$this->Auth->fields = array(
'username' => 'username',
'password' => 'password'
);
但不知何故,它不允許用戶與他們的用戶名登錄。關於如何改變這種情況的任何想法?
AppController的
App::uses('Controller', 'Controller');
class AppController extends Controller {
var $components = array(
'Session',
'RequestHandler',
'Security'
);
var $helpers = array('Form', 'Html', 'Session', 'Js');
public function beforeFilter() {
$this->Auth->authorize = 'Controller';
$this->Auth->fields = array('username' => 'username', 'password' => 'password');
$this->Auth->loginAction = array('plugin' => 'users', 'controller' => 'users', 'action' => 'login', 'admin' => false);
$this->Auth->loginRedirect = '/';
$this->Auth->logoutRedirect = '/';
$this->Auth->authError = __('Sorry, but you need to login to access this location.', true);
$this->Auth->loginError = __('Invalid e-mail/password combination. Please try again', true);
$this->Auth->autoRedirect = true;
$this->Auth->userModel = 'User';
$this->Auth->userScope = array('User.active' => 1);
if ($this->Auth->user()) {
$this->set('userData', $this->Auth->user());
$this->set('isAuthorized', ($this->Auth->user('id') != ''));
}
}
/View/Users/login.ctp
這是一樣的,在插件的文件夾中找到默認login.ctp
。我只是將字段電子郵件更改爲用戶名。
現在,這裏有一些有趣的事情。無論我將哪些代碼放入此文件,CakePHP都會從插件登錄視圖中提取內容,我創建的視圖將被忽略。
調試
當調用調試器:
Debugger::dump($this->Auth);
這說明一切,我設置的值。但它仍然不接受用戶名。我仍然可以通過電子郵件登錄,所以這不是我插入錯誤的憑據。它只是在等待電子郵件/密碼,而不是用戶名/密碼。
未經測試/不知道這是否是正確的方法,但蛋糕DC插件將在'用戶\控制器\ UsersController.php'圍繞線144的價值觀 - 你可以嘗試調整它們那裏。 – Ross
事情是,我不想改變核心,我不認爲這是覆蓋設置的正確方法。但如果沒有其他選擇,我必須遵循這條路線。 – rlcabral
需要注意的是,CakeDC用戶插件使用該電子郵件進行註冊,忘記密碼等等等。 – Dave