I have a login function in my controller that was getting called before, but i did some changes and it all just stopped.
I have a basic login with 2 inputs for a username/password and a submit
//Javascript
function initLogin(e) {
e.preventDefault()
var d = {
user: $('#userName').val(),
password: $('#password').val()
}
console.log('test')//gets returned
$.post('/cms/login/',d,function(data) {
console.log(data);//nothing returning
},'json');
}
//Controller
class CMS extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->library('session');
//$this->_check_if_logged_in();
}
private function _check_if_logged_in() {
if (!$this->uri->segment(2) || $this->uri->segment(2) == 'login') return FALSE;
if ($this->session->userdata('logged_in') != TRUE) redirect('/cms');
}
public function index() {
if ($this->session->userdata('logged_in') == TRUE) redirect('/cms/home', 'refresh');
$this->load->view('cms/log_in_view');
$this->load->view('cms/parts/footer');
}
function login() {
echo json_encode(array('test' => 'test'))//doesn't get echoed
$data['user_name'] = $this->input->post('user');
$data['pass_word'] = sha1($this->input->post('password'));
$this->db->select('id');
$res = $this->db->get_where('login',$data,1)->row_array();
if (is_numeric($res['id'])) {
$data['logged_in'] = TRUE;
$this->session->set_userdata('logged_in',TRUE);
}
echo json_encode($res);
}
}
Basically i commented out everything that I thought might get in the way of returning a response, but this is going against everything I've learned.
I'm convinced the login function in the controller doesn't get called, even though it did before when i didn't change anything in the js or login function itself