224 lines
6.7 KiB
PHP
224 lines
6.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
use CodeIgniter\Database\BaseBuilder;
|
|
|
|
class Login_model extends 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
|
|
*/
|
|
public function loginMe($email, $password)
|
|
{
|
|
$builder = $this->db->table('tbl_users as BaseTbl')
|
|
->select('BaseTbl.userId, BaseTbl.password, Emp.EmpID, Emp.FirstName, Emp.Designation, BaseTbl.roleId, Roles.role, DEPT.DEPCode, DEPT.DepartmentName, DEPT.HeadDept, Emp.ProfilePic')
|
|
->join('tbl_roles as Roles', 'Roles.roleId = BaseTbl.roleId')
|
|
->join('t_employee_details as Emp', 'BaseTbl.EmpID = Emp.EmpID')
|
|
->join('t_departmentdetails as DEPT', 'Emp.Departmentcode = DEPT.DEPCode')
|
|
->where('BaseTbl.isDeleted !=', 1)
|
|
->where('BaseTbl.email', $email)
|
|
->orWhere('Emp.ContactNumber', $email)
|
|
->where('BaseTbl.isDeleted !=', 1);
|
|
|
|
|
|
$query = $builder->get();
|
|
|
|
|
|
if ($query->getNumRows() > 0) {
|
|
|
|
$user = $query->getResult();
|
|
|
|
$query = $this->db->table('t_company_details')->select('CompanyName')->get();
|
|
$result = $query->getRow();
|
|
$CompanyName = !empty($result) ? $result->CompanyName : '';
|
|
$addCompanyName = function ($u) use ($CompanyName) {
|
|
$u->CompanyName = $CompanyName;
|
|
return $u;
|
|
};
|
|
$user = array_map($addCompanyName, $user);
|
|
|
|
if (password_verify($password, $user[0]->password)) {
|
|
return $user;
|
|
} else {
|
|
return []; // Password doesn't match
|
|
}
|
|
} else {
|
|
return []; // No user found
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This function used to insert reset password data
|
|
* @param {array} $data : This is reset password data
|
|
* @return {boolean} $result : TRUE/FALSE
|
|
*/
|
|
function resetPasswordUser($data)
|
|
{
|
|
$builder = $this->db->table('tbl_reset_password');
|
|
$builder->insert($data);
|
|
if ($this->db->affectedRows() > 0) {
|
|
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)
|
|
{
|
|
$builder = $this->db->table('tbl_users');
|
|
$builder->select('userId, email, EmpID')
|
|
->from('tbl_users')
|
|
->where('isDeleted', 0)
|
|
->where('email', $email);
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
/**
|
|
* 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)
|
|
{
|
|
$builder = $this->db->table('tbl_reset_password');
|
|
$builder->select('id')
|
|
->where('email', $email)
|
|
->where('activation_id', $activation_id);
|
|
$query = $builder->get();
|
|
return $query->getNumRows();
|
|
}
|
|
|
|
// This function used to create new password by reset link
|
|
function createPasswordUser($email, $password)
|
|
{
|
|
|
|
$builder = $this->db->table('tbl_users')
|
|
->where('email', $email)
|
|
->where('isDeleted', 0)
|
|
->set('password', password_hash($password, PASSWORD_DEFAULT))
|
|
->update();
|
|
|
|
if ($this->db->affectedRows() > 0) {
|
|
$this->db->table('tbl_reset_password')->delete(['email' => $email]);
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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)
|
|
{
|
|
$builder = $this->db->table('tbl_users');
|
|
$builder->select('userId')
|
|
->where('email', $email)
|
|
->where('isDeleted', 0);
|
|
$countAll = $builder->countAll();
|
|
if ($countAll > 0) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function Accessdep($EmpID)
|
|
{
|
|
|
|
$builder = $this->db->table('t_accessdepartments')
|
|
->select('Departmentcode as AssDep')
|
|
->where('EmpID', $EmpID);
|
|
|
|
$query = $builder->get();
|
|
|
|
return $query->getResult();
|
|
}
|
|
/**
|
|
* get the user dtl
|
|
*/
|
|
function getuserid($mobileno, $emailid)
|
|
{
|
|
$builder = $this->db->table('tbl_users as UsrTbl');
|
|
$builder->select('UsrTbl.userId,UsrTbl.email,EmpTbl.ContactNumber,EmpTbl.FirstName')
|
|
->from('tbl_users as UsrTbl')
|
|
->join('t_employee_details as EmpTbl', 'UsrTbl.EmpID = EmpTbl.EmpID')
|
|
->where('EmpTbl.ContactNumber', $mobileno)
|
|
->where('UsrTbl.email', $emailid)
|
|
->where('UsrTbl.isDeleted', 0);
|
|
$res = $builder->get();
|
|
return $res->getResult();
|
|
}
|
|
|
|
/**
|
|
* To update otp in our database
|
|
**/
|
|
function temp2($userId, $otp)
|
|
{
|
|
$this->db->table('tbl_users')
|
|
->where('userId', $userId)
|
|
->set('OTP', $otp)
|
|
->update();
|
|
|
|
if ($this->db->affectedRows() > 0) {
|
|
$subQuery = "SELECT OTP FROM tbl_users WHERE userId = ?";
|
|
$query = $this->db->query($subQuery, [$userId]);
|
|
return $query->getResult();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* To get user id
|
|
**/
|
|
function getuserdtl($phno)
|
|
{
|
|
$builder = $this->db->table('tbl_users as BaseTbl')
|
|
->select('BaseTbl.userId')
|
|
->join('t_employee_details as Emp', 'BaseTbl.EmpID = Emp.EmpID')
|
|
->where('Emp.ContactNumber', $phno);
|
|
$query = $builder->get();
|
|
$result = $query->getResult();
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* To update password and otp
|
|
**/
|
|
function resetpassword($Array, $userid)
|
|
{
|
|
|
|
$this->db->table('tbl_users')
|
|
->where('userId', $userid)
|
|
->update($Array);
|
|
$count = $this->db->affectedRows();
|
|
return $count;
|
|
}
|
|
|
|
/**
|
|
* To update password only
|
|
**/
|
|
function updatepassword($userid, $password)
|
|
{
|
|
|
|
$this->db->table('tbl_users')
|
|
->where('userId', $userid)
|
|
->set('password', $password)
|
|
->update();
|
|
$count = $this->db->affectedRows();
|
|
return $count;
|
|
}
|
|
} |