我正在使用Employees作为处理用户名和密码的模型。它确实重定向到正确的控制器和操作,但$ 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 this-> request-> data
数组([员工] =>数组([用户名] => tmoorlag [密码] => a8c407a6218250985ccd24ff9ec6))
答案 0 :(得分:1)
应该是
$this->request->data['Employee']['password'] = md5($this->request->data['Employee']['password'].$salt);