Beispiel #1
0
function mso_auth($OPTIONS)
{
    // дефолтные опции
    $def_options = array('username' => 'admin', 'password' => 'admin', 'session' => 'firstauthenticate', 'logout_link' => 'logout', 'login_link' => 'login');
    // объединяем с переданными
    $OPTIONS = array_merge($def_options, $OPTIONS);
    $url_redirect = (isset($_SERVER['HTTP_REFERER']) and $_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
    // вход
    if (mso_url_request(false, $OPTIONS['login_link'])) {
        if (!isset($_SESSION)) {
            session_start();
        }
        mso_auth_dialog($OPTIONS);
        if (mso_is_auth($OPTIONS)) {
            $_SESSION[$OPTIONS['session']] = 1;
            mso_set_val('auth', true);
            if ($url_redirect) {
                header('Location:' . $url_redirect);
            }
        }
    }
    // выход
    if (mso_url_request(false, $OPTIONS['logout_link'])) {
        if (!isset($_SESSION)) {
            session_start();
        }
        if (isset($_SESSION[$OPTIONS['session']])) {
            unset($_SESSION[$OPTIONS['session']]);
        }
        mso_set_val('auth', false);
        if ($url_redirect) {
            header('Location:' . $url_redirect);
        }
    }
    mso_set_val('auth', mso_is_auth($OPTIONS));
    // сохраняем реальное значение авторизации
}
Beispiel #2
0
function mso_auth($text_login = '******', $OPTIONS = true)
{
    // дефолтные опции
    $def_options = array('username' => 'admin', 'password' => 'admin', 'logout_link' => 'logout', 'login_link' => 'login', 'login_form' => CURRENT_PAGE_DIR . 'auth/auth-login-form.php', 'text_error' => 'Ошибочные данные');
    // если $OPTIONS === true, то загружаем из auth/auth-options.php текущей page
    if ($OPTIONS === true) {
        $OPTIONS = mso_load_options(CURRENT_PAGE_DIR . 'auth/auth-options.php');
    }
    // объединяем с переданными
    $OPTIONS = array_merge($def_options, $OPTIONS);
    // все редиректы на эту же страницу без ?-get
    $url_redirect = mso_current_url(false, true, true);
    // признак отображения формы
    $show_form = false;
    // вход
    if (mso_url_request(false, $OPTIONS['login_link'])) {
        // если есть post, то проверяем данные
        if ($_POST and isset($_POST['flogin_user']) and isset($_POST['flogin_password']) and isset($_POST['flogin_submit'])) {
            // сравниваем логин и пароль
            if (strcmp($_POST['flogin_user'], $OPTIONS['username']) == 0 and strcmp($_POST['flogin_password'], $OPTIONS['password']) == 0) {
                // равно
                if (!isset($_SESSION)) {
                    session_start();
                }
                $_SESSION['username'] = $OPTIONS['username'];
                $_SESSION['password'] = $OPTIONS['password'];
                // все ок!
                header('Location:' . $url_redirect);
            } else {
                // не равно
                echo $OPTIONS['text_error'];
                // ошибочные данные
                $show_form = true;
            }
        } else {
            // нет post
            // если уже есть залогиненость, то редиректим
            if (mso_is_auth($OPTIONS)) {
                header('Location:' . $url_redirect);
            }
            $show_form = true;
            // выводим форму
        }
    } elseif (mso_url_request(false, $OPTIONS['logout_link'])) {
        if (!isset($_SESSION)) {
            session_start();
        }
        if (isset($_SESSION['username'])) {
            unset($_SESSION['username']);
        }
        if (isset($_SESSION['password'])) {
            unset($_SESSION['password']);
        }
        header('Location:' . $url_redirect);
    }
    if ($show_form) {
        if (file_exists($OPTIONS['login_form'])) {
            require $OPTIONS['login_form'];
        } else {
            mso_auth_form();
        }
    }
    // если нет авторизации, то выводим сслыку на ВХОД
    if (strpos($_SERVER['REQUEST_URI'], '?') === FALSE) {
        if (!mso_is_auth($OPTIONS)) {
            echo $text_login;
        }
    }
    if (mso_is_auth($OPTIONS)) {
        return $OPTIONS;
    } else {
        return false;
    }
}