当任何用户尝试登录时,我正在尝试检查状态,如果状态为0,则重定向回管理员。 然后,如果status为1,则重定向到仪表板。
我已经测试了它仍然让我发送到仪表板,即使状态0
Var Dump数组(1){[" status"] => string(1)" 0" } *
确保检查登录状态的最佳解决方案是什么。
模型功能
public function getStatus() {
$this->db->select('status');
$this->db->from($this->db->dbprefix . 'user');
$this->db->where('username', $this->input->post('username'));
$query = $this->db->get();
return $query->row_array();
}
控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends Admin_Controller {
public function index() {
$this->form_validation->set_rules('username', 'Username', 'required|callback_validate');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run($this) == FALSE) {
$this->load->view('template/common/login.tpl', $this->data);
} else {
$this->load->model('admin/user/model_user');
var_dump($this->model_user->getStatus());
// array(1) { ["status"]=> string(1) "0" }
exit;
if ($this->model_user->getStatus()) {
redirect('admin/dashboard');
} else {
$this->session->set_flashdata('error', 'You have not been enabled by the webmaster. Please wait up to 24/48 hours. If you need to contact the website master email' .' '. config_item('config_email'));
redirect('admin');
}
}
}
}
public function validate() {
$this->load->library('user');
if ($this->user->login() == FALSE) {
$this->form_validation->set_message('validate', '<i class="fa fa-exclamation-triangle"></i> Does not match any of our database records!');
return false;
} else {
return true;
}
}
}
答案 0 :(得分:0)
问题解决了我不得不从控制器和模型中删除一些东西。
模型
public function getStatus() {
$this->db->where('username', $this->input->post('username'));
$query = $this->db->get($this->db->dbprefix . 'user');
$ret = $query->row();
return $ret->status;
}
控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends Admin_Controller {
private $error = array();
public function __construct() {
parent::__construct();
}
public function index() {
$data['title'] = 'Administration';
$this->form_validation->set_rules('username', 'Username', 'required|callback_validate');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run($this) == FALSE) {
$this->load->view('template/common/login.tpl', $data);
} else {
$this->load->model('admin/user/model_user');
if ($this->model_user->getStatus() == 1) {
redirect('admin/dashboard');
} else {
$this->session->set_flashdata('error', 'You have not been enabled by the webmaster. Please wait up to 24/48 hours. If you need to contact the website master email' .' '. config_item('config_email'));
redirect('admin');
}
}
}
public function validate() {
$this->load->library('user');
if ($this->user->login() == FALSE) {
$this->form_validation->set_message('validate', '<i class="fa fa-exclamation-triangle"></i> Does not match any of our database records!');
return false;
} else {
return true;
}
}
}