249 lines
8.4 KiB
PHP
Executable File
249 lines
8.4 KiB
PHP
Executable File
<?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,
|
|
'CompanyName' =>$res->CompanyName,
|
|
'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');
|
|
}
|
|
|
|
/**
|
|
* To reset password of the user (without one time code)
|
|
*/
|
|
function resetPasswordUser(){
|
|
|
|
$mobileno = $this->input->post('phno');
|
|
$emailid = $this->input->post('email');
|
|
$result = $this->login_model->getuserid($mobileno,$emailid);
|
|
|
|
if(!empty($result)){
|
|
|
|
$string = "abcde".rand(10000,99999)."vwxyz";
|
|
$string_shuffled = str_shuffle($string);
|
|
$passcode = substr($string_shuffled, 1, 6);
|
|
$password = "RESICO@".$passcode;
|
|
|
|
$mobile = "91".$result[0]->ContactNumber;
|
|
//$msg = "Your Password is 'resico1234' sent from Resico Industries ";
|
|
$msg = "Hi " .$result[0]->FirstName. ",
|
|
\n Your password has been resetted sucessfully.
|
|
\n Please login with your new password '".$password."'";
|
|
|
|
$message = urlencode($msg);
|
|
|
|
$ch=curl_init();
|
|
curl_setopt($ch,CURLOPT_URL,"https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=xegCdYUIMf3&MobileNo=".$mobile."&SenderID=VNBAIT&Message=".$message."&ServiceName=PROMOTIONAL_HIGH");
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
|
$output =curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
$resetpassword = getHashedPassword($password);
|
|
|
|
$updatepassword = $this->login_model->updatepassword($result[0]->userId,$resetpassword);
|
|
|
|
echo "<script>alert('Password Send successfully, Please check your mobile.');</script>";
|
|
redirect('/loginMe','refresh');
|
|
}
|
|
else{
|
|
echo "<script>alert('".$mobileno." This Mobile Number is not registered with us.');</script>";
|
|
redirect('/loginMe','refresh');
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* To Get One time code to reset password of the user (ajax call)
|
|
*/
|
|
/** function getOTP()
|
|
* {
|
|
* $id = $this->input->post('id');
|
|
* $result = $this->login_model->temp($id);
|
|
* if(!empty($result)){
|
|
* $string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
* $string_shuffled = str_shuffle($string);
|
|
* $password = substr($string_shuffled, 1, 7);
|
|
* $otp = rand(1000, 9999);
|
|
* echo "resico@".rand(1000,9999);die;
|
|
*
|
|
* //print_r($result);die;
|
|
* //$result[0]->ContactNumber;
|
|
*
|
|
* $mobile = "91".$result[0]->ContactNumber;
|
|
* //$msg = "Your Password is 'resico1234' sent from Resico Industries ";
|
|
* $msg = "Hi " .$result[0]->FirstName. ",
|
|
* \n We have generated One Time Code For You. This code used for reset your password
|
|
* \n YOUR CODE IS'".$password."'and'".$otp."'";
|
|
*
|
|
* $message = urlencode($msg);
|
|
* // echo $mobile , $message;
|
|
* $ch=curl_init();
|
|
* curl_setopt($ch,CURLOPT_URL,"https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=xegCdYUIMf3&MobileNo=".$mobile."&SenderID=VNBAIT&Message=".$message."&ServiceName=PROMOTIONAL_HIGH");
|
|
* curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
|
* $output =curl_exec($ch);
|
|
*
|
|
* //return $output;
|
|
* //print_r($output);exit();
|
|
* curl_close($ch);
|
|
* //echo json_encode($result);
|
|
* $updateotp = $this->login_model->temp2($result[0]->userId,$otp);
|
|
* $data = $updateotp[0]->OTP;
|
|
* echo $data;
|
|
* }}
|
|
*/
|
|
|
|
/**
|
|
* After Getting One time code
|
|
* Reset password of the user (with OTP)
|
|
*/
|
|
/** function resetPasswordConfirmUser(){
|
|
*
|
|
* // $this->load->library('form_validation');
|
|
*
|
|
* // $this->form_validation->set_rules('newPassword','New password','required|max_length[20]');
|
|
* // $this->form_validation->set_rules('confirmPassword','Confirm new password','required|matches[newPassword]|max_length[20]');
|
|
*
|
|
* $newPassword = $this->input->post('newPassword');
|
|
* $ConfirmPassword = $this->input->post('confirmPassword');
|
|
*
|
|
* $mobileno = $this->input->post('phno');
|
|
*
|
|
* $da ta = $this->login_model->getuserdtl($mobileno);
|
|
* $userid = $data[0]->userId;
|
|
* $OTP = NULL;
|
|
*
|
|
* $Array = array('password'=>getHashedPassword($newPassword),'OTP'=>$OTP);
|
|
*
|
|
* $result = $this->login_model->resetpassword($Array,$userid);
|
|
*
|
|
* if($result > 0)
|
|
* {
|
|
* echo "<script>alert('You Password Resetted!');</script>"; redirect('login','refresh');
|
|
* }
|
|
* else
|
|
* {
|
|
* echo "<script>alert('Have Not Update Error Msg!');</script>"; redirect('login','refresh');
|
|
* }
|
|
*
|
|
* }
|
|
*/
|
|
|
|
|
|
}
|
|
|
|
?>
|