Я пробовал почти все сейчас, и у меня все еще возникают проблемы с моей установкой Auth. Я использую Employee в качестве моей модели с поля employee_id и password. Blowfish - мой пароль, а Employees/index - в моем контроллере/действии.
Я пытаюсь повторить $ this-> Auth-> login(), но не отвечает.
Выход из $ this-> request-> данные
Array ([Employee] => Array ([employee_id] => bob [password] => temp))
Сотрудник Модель
<?php
class Employee extends AppModel {
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}
public $primaryKey = 'employee_id';
public $hasMany = array(
'CustomerInteraction' => array(
'foreignKey' => 'created_by'
),
'Appointment' => array(
'foreignKey' => 'assigned_to'
),
'Customer' => array(
'className' => 'Customer',
'foreignKey' => false
)
);
public $hasOne = array(
'SalesTarget' => array(
'foreignKey' => 'subject'
)
);
public $virtualFields = array(
'full_name' => 'CONCAT(Employee.first_name, " ", Employee.last_name)'
);
}
?>
AppController
public $components = array(
'Session',
'Auth' => array(
'flashElement' => 'login_error',
'authError' => 'You must be logged in to view this page.',
'loginError' => 'Invalid Username or Password entered, please try again.',
'loginAction' => array(
'controller' => 'Employees',
'action' => 'index',
),
'authenticate' => array(
'all' => array(
'userModel' => 'Employee',
'passwordHasher' => 'Blowfish'
),
'Form' => array(
'userModel' => 'Employee',
'passwordHasher' => 'Blowfish',
'fields' => array(
'username' => 'employee_id',
'password' => 'password',
)
)
)
),
);
public $uses = array(
'ProgramApplication',
'Employee'
);
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->fields = array(
'username' => 'employee_id',
'password' => 'password'
);
EmployeesController
<?php
class EmployeesController extends AppController {
public $uses = array(
'TimeEntry',
'Employee',
'CakeEmail',
'Network/Email' ,
'CraigslistTemplate',
'Inventory'
);
public $helpers = array(
'DateConversion'
);
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('index','checkUsername','passwordStatus','passwordCheck','convertPassword');
}
public function index() {
//Set layout to loginr
$this->layout = 'login';
//if already logged-in, redirect
if($this->Session->check('Auth.User')){
return $this->redirect(
array('controller' => 'Search', 'action' => 'index'));
}
echo "1";
if($this->request->is('post')) {
echo $this->Auth->login();
if($this->passwordCheck($this->request->data['Employee']['employee_id'],$this->request->data['Employee']['password'])) {
}else{
echo "Invalid username/password";
}
}
Index.ctp
<div class="Employees form">
<?php //echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('Employee',array('controller' => 'Employees','type' => 'POST')); ?>
<fieldset>
<legend>
<?php echo __('Please enter your username and password'); ?>
</legend>
<?php echo $this->Form->input('employee_id',array('type' => 'Username'));
echo $this->Form->input('password');
?>
</fieldset>
<?php echo $this->Form->end(__('Login')); ?>
</div>
Я буду использовать то, что когда-либо работает. Какое шифрование вы использовали? или что такое торты по умолчанию? – Subie
Я просто прокомментировал строки, связанные с blowfish – cornelb
Работал отлично! Я не могу вас поблагодарить! – Subie