public static function getInstance() { if (empty(self::$instance)) { $additional_settings = RublonHelper::getSettings('additional'); $current_user = wp_get_current_user(); self::$instance = new self(RublonHelper::getRublon(), RublonHelper::getUserId($current_user), RublonHelper::getUserEmail($current_user), $logout_listener = RublonHelper::isLogoutListenerEnabled()); // Embed consumer script if (RublonHelper::isSiteRegistered()) { add_action('wp_footer', array(self::$instance, 'renderConsumerScript'), PHP_INT_MAX); add_action('admin_footer', array(self::$instance, 'renderConsumerScript'), PHP_INT_MAX); } } return self::$instance; }
/** * Check mobile app status of a single WP user * * @param WP_User $user * @return string RublonHelper constant */ public function checkMobileStatus($user) { $user_id = RublonHelper::getUserId($user); $user_email = RublonHelper::getUserEmail($user); require_once dirname(__FILE__) . '/libs/RublonImplemented/RublonAPICheckProtection.php'; $check = new RublonAPICheckProtection($this->rublon, $user_id, $user_email); try { $check->perform(); } catch (RublonException $e) { $check = null; } if (!empty($check) && $check->isProtectionEnabled($user_id)) { $mobile_user_status = RublonHelper::YES; } else { $mobile_user_status = RublonHelper::NO; } return $mobile_user_status; }
protected function getUserId() { $current_user = wp_get_current_user(); return RublonHelper::getUserId($current_user); }
static function confirm(RublonConfirmStrategy $strategy, $dataKey) { try { $rublon = RublonHelper::getRublon(); $authUrl = $rublon->confirm(RublonHelper::getActionURL('confirm'), RublonHelper::getUserId(), RublonHelper::getUserEmail(), $strategy->getConfirmMessage(), self::getConfirmParams($strategy, $dataKey)); } catch (ForbiddenMethod_RublonAPIException $e) { RublonConfirmations::abortConfirmation('FORBIDDEN_METHOD'); } catch (RublonException $e) { // echo $e->getClient()->getRawRequest();exit; RublonHelper::_handleCallbackException($e); RublonConfirmations::abortConfirmation('API_ERROR'); } if (!empty($authUrl)) { wp_redirect($authUrl); exit; } else { // Why empty? if ($roleProtectionType == RublonHelper::PROTECTION_TYPE_MOBILE) { // Mobile App is required: RublonConfirmations::abortConfirmation('MOBILE_APP_REQUIRED'); } else { // Rublon is not working at this moment or user is not protected: self::redirectParentFrame($_SERVER['REQUEST_URI'], $strategy->getAction(), __('Please wait.', 'rublon'), $dataKey); } } }
/** * * @deprecated * @TODO remove function * @param unknown $errors * @param unknown $update * @param unknown $user */ function rublon2factor_user_profile_update_errors(&$errors, $update, &$user) { global $pagenow; if (RublonHelper::isSiteRegistered()) { $current_user = wp_get_current_user(); $current_user_id = RublonHelper::getUserId($current_user); $updated_user_id = !empty($user->ID) ? $user->ID : $user->Id; if ($pagenow == RublonHelper::WP_PROFILE_PAGE && $current_user_id == $updated_user_id && empty($errors->errors) && $update) { if (!empty($_POST)) { $post = $_POST; RublonHelper::checkPostDataProfileUpdate($post); } } } }
/** * Prepares the Rublon auth cookie data * * @param WP_User $user User whose data will be hashed into the cookie * @param int $expiration * @param string $plugin_version * @return string */ private static function _prepareAuthCookieData($user, $expiration, $plugin_version = '2.0.2') { $user_id = RublonHelper::getUserId($user); $settings = RublonHelper::getSettings(); if (version_compare($plugin_version, '2.0.2', 'lt')) { $user_login = $user->user_login; $user_data = $user_login . $user_id; $cookie_data = hash_hmac('SHA256', $user_data, $settings['rublon_secret_key']); } else { $pass_frag = substr($settings['rublon_secret_key'], 8, 4); $key = wp_hash($user->user_login . '|' . $pass_frag . '|' . $expiration, 'auth'); $hash = hash_hmac('SHA256', $user->user_login . '|' . $expiration, $key); $cookie_data = $user->user_login . '|' . $expiration . '|' . $hash; } return $cookie_data; }