186 lines
4.8 KiB
PHP
Executable File
186 lines
4.8 KiB
PHP
Executable File
<?php
|
|
|
|
use App\Models\UserModel;
|
|
|
|
if(!function_exists('check_cookie')){
|
|
function check_cookie(){
|
|
$UserModel = new UserModel();
|
|
|
|
if(isset($_COOKIE['session_data'])){
|
|
$value = (array)json_decode($_COOKIE['session_data']);
|
|
$user = $UserModel->getUserByEmail($value['userData']->email);
|
|
if($user){
|
|
if($user->is_active !== '0'){
|
|
$user_team = $UserModel->getUserTeamsByUserID($user->id);
|
|
// dd($user_team);
|
|
|
|
$session_data = [
|
|
'isLoggedIn' => True ,
|
|
'userid' => $user->id,
|
|
'userData' => $user,
|
|
'userProfile' => $value['userProfile'],
|
|
'user_team' => $user_team,
|
|
];
|
|
set_session_data($session_data);
|
|
// $this->getUserDeviceInfo($user->id, 'NhanceUser');
|
|
// return redirect()->to(base_url('/dashboard/view'));
|
|
return true;
|
|
|
|
}
|
|
// $session_data = (array)json_decode($_COOKIE['session_data']);
|
|
// set_session_data($session_data);
|
|
}
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!function_exists('check_session')) {
|
|
function check_session()
|
|
{
|
|
// $ci =& get_instance();
|
|
$session = \Config\Services::session();
|
|
return $session->get('isLoggedIn');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('set_last_visited_time')) {
|
|
function set_last_visited_time()
|
|
{
|
|
$session = \Config\Services::session();
|
|
$session->set('last_visited', date("Y-m-d H:i:s"));
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_last_visited_time')) {
|
|
function get_last_visited_time()
|
|
{
|
|
// Get the session service
|
|
$session = \Config\Services::session();
|
|
|
|
// Get the last visited time from session
|
|
$lastVisitTime = $session->get('last_visited');
|
|
|
|
// Check if the last visited time is set
|
|
if ($lastVisitTime) {
|
|
// Calculate the time five minutes ago
|
|
$fiveMinutesBefore = date("YmdHi", strtotime('-5 minutes'));
|
|
|
|
// Compare the last visited time with the time five minutes ago
|
|
return date("YmdHi", strtotime($lastVisitTime)) > $fiveMinutesBefore ? 1 : 0;
|
|
}
|
|
|
|
// If last visited time is not set, return 0
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_session_userid')) {
|
|
function get_session_userid()
|
|
{
|
|
// $ci =& get_instance();
|
|
$session = \Config\Services::session();
|
|
return $session->get('userid');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_session_userdata')) {
|
|
function get_session_userdata()
|
|
{
|
|
// $ci =& get_instance();
|
|
$session = \Config\Services::session();
|
|
return $session->get('userData');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_userProfile')) {
|
|
function get_userProfile()
|
|
{
|
|
// $ci =& get_instance();
|
|
$session = \Config\Services::session();
|
|
return $session->get('userProfile');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_session_user')) {
|
|
function get_session_user()
|
|
{
|
|
// $ci =& get_instance();
|
|
$session = \Config\Services::session();
|
|
return $session->get('isLoggedIn');
|
|
}
|
|
}
|
|
|
|
|
|
if (!function_exists('check_role')) {
|
|
function check_role()
|
|
{
|
|
// $ci =& get_instance();
|
|
$session = \Config\Services::session();
|
|
return $session->get('role');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('check_permission')) {
|
|
function check_permission()
|
|
{
|
|
// $ci =& get_instance();
|
|
$session = \Config\Services::session();
|
|
return $session->get('role');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('set_session_uuid')) {
|
|
function set_session_uuid($uuid)
|
|
{
|
|
$session = \Config\Services::session();
|
|
$session->set('uuid', $uuid);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_session_uuid')) {
|
|
function get_session_uuid()
|
|
{
|
|
$session = \Config\Services::session();
|
|
return $session->get('uuid');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('set_session')) {
|
|
function set_session_data($data)
|
|
{
|
|
// $CI =& get_instance();
|
|
$session = \Config\Services::session();
|
|
$session->set($data);
|
|
}
|
|
}
|
|
|
|
|
|
if (!function_exists('set_session_context')) {
|
|
function set_session_context($context)
|
|
{
|
|
// $CI =& get_instance();
|
|
$session = \Config\Services::session();
|
|
$session->set('context',$context);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_session_context')) {
|
|
function get_session_context()
|
|
{
|
|
// $CI =& get_instance();
|
|
$session = \Config\Services::session();
|
|
return $session->get('context');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('user_team')) {
|
|
function user_team()
|
|
{
|
|
// $CI =& get_instance();
|
|
$session = \Config\Services::session();
|
|
return $session->get('user_team');
|
|
}
|
|
}
|