File: //var/www/html/qcr24/app/application/controllers/admin/Login.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Login extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('mcommon');
//
if (!empty($this->session->userdata('admin'))) {
redirect('admin/dashboard', 'refresh');
}
}
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$this->load->view('admin/login');
}
public function submitlogin()
{
$condition=array();
if($this->input->post()){
$this->form_validation->set_rules('email','Email','trim|required');
$this->form_validation->set_rules('password','Password','trim|required');
if($this->form_validation->run()==FALSE){
$this->load->view('admin/login');
}else{
$condition['email']=$this->input->post('email');
$condition['password']=md5($this->input->post('password'));
// $condition['role_id']='2';
$user_details=$this->mcommon->getRow('master_admin',$condition);
if(empty($user_details)){
$this->session->set_flashdata('error_msg','Invalid email or password');
redirect('admin/login');
}else{
if($user_details['status'] !='0'){
$this->session->set_flashdata('error_msg','Your account is pending.check your email to activate account');
redirect('admin/login');
}
$this->session->set_userdata('admin_data',$user_details);
redirect('admin/dashboard');
}
}
}else{
redirect('admin/login');
}
}
}