Esempio n. 1
0
function action_login()
{
    global $DETDB;
    if (check_login() && action_check_login()) {
        replace_page('index');
    }
    if (isset($_POST['form_login'])) {
        $checker = actions_zone('login_check');
        if (!in_array(false, $checker, true)) {
            $login = $_POST['form_login'];
            if ($user = $DETDB->select('users', 'ID, login, password, salt', true, "WHERE login='******'")) {
                $password = md5($_POST['form_password']);
                if (crypt($password, $user->salt) == $user->password) {
                    setcookie('user_ID', $user->ID, time() + get_option('cookie_login_live'), '/');
                    $hash = random_hash(10);
                    setcookie('user_hash', $hash, time() + get_option('cookie_login_live'), '/');
                    if ($DETDB->update('users', array('hash' => $hash, 'last_ip' => $_SERVER['REMOTE_ADDR'], 'last_activity' => date('c'), 'last_agent' => $_SERVER['HTTP_USER_AGENT']), "WHERE ID='" . $user->ID . "'")) {
                        $_COOKIE['user_ID'] = $user->ID;
                        $_COOKIE['user_hash'] = $hash;
                        $url = isset($_COOKIE['from_page']) ? $_COOKIE['from_page'] : 'index';
                        destroy_cookie('from_page');
                        int_user();
                        if (make_action('check_login')) {
                            replace_page($url);
                        }
                    }
                }
            }
            if (!$user || !isset($hash)) {
                push_output_message(array('text' => 'Неверный логин или пароль', 'title' => 'Ошибка!', 'class' => 'alert alert-danger', 'type' => 'error'));
            }
        }
    }
}
Esempio n. 2
0
function check_login($full = false)
{
    global $USER, $DETDB;
    if ($full) {
        $t = false;
        if (isset($_COOKIE['user_ID']) && isset($_COOKIE['user_hash'])) {
            $check_plus = get_option('admin_check_login');
            $cond = array(array('param' => 'ID', 'value' => $_COOKIE['user_ID']), array('param' => 'hash', 'value' => $_COOKIE['user_hash']));
            if (isset($check_plus['login_ip']) && $check_plus['login_ip']) {
                $cond[] = array('param' => 'last_ip', 'value' => $_SERVER['REMOTE_ADDR']);
            }
            if (isset($check_plus['login_agent']) && $check_plus['login_agent']) {
                $cond[] = array('param' => 'last_agent', 'value' => $_SERVER['HTTP_USER_AGENT']);
            }
            if ($DETDB->select('users', 'ID', true, $cond)) {
                $t = true;
            } else {
                destroy_cookie('user_ID');
                destroy_cookie('user_hash');
            }
        }
        return $t;
    } else {
        return isset($USER->check) && $USER->check;
    }
}
Esempio n. 3
0
function login_cookie_destroy()
{
    if (!login_cookie_isset()) {
        return;
    }
    $cookie = login_cookie_decode();
    db_delete('cookie_tokens', array('token' => $cookie['t'], 'token_series' => $cookie['ts']));
    destroy_cookie(CONST_COOKIE_NAME);
}
Esempio n. 4
0
if (isset($_COOKIE['reload_message']) && check_json($_COOKIE['reload_message'])) {
    $message = json_decode($_COOKIE['reload_message'], true);
    if (!is_array($message)) {
        $message = array('warning', $message, 'Внимание!');
    }
    if ($message[1]) {
        if ($message[0] == 'reload') {
            $message[0] = 'success';
        }
        if (!isset($message[2])) {
            $message[2] = 'Внимание!';
        }
        push_output_message(array('title' => $message[2], 'type' => $message[0], 'text' => $message[1], 'class' => "message-generate alert alert-{$message[0]}"));
    }
    unset($message);
    destroy_cookie('reload_message');
}
actions_zone('before_form_page');
//Формирование страницы
if (is_ajax()) {
    $PAGE->code = 'ajax_call';
} elseif (is_remote()) {
    $PAGE->code = 'remote_call';
} elseif (!$PAGE->code) {
    $key = get_current_key();
    $PAGE->title = $APAGES[$key]->title;
    $PAGE->code = $key;
}
uasort($APAGES, 'collector_sort');
foreach ($APAGES as $item) {
    if (count($item->childs) > 1) {