【发布时间】:2014-01-21 20:10:02
【问题描述】:
我使用员工作为模型来处理用户名和密码。它确实重定向到正确的控制器和操作,但 $this->Auth->login() 似乎无法正常工作。有没有人发现问题?
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 of $this->request->data
数组([员工] => 数组([用户名] => tmoorlag [密码] => a8c407a6218250985ccd24ff9ec6))
【问题讨论】:
标签: php cakephp authentication