0
我使用Employees作为模型来处理用户名和密码。它重定向到正确的控制器和操作,但$ this-> Auth-> login()似乎没有正常工作。有没有人看到问题?在自定义模型上使用CakePHP身份验证
EmployeesController
public function index() {
//Set layout to login
$this->layout = 'login';
//Set salt
//Convert user password to md5
$this->request->data['password'] = md5($this->request->data['password'].$salt);
//if already logged-in, redirect
if($this->Session->check('Auth.User')){
$this->redirect(array('action' => 'index'));
}
if ($this->request->is('post')) {
echo "here";
if ($this->Auth->login()) {
echo $this->Auth->user('username');
$this->redirect($this->Auth->redirectUrl());
} else {
echo "Invlaid Username";
}
}
}
AppController的
public $components = array(
'Session',
'Auth' => array(
'loginAction' => array(
'controller' => 'Employees',
'action' => 'index',
),
'authenticate' => array(
'all' => array('userModel' => 'Employee'),
'Form' => array(
'userModel' => 'Employee',
'fields' => array(
'username' => 'employee_id',
'password' => 'password',
)
)
)
),
);
的$这 - 的print_r>请求 - >数据
阵列([雇员] =>数组([用户名] => tmoorlag [password] => a8c407a6218250985ccd24ff9ec6))
仍然没有变化。我如何告诉Auth使用除默认用户模型之外的模型? – Subie
try:'authenticate'=> array('all'=> array('userModel'=>'Emplyee'),'Form'=> array(...)。你是否收到“invalid username”错误?在尝试登录之前调试$ this-> request-> data,看看数据是否正确? – cornelb
进行了更改。它表示无效的用户名,我将print_r的结果放在最上面 – Subie