I have an issue where every time I click on login it just takes me to my page it seems to not be checking to see if the username or password was entered. I am not sure what the issue is I changed the line if ($this->form_validation->run() == FALSE)
to true and then I just get redirected back to the login when I enter correct password. I think it is something simple I am just missing. If anyone has an idea any direction would help in the mean time I will keep figuring it out.
Controllers
Verifylogin.php controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class VerifyLogin extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('user','',TRUE);
}
function index()
{
//This method will have the credentials validation
$this->load->library('form_validation');
if($this->form_validation->run() == false)
{
//Field validation failed. User redirected to login page
$this->load->view('person_view');
}
else
{
//Go to private area
redirect('Person', 'refresh');
}
}
public function check_database() {
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE) {
$this->load->view('login_view.php');
} else {
$data = array(
'username' => $this->input->post('username'),
'password' => $this->input->post('password')
);
$result = $this->admin_database->login($data);
if($result == TRUE){
$sess_array = array(
'username' => $this->input->post('username')
);
}
}
}
}
Person.php controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Person extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('person_model','callin_list');
}
public function index()
{
if($this->session->userdata('logged_in'))
{
$this->load->view('person_view');
}else
{
//If no session, redirect to login page
redirect('login', 'refresh');
}
}
public function ajax_list()
{
$list = $this->callin_list->get_datatables();
$data = array();
$no = $_POST['start'];
foreach ($list as $callin_list) {
$no++;
$row = array();
$row[] = $callin_list->Date_Scheduled;
$row[] = $callin_list->Employee_Name;
$row[] = $callin_list->Employee_Number;
$row[] = $callin_list->Time_Reported;
$row[] = $callin_list->Reason;
$row[] = $callin_list->Scheduled_Area;
$row[] = $callin_list->Contact;
$row[] = $callin_list->Comments;
//add html for action
$row[] = '<a class="btn btn-sm btn-primary" href="javascript:void()" title="Edit" onclick="edit_person('."'".$callin_list->id."'".')"><i class="glyphicon glyphicon-pencil"></i> Edit</a>
<a class="btn btn-sm btn-danger" href="javascript:void()" title="Hapus" onclick="delete_person('."'".$callin_list->id."'".')"><i class="glyphicon glyphicon-trash"></i> Delete</a>';
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->callin_list->count_all(),
"recordsFiltered" => $this->callin_list->count_filtered(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}
public function ajax_edit($id)
{
$data = $this->callin_list->get_by_id($id);
echo json_encode($data);
}
public function ajax_add()
{
$this->_validate();
$data = array(
'Date_Scheduled' => $this->input->post('Date_Scheduled'),
'Employee_Name' => $this->input->post('Employee_Name'),
'Employee_Number' => $this->input->post('Employee_Number'),
'Time_Reported' => $this->input->post('Time_Reported'),
'Reason' => $this->input->post('Reason'),
'Scheduled_Area' => $this->input->post('Scheduled_Area'),
'Contact' => $this->input->post('Contact'),
'Comments' => $this->input->post('Comments'),
);
$insert = $this->callin_list->save($data);
echo json_encode(array("status" => TRUE));
}
public function ajax_update()
{
$this->_validate();
$data = array(
'Date_Scheduled' => $this->input->post('Date_Scheduled'),
'Employee_Name' => $this->input->post('Employee_Name'),
'Employee_Number' => $this->input->post('Employee_Number'),
'Time_Reported' => $this->input->post('Time_Reported'),
'Reason' => $this->input->post('Reason'),
'Scheduled_Area' => $this->input->post('Scheduled_Area'),
'Contact' => $this->input->post('Contact'),
'Comments' => $this->input->post('Comments'),
);
$this->callin_list->update(array('id' => $this->input->post('id')), $data);
echo json_encode(array("status" => TRUE));
}
public function ajax_delete($id)
{
$this->callin_list->delete_by_id($id);
echo json_encode(array("status" => TRUE));
}
//validation section were user must enter data in all fields
private function _validate()
{
$data = array();
$data['error_string'] = array();
$data['inputerror'] = array();
$data['status'] = TRUE;
if($this->input->post('Date_Scheduled') == '')
{
$data['inputerror'][] = 'Date_Scheduled';
$data['error_string'][] = 'Date_Scheduled is required';
$data['status'] = FALSE;
}
if($this->input->post('Employee_Name') == '')
{
$data['inputerror'][] = 'Employee_Name';
$data['error_string'][] = 'Employee_Name is required';
$data['status'] = FALSE;
}
if($this->input->post('Employee_Number') == '')
{
$data['inputerror'][] = 'Employee_Number';
$data['error_string'][] = 'Employee_Number is required';
$data['status'] = FALSE;
}
if($this->input->post('Time_Reported') == '')
{
$data['inputerror'][] = 'Time_Reported';
$data['error_string'][] = 'Time_Reported is required';
$data['status'] = FALSE;
}
if($this->input->post('Reason') == '')
{
$data['inputerror'][] = 'Reason';
$data['error_string'][] = 'Reason is required';
$data['status'] = FALSE;
}
if($this->input->post('Scheduled_Area') == '')
{
$data['inputerror'][] = 'Scheduled_Area';
$data['error_string'][] = 'Scheduled_Area is required';
$data['status'] = FALSE;
}
if($this->input->post('Contact') == '')
{
$data['inputerror'][] = 'Contact';
$data['error_string'][] = 'contact is required';
$data['status'] = FALSE;
}
if($this->input->post('Comments') == '')
{
$data['inputerror'][] = 'Comments';
$data['error_string'][] = 'Comments is required';
$data['status'] = FALSE;
}
if($data['status'] === FALSE)
{
echo json_encode($data);
exit();
}
}
}
login_model.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Author: Jorge Torres
* Description: Login model class
*/
class Login_model extends CI_Model{
function __construct(){
parent::__construct();
}
public function validate(){
// grab user input
$username = $this->security->xss_clean($this->input->post('username'));
$password = $this->security->xss_clean($this->input->post('password'));
// Prep the query
$this->db->where('username', $username);
$this->db->where('password', $password);
// Run the query
$query = $this->db->get('users');
// Let's check if there are any results
if($query->num_rows() == 1)
{
// If there is a user, then create session data
$row = $query->row();
$data = array(
'userid' => $row->userid,
'fname' => $row->fname,
'lname' => $row->lname,
'username' => $row->username,
'validated' => true
);
$this->session->set_userdata($data);
return true;
}
// If the previous process did not validate
// then return false.
return false;
}
}
?>
login_view.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login Form</title>
<style type="text/css">
.content{
margin-left: 400px;
margin-top: 300px;
}
.btn{
width:242px;
height: 50px;
}
#label{
font-size: 24px;
font-weight: normal;
}
</style>
<link href="<?php echo base_url('assets/bootstrap/css/bootstrap.min.css')?>" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="content">
<h1>DC399 Callin Login Page</h1>
<?php echo validation_errors(); ?>
<?php echo form_open('verifylogin'); ?>
<label id="label"for="username">Username:</label><br>
<input type="text" size="20" id="username"style="width: 239px; height: 40px; margin-right: 20px;"name="username"/>
<br/>
<label id="label" for="password">Password:</label><br>
<input type="password" size="20" id="passowrd" style="width: 239px; height: 40px; margin-right: 20px;"name="password"/>
<br/><br>
<input class="btn btn-success" type="submit" value="Login"/>
</form>
</div>
</div>
<script src="<?php echo base_url('assets/jquery/jquery-2.1.4.min.js')?>"></script>
<script src="<?php echo base_url('assets/bootstrap/js/bootstrap.min.js')?>"></script>
</body>
</html>