我无法登录基于CakePHP 2.5的新开发网站。
我使用默认标识,使用AuthComponent :: password,但每次,函数AuthAuthComponent :: login都返回false,即使在表单中放入正确的凭据。
AppController.php
public $components = array(
"DebugKit.Toolbar",
"Session",
"Auth" => array(
"loginAction" => array(
"controller" => "users",
"action" => "login"
),
"authError" => "Accès refusé"
)
);
UsersController.php
public function manager_login() {
$this->layout = "manager_login";
// The user tries to connect
if($this->request->is("post")) {
if($this->Auth->login()) {
return $this->redirect("/manager/");
}
}
}
User.php(Model)beforeSave()函数
public function beforeSave($options = array()) {
$this->data["User"]["password"] = AuthComponent::password($this->data["User"]["password"]);
}
manager_login.ctp(带有表单的视图)
<?php echo $this->form->create("User", array("inputDefaults" => array("div" => false, "label" => false))); ?>
<div class="login-box-header bg-dark-blue">
<h3 class="login-box-title">Administration</h3>
</div>
<div class="login-box-content bg-light-white">
<?php echo $this->form->input("User.username"); ?>
<?php echo $this->form->input("User.password"); ?>
<?php echo $this->form->checkbox("User.remember"); ?>
<?php echo $this->form->label("User.remember", "Se souvenir de moi"); ?>
</div>
<div class="login-box-footer" style="background-color: #fff">
<button type="submit" class="tiny expand">Se connecter</button>
</div>
<?php echo $this->form->end(); ?>
事实上,我认为SQL查询存在问题,因为我在以下查询中看不到WHERE条件:
SELECT `User`.`id`, `User`.`username`, `User`.`password`, `User`.`email`,
`User`.`avatar`, `User`.`skype`, `User`.`twitter`, `User`.`created`,
`User`.`updated`
FROM `leboncube`.`lbc_users` AS `User`
WHERE `User`.`username` = 'Mike Hell'
LIMIT 1
我在函数beforeSave中对用户注册的密码进行哈希处理;我将控制器中生成的哈希与$ this-&gt; Auth-&gt;密码和数据库中的哈希进行了比较:它们完全相同。
答案 0 :(得分:0)
我发现了问题!
这是因为我忘了将函数isAuthorized()添加到我的控制器中
谢谢你的回答!