135 lines
3.5 KiB
PHP
135 lines
3.5 KiB
PHP
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Class : Login (Login - Controller)
|
|
* Login class to control to authenticate user credentials and starts user's session.
|
|
* @author : Venba Info Tech
|
|
* @version : 1.1
|
|
* @since :18 November 2017
|
|
*/
|
|
class Login extends CI_Controller
|
|
{
|
|
/**
|
|
* Default constructor of the class
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('login_model');
|
|
}
|
|
|
|
/**
|
|
* Index Page for this controller(default function of the class)
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->isLoggedIn();
|
|
}
|
|
|
|
/**
|
|
* To check the user is logged in or not
|
|
*/
|
|
function isLoggedIn()
|
|
{
|
|
$isLoggedIn = $this->session->userdata('isLoggedIn');
|
|
|
|
if(!isset($isLoggedIn) || $isLoggedIn != TRUE)
|
|
{
|
|
$this->load->view('login');
|
|
|
|
}
|
|
else
|
|
{
|
|
redirect('/dashboard');
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* To logged in user
|
|
*/
|
|
public function loginMe()
|
|
{
|
|
|
|
$this->load->library('form_validation');
|
|
|
|
|
|
$this->form_validation->set_rules('password', 'Password', 'required|max_length[32]|');
|
|
$designation='';
|
|
$role='';
|
|
|
|
if($this->form_validation->run() == FALSE)
|
|
{
|
|
$this->index();
|
|
}
|
|
else
|
|
{
|
|
$email = $this->input->post('email');
|
|
$password = $this->input->post('password');
|
|
|
|
$result = $this->login_model->loginMe($email, $password);
|
|
print_r($result);
|
|
if(count($result) > 0)
|
|
{
|
|
foreach ($result as $res)
|
|
{
|
|
$sessionArray = array('userId'=>$res->userId,
|
|
'role'=>$res->roleId,
|
|
'roleText'=>$res->role,
|
|
'name'=>$res->FirstName,
|
|
'Designation'=>$res->Designation,
|
|
'DEPCode'=>$res->DEPCode,
|
|
'HeadDept'=>$res->HeadDept,
|
|
'depaccess'=>$this->login_model->Accessdep($res->EmpID),
|
|
'DepartmentName'=>$res->DepartmentName,
|
|
'EmpID' => $res->EmpID,
|
|
'ProfilePic' =>$res->ProfilePic,
|
|
'isLoggedIn' => TRUE
|
|
);
|
|
|
|
$this->session->set_userdata($sessionArray);
|
|
|
|
$role=$res->roleId;
|
|
$designation=$res->Designation;
|
|
$DEPCode=$res->DEPCode;
|
|
|
|
|
|
|
|
}
|
|
if ($DEPCode == SECURITY)
|
|
{
|
|
redirect('/Addigr');
|
|
}
|
|
else
|
|
{
|
|
redirect('/dashboard');
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$this->session->set_flashdata('error', 'Email or password mismatch');
|
|
redirect('login');
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* To load forgot password view
|
|
*/
|
|
function forgotPassword()
|
|
{
|
|
$this->load->view('forgotPassword');
|
|
}
|
|
|
|
|
|
function resetPasswordUser()
|
|
{
|
|
$ContactNo = $this->input->post('phno');
|
|
echo $ContactNo;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
?>
|