我使用插件BzUtils插件創建令牌進行身份驗證。 文件助推:如何使用BzUtils插件在cakephp2中使用Token進行身份驗證。
CakePlugin :: load('BzUtils');
文件的AppController:
public function beforeFilter() {
$this->Auth->authenticate = array(
'Form' => array(
'fields' => array(
'username' => 'username',
'password' => 'password'
),
'userModel' => 'User',
'scope' => array(
'User.active' => 1,
)
),
'BzUtils.JwtToken' => array(
'fields' => array(
'username' => 'username',
'password' => 'password',
),
'header' => 'AuthToken',
'userModel' => 'User',
'scope' => array(
'User.active' => 1
)
)
);
和行動登錄在RestUsersController:
public function login() {
if ($this->Auth->login()) {
$user = $this->Auth->user();
$token = JWT::encode($user, Configure::read('Security.salt'));
$this->set('user', $user);
$this->set('token', $token);
$this->set('_serialize', array('user', 'token'));
} else {
throw new NotAcceptableException(__('Email or password is wrong.'));
}
}
地址:http://kcxcode1.dev/restusers/login
錯誤:致命錯誤:類 '智威湯遜' 不缶ND在C:\ XAMPP \ htdocs中\ koreconx \應用\控制器\ RestUsersController.php第42行
這是你使用的插件嗎? https://github.com/burzum/cakephp-bz-utils – gmponos
我使用的插件:https://github.com/burzum/cakephp-bz-utils/tree/develop –
是的,我發現不同的分支。在這個插件/分支裏,靜態函數'encode'是什麼?你能找到它並把它鏈接到這裏嗎? – gmponos