Codeigniter Вход в сеанс Неизвестная ошибка

Добрый день, ребята.

У меня проблема с входом в CMS. Когда я нажимаю кнопку входа, страница входа обновляется и снова появляется.
Библиотека сессий определена. Ключ шифрования сеанса установлен.

Код контроллера входа в систему:

<?php
class User extends Admin_Controller {

public function __construct(){
parent::__construct();
}

public function login(){

$dashboard = 'admin/dashboard';
$this->user_m->loggedin() == FALSE || redirect($dashboard);

$rules = $this->user_m->rules;
$this->form_validation->set_rules($rules);
if ($this->form_validation->run() == TRUE) {
// We can login and redirect
if ($this->user_m->login() == TRUE) {
redirect($dashboard);
}
else {
$this->session->set_flashdata('error', 'That email/password combination does not       exist');
redirect('admin/user/login', 'refresh');

}
}
$this->data['subview'] = 'admin/user/login';
$this->load->view('admin/_layout_modal', $this->data);
}

public function logout(){
$this->user_m->logout();
redirect('admin/user/login');
}
}

Логин Модель код:

<?php
class User_M extends MY_Model
{

protected $_table_name = 'users';
protected $_order_by = 'name';
public $rules = array(
'email' => array(
'field' => 'email',
'label' => 'Email',
'rules' => 'trim|required|valid_email|xss_clean'
),
'password' => array(
'field' => 'password',
'label' => 'Password',
'rules' => 'trim|required'
)
);

function __construct ()
{
parent::__construct();
}

public function login ()
{
$user = $this->get_by(array(
'email' => $this->input->post('email'),
'password' => $this->hash($this->input->post('password')),
), TRUE);

if (count($user)) {
// Log in user
$data = array(
'name' => $user->name,
'email' => $user->email,
'id' => $user->id,
'loggedin' => TRUE,
);
$this->session->set_userdata($data);
}
}

public function logout ()
{
$this->session->sess_destroy();
}

public function loggedin ()
{
return (bool) $this->session->userdata('loggedin');
}

public function hash ($string)
{
return hash('sha512', $string . config_item('encryption_key'));
}
}

0

Решение

Я предлагаю лучше поставить вид входа в систему в другом состоянии,

public function login(){
$dashboard = 'admin/dashboard';
$this->user_m->loggedin() == FALSE || redirect($dashboard);
$rules = $this->user_m->rules;
$this->form_validation->set_rules($rules);
if($this->input->post()) {       //check if request if post
if ($this->form_validation->run() == TRUE) {
// We can login and redirect
if ($this->user_m->login() == TRUE) {
redirect($dashboard);
}
else {
$this->session->set_flashdata('error', 'That email/password combination does not       exist');
redirect('admin/user/login', 'refresh');

}
}
} else {     //defult login page
$this->data['subview'] = 'admin/user/login';
$this->load->view('admin/_layout_modal', $this->data);
} }

Если проблема не устранена, отладьте ее вручную и проверьте, где она застряла!

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector