Skip to content
Snippets Groups Projects
AuthenticationController.php 1.03 KiB
Newer Older
  • Learn to ignore specific revisions
  • Florian Azizian's avatar
    Florian Azizian committed
    <?php
    
    /**
     * Copyright Maarch since 2008 under licence GPLv3.
     * See LICENCE.txt file at the root folder for more details.
     * This file is part of Maarch software.
     */
    
    /**
     * @brief Authentication Controller
     *
     * @author dev@maarch.org
     */
    
    namespace SrcCore\controllers;
    
    use SrcCore\models\AuthenticationModel;
    
    class AuthenticationController
    {
        public static function authentication()
        {
    
    Damien's avatar
    Damien committed
            $login = null;
    
    Florian Azizian's avatar
    Florian Azizian committed
            if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
    
                if (AuthenticationModel::authentication(['login' => $_SERVER['PHP_AUTH_USER'], 'password' => $_SERVER['PHP_AUTH_PW']])) {
    
    Damien's avatar
    Damien committed
                    $login = $_SERVER['PHP_AUTH_USER'];
    
    Florian Azizian's avatar
    Florian Azizian committed
                }
            } else {
                $cookie = AuthenticationModel::getCookieAuth();
                if (!empty($cookie) && AuthenticationModel::cookieAuthentication($cookie)) {
                    AuthenticationModel::setCookieAuth(['userId' => $cookie['userId']]);
    
    Damien's avatar
    Damien committed
                    $login = $cookie['userId'];
    
    Damien's avatar
    Damien committed
            return $login;