/** * Check if the current Glome ID is paired to a wallet */ function glome_is_session_paired() { $ret = false; $data = glome_get_user_profile(); if (isset($data['inwallet'])) { $ret = $data['inwallet'] == 'true'; } return $ret; }
/** * Where it all begins; hooked to the init phase */ function glome_start() { $token = $glomeid = $current_user = false; global $post; if (session_status() != PHP_SESSION_ACTIVE) { $_SESSION['glome'] = array(); session_start(); } // we don't save this into DB or file, no need to sanitze further if (isset($_POST['one_time_access'])) { $_SESSION['glome'] = glome_create_user(); } if (array_key_exists('glome', $_SESSION) and array_key_exists('token', $_SESSION['glome']) and array_key_exists('glomeid', $_SESSION['glome'])) { $token = $_SESSION['glome']['token']; $glomeid = $_SESSION['glome']['glomeid']; } if (array_key_exists('magic', $_COOKIE) and strlen($_COOKIE['magic']) > 12) { // this is set after a succesful identification with Glome key if (array_key_exists('key', $_SESSION['glome'])) { $key = substr($_COOKIE['magic'], 0, 12); if ($_SESSION['glome']['key']['code'] == $key) { $token = substr($_COOKIE['magic'], 12, 32); $glomeid = substr($_COOKIE['magic'], 44); } } } if ($token and $glomeid) { if (mywp_user_exists($token) === false) { mywp_create_user($token, $glomeid); } mywp_login_user($token, $glomeid); setcookie('magic', '', time() - 3600); /* delete */ redirect_if_needed(); } // check Glome session $ret = glome_get_user_profile(); if ($ret) { // is the Glome user locked? $_SESSION['glome'] = $ret; if (isset($ret['code'])) { switch ($ret['code']) { case 403: case 2301: $ret = null; break; } } } if (is_user_logged_in()) { $current_user = wp_get_current_user(); } if ($current_user && $ret == null) { if (!is_super_admin($current_user->ID)) { //logout from Wordpress wp_logout(); header('Location: /exit'); exit; } } if (get_option('glome_activity_tracking')) { if ($current_user && $current_user->has_prop('glomeid') && $current_user->get('allow_tracking_me') == 1) { glome_track_activity($_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]); redirect_if_needed(); } } return; }