Пример #1
0
/**
 * Init user
 *
 * @return boolean always true
 */
function fn_init_user()
{
    if (!empty($_SESSION['auth']['user_id'])) {
        $user_info = fn_get_user_short_info($_SESSION['auth']['user_id']);
        if (empty($user_info)) {
            // user does not exist in the database, but exists in session
            $_SESSION['auth'] = array();
        } else {
            $_SESSION['auth']['usergroup_ids'] = fn_define_usergroups(array('user_id' => $_SESSION['auth']['user_id'], 'user_type' => $user_info['user_type']));
        }
    }
    $first_init = false;
    if (empty($_SESSION['auth'])) {
        $udata = array();
        if (fn_get_cookie(AREA_NAME . '_user_id')) {
            $udata = db_get_row("SELECT user_id, user_type, tax_exempt, last_login FROM ?:users WHERE user_id = ?i AND password = ?s", fn_get_cookie(AREA_NAME . '_user_id'), fn_get_cookie(AREA_NAME . '_password'));
            fn_define('LOGGED_VIA_COOKIE', true);
        }
        $_SESSION['auth'] = fn_fill_auth($udata, isset($_SESSION['auth']['order_ids']) ? $_SESSION['auth']['order_ids'] : array());
        if (!defined('NO_SESSION')) {
            $_SESSION['cart'] = isset($_SESSION['cart']) ? $_SESSION['cart'] : array();
        }
        if (defined('LOGGED_VIA_COOKIE') && !empty($_SESSION['auth']['user_id']) || ($cu_id = fn_get_cookie('cu_id'))) {
            $first_init = true;
            if (!empty($cu_id)) {
                fn_define('COOKIE_CART', true);
            }
            // Cleanup cached shipping rates
            unset($_SESSION['shipping_rates']);
            $_utype = empty($_SESSION['auth']['user_id']) ? 'U' : 'R';
            $_uid = empty($_SESSION['auth']['user_id']) ? $cu_id : $_SESSION['auth']['user_id'];
            fn_extract_cart_content($_SESSION['cart'], $_uid, 'C', $_utype);
            fn_save_cart_content($_SESSION['cart'], $_uid, 'C', $_utype);
            if (!empty($_SESSION['auth']['user_id'])) {
                $_SESSION['cart']['user_data'] = fn_get_user_info($_SESSION['auth']['user_id']);
            }
        }
    }
    if (TIME > Registry::get('settings.cart_products_next_check')) {
        fn_define('CART_PRODUCTS_CHECK_PERIOD', SECONDS_IN_HOUR * 12);
        fn_define('CART_PRODUCTS_DELETE_TIME', TIME - SECONDS_IN_DAY * 30);
        db_query("DELETE FROM ?:user_session_products WHERE user_type = 'U' AND timestamp < ?i", CART_PRODUCTS_DELETE_TIME);
        db_query("UPDATE ?:settings SET value = ?s WHERE option_name = 'cart_products_next_check'", TIME + CART_PRODUCTS_CHECK_PERIOD);
    }
    // If administrative account has usergroup, it means the access restrictions are in action
    if (AREA == 'A' && !empty($_SESSION['auth']['usergroup_ids'])) {
        fn_define('RESTRICTED_ADMIN', true);
    }
    if (!empty($user_info) && $user_info['user_type'] == 'A') {
        if (Registry::get('settings.translation_mode') == 'Y') {
            fn_define('TRANSLATION_MODE', true);
        }
        if (Registry::get('settings.customization_mode') == 'Y') {
            if (AREA != 'A') {
                fn_define('PARSE_ALL', true);
            }
            fn_define('CUSTOMIZATION_MODE', true);
        }
    }
    fn_set_hook('user_init', $_SESSION['auth'], $user_info, $first_init);
    Registry::set('user_info', $user_info);
    Registry::get('view')->assign('auth', $_SESSION['auth']);
    Registry::get('view')->assign('user_info', $user_info);
    return true;
}
Пример #2
0
/**
 * Init user
 *
 * @return boolean always true
 */
function fn_init_user($area = AREA)
{
    $user_info = array();
    if (!empty(Tygh::$app['session']['auth']['user_id'])) {
        $user_info = fn_get_user_short_info(Tygh::$app['session']['auth']['user_id']);
        if (empty($user_info)) {
            // user does not exist in the database, but exists in session
            Tygh::$app['session']['auth'] = array();
        } else {
            Tygh::$app['session']['auth']['usergroup_ids'] = fn_define_usergroups(array('user_id' => Tygh::$app['session']['auth']['user_id'], 'user_type' => $user_info['user_type']));
        }
    }
    $first_init = false;
    if (empty(Tygh::$app['session']['auth'])) {
        $udata = array();
        $user_id = fn_get_session_data($area . '_user_id');
        if ($area == 'A' && defined('CONSOLE')) {
            $user_id = 1;
        }
        if ($user_id) {
            fn_define('LOGGED_VIA_COOKIE', true);
        }
        fn_login_user($user_id);
        if (!defined('NO_SESSION')) {
            Tygh::$app['session']['cart'] = isset(Tygh::$app['session']['cart']) ? Tygh::$app['session']['cart'] : array();
        }
        if (defined('LOGGED_VIA_COOKIE') && !empty(Tygh::$app['session']['auth']['user_id']) || ($cu_id = fn_get_session_data('cu_id'))) {
            $first_init = true;
            if (!empty($cu_id)) {
                fn_define('COOKIE_CART', true);
            }
            // Cleanup cached shipping rates
            unset(Tygh::$app['session']['shipping_rates']);
            $_utype = empty(Tygh::$app['session']['auth']['user_id']) ? 'U' : 'R';
            $_uid = empty(Tygh::$app['session']['auth']['user_id']) ? $cu_id : Tygh::$app['session']['auth']['user_id'];
            fn_extract_cart_content(Tygh::$app['session']['cart'], $_uid, 'C', $_utype);
            fn_save_cart_content(Tygh::$app['session']['cart'], $_uid, 'C', $_utype);
            if (!empty(Tygh::$app['session']['auth']['user_id'])) {
                Tygh::$app['session']['cart']['user_data'] = fn_get_user_info(Tygh::$app['session']['auth']['user_id']);
                $user_info = fn_get_user_short_info(Tygh::$app['session']['auth']['user_id']);
            }
        }
    }
    if (fn_is_expired_storage_data('cart_products_next_check', SECONDS_IN_HOUR * 12)) {
        db_query("DELETE FROM ?:user_session_products WHERE user_type = 'U' AND timestamp < ?i", TIME - SECONDS_IN_DAY * 30);
    }
    if (!fn_allowed_for('ULTIMATE:FREE')) {
        // If administrative account has usergroup, it means the access restrictions are in action
        if ($area == 'A' && !empty(Tygh::$app['session']['auth']['usergroup_ids'])) {
            fn_define('RESTRICTED_ADMIN', true);
        }
    }
    if (!empty($user_info) && $user_info['user_type'] == 'A' && (empty($user_info['company_id']) || fn_allowed_for('ULTIMATE') && $user_info['company_id'] == Registry::get('runtime.company_id'))) {
        $customization_mode = fn_array_combine(explode(',', Registry::get('settings.customization_mode')), true);
        if (!empty($customization_mode)) {
            Registry::set('runtime.customization_mode', $customization_mode);
            if ($area == 'A' || Embedded::isEnabled()) {
                Registry::set('runtime.customization_mode.live_editor', false);
            }
        }
    }
    fn_set_hook('user_init', Tygh::$app['session']['auth'], $user_info, $first_init);
    Registry::set('user_info', $user_info);
    return array(INIT_STATUS_OK);
}
Пример #3
0
function fn_fill_auth($user_data = array(), $original_auth = array(), $act_as_user = false, $area = AREA)
{
    $active_usergroups = fn_define_usergroups($user_data, $area);
    $ip = fn_get_ip();
    $auth = array('area' => !fn_check_user_type_admin_area($user_data) ? 'C' : 'A', 'user_id' => empty($user_data['user_id']) ? 0 : $user_data['user_id'], 'user_type' => !empty($user_data['user_type']) ? $user_data['user_type'] : 'C', 'tax_exempt' => empty($user_data['tax_exempt']) ? 'N' : $user_data['tax_exempt'], 'last_login' => empty($user_data['last_login']) ? 0 : $user_data['last_login'], 'order_ids' => !empty($original_auth['order_ids']) ? $original_auth['order_ids'] : array(), 'password_change_timestamp' => empty($user_data['password_change_timestamp']) ? 0 : $user_data['password_change_timestamp'], 'company_id' => empty($user_data['company_id']) ? 0 : $user_data['company_id'], 'is_root' => empty($user_data['is_root']) ? 'N' : $user_data['is_root'], 'usergroup_ids' => $active_usergroups, 'act_as_user' => $act_as_user, 'this_login' => !empty($original_auth['this_login']) ? $original_auth['this_login'] : TIME, 'referer' => !empty($original_auth['referer']) ? $original_auth['referer'] : (!empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''), 'ip' => $ip['host']);
    if (Registry::get('runtime.simple_ultimate')) {
        unset($auth['company_id']);
    }
    fn_set_hook('fill_auth', $auth, $user_data, $area, $original_auth);
    return $auth;
}
Пример #4
0
function fn_fill_auth($user_data = array(), $order_ids = array(), $act_as_user = false, $area = AREA)
{
    $active_usergroups = fn_define_usergroups($user_data, $area);
    $_auth = array('area' => empty($user_data['user_type']) || $user_data['user_type'] != 'A' ? 'C' : $user_data['user_type'], 'user_id' => empty($user_data['user_id']) ? 0 : $user_data['user_id'], 'tax_exempt' => empty($user_data['tax_exempt']) ? 'N' : $user_data['tax_exempt'], 'last_login' => empty($user_data['last_login']) ? 0 : $user_data['last_login'], 'usergroup_ids' => $active_usergroups, 'order_ids' => $order_ids, 'act_as_user' => $act_as_user, 'this_login' => TIME, 'password_change_timestamp' => empty($user_data['password_change_timestamp']) ? 0 : $user_data['password_change_timestamp'], 'company_id' => empty($user_data['company_id']) ? 0 : $user_data['company_id'], 'is_root' => empty($user_data['is_root']) ? 'N' : $user_data['is_root'], 'referer' => !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
    fn_set_hook('fill_auth', $_auth, $user_data);
    return $_auth;
}