我在使用CakePHP 2一段时间后开始使用CakePHP 3,我在创建身份验证登录时遇到了麻烦.
新的auth函数$this->Auth->identify()总是返回false.
在数据库上,密码是完美加密的,并且用户也可以查询.
我的代码:
AppController的:
[...]
class AppController extends Controller{
public function initialize(){
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'loginRedirect' => [
'controller' => 'Admin',
'action' => 'index'
],
'logoutRedirect' => [
'controller' => 'Pages',
'action' => 'display'
]
]);
}
public function beforeFilter(Event $event)
{
$this->Auth->allow(['display']);
}
}
Run Code Online (Sandbox Code Playgroud)
UserController的:
[...]
class UsersController extends AppController{
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
$this->Auth->allow(['logout']);
}
[...]
public function login()
{
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return …Run Code Online (Sandbox Code Playgroud) 我试图发送一个帖子到Ionic使用角度,但我有回应:
对预检请求的响应未通过访问控制检查:请求的资源上不存在"Access-Control-Allow-Origin"标头.原产地" 的http://本地主机:8100 "因此不允许访问.响应具有HTTP状态代码404.
我知道外部服务正在运行,因为我用ajax测试它,一切都运行完美......
在AngularJS(Ionic)和Ajax中使用的代码下面:
离子型:
var loginServiceUrl = 'http://url.com.br'; //It is not the real one
var loginServiceData = {
email: email@email.com.br
senha: 1234
};
$http.post(loginServiceUrl, loginServiceData).
then(function (res){
console.log(res);
});
Run Code Online (Sandbox Code Playgroud)
阿贾克斯:
$.ajax({
type: "POST",
url : 'http://url.com.br', //It is not the real one
data : {email: 'email@email.com.br', senha: '1234'},
success: function(result) {
$('html').text(JSON.stringify(result));
}
});
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么我通过我的localhost上的ajax获取帖子而不是离子,也是localhost?