198 lines
6.1 KiB
PHP
198 lines
6.1 KiB
PHP
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
class Login_model extends CI_Model
|
|
{
|
|
|
|
/**
|
|
* This function used to check the login credentials of the user
|
|
* @param string $email : This is email of the user
|
|
* @param string $password : This is encrypted password of the user
|
|
*/
|
|
function loginMe($email, $password)
|
|
{
|
|
$this->db->select('BaseTbl.userId, BaseTbl.password, Emp.EmpID,Emp.FirstName,Emp.Designation, BaseTbl.roleId, Roles.role,DEPT.DEPCode,DEPT.DepartmentName,DEPT.HeadDept,Emp.ProfilePic,CompTbl.CompanyName');
|
|
$this->db->from('tbl_users as BaseTbl');
|
|
$this->db->join('tbl_roles as Roles','Roles.roleId = BaseTbl.roleId');
|
|
$this->db->join('t_employee_details as Emp','BaseTbl.EmpID = Emp.EmpID');
|
|
$this->db->join('t_departmentdetails as DEPT','Emp.Departmentcode = DEPT.DEPCode');
|
|
$this->db->where('BaseTbl.isDeleted !=',1);
|
|
$this->db->join('t_company_details as CompTbl','true','cross');
|
|
$this->db->where('BaseTbl.email', $email);
|
|
$this->db->or_where('Emp.ContactNumber', $email);
|
|
$this->db->where('BaseTbl.isDeleted !=',1);
|
|
|
|
$query = $this->db->get();
|
|
|
|
|
|
$user = $query->result();
|
|
if(!empty($user)){
|
|
if(verifyHashedPassword($password, $user[0]->password)){
|
|
return $user;
|
|
} else {
|
|
return array();
|
|
}
|
|
} else {
|
|
return array();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This function used to insert reset password data
|
|
* @param {array} $data : This is reset password data
|
|
* @return {boolean} $result : TRUE/FALSE
|
|
*/
|
|
function resetPasswordUser($data)
|
|
{
|
|
$result = $this->db->insert('tbl_reset_password', $data);
|
|
|
|
if($result) {
|
|
return TRUE;
|
|
} else {
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This function is used to get customer information by email-id for forget password email
|
|
* @param string $email : Email id of customer
|
|
* @return object $result : Information of customer
|
|
*/
|
|
function getCustomerInfoByEmail($email)
|
|
{
|
|
$this->db->select('userId, email, EmpID');
|
|
$this->db->from('tbl_users');
|
|
$this->db->where('isDeleted', 0);
|
|
$this->db->where('email', $email);
|
|
$query = $this->db->get();
|
|
|
|
return $query->result();
|
|
}
|
|
|
|
/**
|
|
* This function used to check correct activation deatails for forget password.
|
|
* @param string $email : Email id of user
|
|
* @param string $activation_id : This is activation string
|
|
*/
|
|
function checkActivationDetails($email, $activation_id)
|
|
{
|
|
$this->db->select('id');
|
|
$this->db->from('tbl_reset_password');
|
|
$this->db->where('email', $email);
|
|
$this->db->where('activation_id', $activation_id);
|
|
$query = $this->db->get();
|
|
return $query->num_rows;
|
|
}
|
|
|
|
// This function used to create new password by reset link
|
|
function createPasswordUser($email, $password)
|
|
{
|
|
$this->db->where('email', $email);
|
|
$this->db->where('isDeleted', 0);
|
|
$this->db->update('tbl_users', array('password'=>getHashedPassword($password)));
|
|
$this->db->delete('tbl_reset_password', array('email'=>$email));
|
|
}
|
|
|
|
/**
|
|
* This function used to check email exists or not
|
|
* @param {string} $email : This is users email id
|
|
* @return {boolean} $result : TRUE/FALSE
|
|
*/
|
|
function checkEmailExist($email)
|
|
{
|
|
$this->db->select('userId');
|
|
$this->db->where('email', $email);
|
|
$this->db->where('isDeleted', 0);
|
|
$query = $this->db->get('tbl_users');
|
|
|
|
if ($query->num_rows() > 0){
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function Accessdep($EmpID)
|
|
{
|
|
|
|
$this->db->select('Departmentcode as AssDep');
|
|
$this->db->from('t_accessdepartments');
|
|
$this->db->where('EmpID', $EmpID);
|
|
|
|
|
|
$query = $this->db->get();
|
|
// print_r( $this->db->last_query());
|
|
return $query->result();
|
|
}
|
|
/**
|
|
* get the user dtl
|
|
*/
|
|
function getuserid($mobileno,$emailid)
|
|
{
|
|
$this->db->select('UsrTbl.userId,UsrTbl.email,EmpTbl.ContactNumber,EmpTbl.FirstName');
|
|
$this->db->from('tbl_users as UsrTbl');
|
|
$this->db->join('t_employee_details as EmpTbl','UsrTbl.EmpID = EmpTbl.EmpID');
|
|
$this->db->where('EmpTbl.ContactNumber', $mobileno);
|
|
$this->db->where('UsrTbl.email',$emailid);
|
|
$this->db->where('UsrTbl.isDeleted', 0);
|
|
$res = $this->db->get();
|
|
return $res->result();
|
|
|
|
}
|
|
|
|
/**
|
|
* To update opt in our database
|
|
**/
|
|
function temp2($userId,$otp){
|
|
$this->db->set('OTP',$otp);
|
|
$this->db->where('userId',$userId);
|
|
$this->db->update('tbl_users');
|
|
$count = $this->db->affected_rows();
|
|
|
|
if($count > 0)
|
|
{
|
|
$subQuery = "select OTP from tbl_users where userId = '".$userId."'";
|
|
$query = $this->db->query($subQuery);
|
|
return $query->result();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* To get user id
|
|
**/
|
|
function getuserdtl($phno){
|
|
$this->db->select('BaseTbl.userId');
|
|
$this->db->from('tbl_users as BaseTbl');
|
|
$this->db->join('t_employee_details as Emp','BaseTbl.EmpID = Emp.EmpID');
|
|
$this->db->where('Emp.ContactNumber', $phno);
|
|
$query = $this->db->get();
|
|
$result = $query->result();
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* To update password and otp
|
|
**/
|
|
function resetpassword($Array,$userid){
|
|
|
|
$this->db->where('userId',$userid);
|
|
$this->db->update('tbl_users',$Array);
|
|
$count = $this->db->affected_rows();
|
|
return $count;
|
|
|
|
}
|
|
|
|
/**
|
|
* To update password only
|
|
**/
|
|
function updatepassword($userid,$password){
|
|
|
|
$this->db->set('password',$password);
|
|
$this->db->where('userId',$userid);
|
|
$this->db->update('tbl_users');
|
|
$count = $this->db->affected_rows();
|
|
return $count;
|
|
|
|
}
|
|
|
|
}
|
|
?>
|