<?php

namespace App\Controllers\Auth;

use App\Controllers\BaseController;
use CodeIgniter\Controller;
use Config\Services;


class AuthController extends BaseController 
{
	
	public function initController($request, $response, $logger)
    {
        parent::initController($request, $response, $logger);
		$this->init();
    }

	public function init(){
		
		$this->data['validation'] = null;
		$this->data['userdata'] = $this->authloginModel->getUserDetails($this->session->get('logged_user'));
		$this->userdata = $this->authloginModel->getUserDetails($this->session->get('logged_user'));
		$this->session->set('loggedIn', true);

		$this->data['mynotifications'] = $this->notificationsModel->getTotalUserAlerts($this->userdata->user_id);
		$this->data['countries']    = $this->countryModel->getAll();
		$this->data['currencies']	= $this->currencyModel->getAll();
			
		if (!session()->get('loggedIn'))
        {
            return redirect()
                ->to('account/login');
        }
		
		
	}

	
	//Check Login 
	protected function checkLoggedIn()
	{
		if (!session()->get('loggedIn')) {
			return redirect()->to('account/login');
		}
	}
	
	
	public function logout()
	{
		$this->session = session();
		$this->session->setTempdata('success', 'You have <strong>logged out</strong> successfully.', 1);
        $this->session->remove('logged_user');
        $this->session->remove('loggedIn', true);
		return redirect()->to('account/login');
		$this->session->destroy();
		return redirect()->to('account/login');
	}
}