03-06-2018, 07:39 AM
I need Valid is user login form enter below company controller. Please help me to do this session validate. Company controller and login model are below here.
Controller
Login Model
Controller
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Company extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model("Login_model");
}
public function index()
{
$this->load->view('header');
$this->load->view('top_header');
$this->load->view('left_nav');
$this->load->view('company/index');
$this->load->view('footer');
$this->load->view('settings');
}
//Add New Company
public function company_create()
{
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('company/create');
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}
//Save create company data to DB
public function save()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('company_name','Company Name','required|max_length[500]');
if($this->form_validation->run() == TRUE) {
$this->load->model('Company_model');
$this->Company_model->insert();
redirect('company/all_company');
}
else {
redirect('company/company_create');
}
}
//View Added Company List
public function all_company()
{
$this->load->model('Company_model');
$data["result"] = $this->Company_model->all_company();
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('company/all', $data);
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}
//View Individual Company Data
public function view_company($id)
{
$this->load->model('Company_model');
$data["row"] = $this->Company_model->view_company_data($id);
if ($data["row"] ==null) {
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('error_page/404');
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}else{
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('company/view', $data);
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}
}
//Get Data to form to edit data
public function company_update($id)
{
$this->load->model('Company_model');
$data["company"] = $this->Company_model->get($id);
if ($data["company"] ==null) {
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('error_page/404');
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}
else {
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('company/update', $data);
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}
}
//Update create company data to DB
public function update($id)
{
$this->load->model('Company_model');
$this->Company_model->update($id);
redirect('company/all_company');
}
//Block unwanted Company
public function company_delete($id)
{
$setstatus=array('status' => 1);
$wherestatus=array('id' => $id);
$this->load->model('Company_model');
$this->Company_model->delete('company',$setstatus, $wherestatus);
redirect("company/all_company");
}
//Show blocked company
public function show_suspended_companies()
{
$this->load->model('Company_model');
$data["result"] = $this->Company_model->get_suspended_companies();
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('company/suspended', $data);
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}
//Unblock the suspended companies
public function company_un_delete($id)
{
$wherestatus=array('status' => 0);
$setstatus=array('id' => $id);
$this->load->model('Company_model');
$this->Company_model->un_delete('company', $wherestatus, $setstatus);
redirect("company/all_company");
}
public function delete_company_from_db($id)
{
$this->load->model('Company_model');
$data = $this->Company_model->delete_company($id);
redirect("company/all_company");
}
}
Login Model
Code:
<?php
Class Login_model extends CI_model
{
public function __construct()
{
parent:: __construct();
$this->load->library('session');
}
public function user_create()
{
$data["user_name"] = $this->input->post('user_name');
$data["email"] = $this->input->post('email');
$data["password"] = $this->input->post('password');
$data["role"] = $this->input->post('role');
$data["status"] = 0;
$this->db->insert('app_user', $data);
}
public function auth()
{
$email = $this->input->post('email');
$password = md5($this->input->post('password'));
$query = $this->db->query("SELECT * FROM app_user WHERE email='$email' AND password='$password'");
if($query->num_rows() > 0)
{
$row = $query->row();
$this->session->set_userdata('NAME', $row->user_name);
$this->session->set_userdata('ID', $row->id);
//$this->session->set_userdata('PHOTO', $row->image);
return true;
} else {
return false;
}
}
public function login_desable()
{
$this->session->sess_destroy();
//$this->auth();
//unset($_SESSION['NAME']);
}
}