ria/application/models/login_model.php
2018-03-12 12:02:30 +05:30

129 lines
3.9 KiB
PHP

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class Login_model extends CI_Model
{
/**
* 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');
$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.email', $email);
$this->db->or_where('Emp.ContactNumber', $email);
$this->db->where('BaseTbl.isDeleted', 0);
$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();
}
}
?>