<?php
namespace Nibiru;
/**
 * Class    loginController
 * @project src
 * @desc    This is a PHP class file, please specify the use
 * @author  nibiru Framework
 * @date    Aug 17 2023
 * @time    16:11:34
 * @package Nibiru
 */
use Nibiru\Adapter\Controller;
use Nibiru\Module\{
    Users\Plugins\Acl,
    Users\Plugins\User,
    Users\Traits\NewUser
};
class loginController extends Controller
{
    private string $page;
    private object $user;
    private array $navigation;
    private object $acl;

    public function __construct()
    {
        $this->acl = new Acl();
        $this->user = new User();
        $this->user->validate();
        $this->page = Router::getInstance()->currentPage();
        if(!$this->user->checkForStandardUser())
        {
            $this->user->loadUser();
            $this->user->createStandardUser();
        }
        $this->navigation = JsonNavigation::getInstance()->loadCompleteNavigation("main");
    }
    public function pageAction()
    {
        // TODO: Implement pageAction() method.
    }

    public function navigationAction()
    {
        View::assign([
            'navigation' => $this->navigation,
            'current_path' => $_SERVER['REQUEST_URI']
        ]);
    }

    public function authAction()
    {
        if(!$this->user->isAuthorized())
        {
            View::assign([
                'loginForm' => $this->user->loginForm()
            ]);
        }
        else
        {
            View::forwardTo('/index');
        }
    }

    public function logoutAction()
    {
        $this->user->revokeAuthorized();
        View::forwardTo('/login');
    }
}
