У меня есть таблица с именем "userinformations". Я хочу использовать поля emailid и password в качестве учетных данных для входа на мой сайт.
Добавили ниже коды в соответствующих файлах. Но когда я вхожу в систему, я нахожусь на той же странице входа в систему с сообщением «У вас нет прав доступа к этому местоположению».
приложение / app_controller.php
класс AppController расширяет контроллер {
var $components = array('Auth','Session');
function beforeFilter() {
$this->Auth->userModel = 'Userinformation';
Security::setHash("md5");
$this->Auth->fields = array('username' => 'emailid', 'password' => 'password');
$this->Auth->loginAction = array('controller' => 'Userinformations', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'Userinformations', 'action' => 'updateuserprofile');
//sign up is a page which don't requires to login
$this->Auth->allow('signup');
$this->Auth->authorize = 'controller';
$this->Auth->logoutRedirect = '/';
}
function isAuthorized() {
return true;
}
}
Модель: пользовательская информация
class Userinformation extends Appmodel
{
var $name='Userinformation';
var $primaryKey = 'userid';
.
.
.
.
.
.
.
function hashPasswords($data){
if(isset($this->data['Userinformation']['password'])){
$this->data['Userinformation']['password']= md5($this->data['Userinformation']['password']);
return $data;
}
return $data;
}
function beforeSave() {
$this->hashPasswords(NULL,TRUE);
return TRUE;
}
}
Контроллер: пользовательская информацияКонтроллер
function login(){
}
function logout() {
$this->redirect($this->Auth->logout());
}
просмотр: userinformations / login.ctp
<?php
echo $this->Session->flash('auth');
echo $form->create('userinformation', array('action' => 'login'));
echo $form->input('user.username');
echo $form->input('user.password');
echo $form->end('Login');
?>