/** * @since 1.0.0 */ public function verify_configuration_callback() { if (isset($_REQUEST['nonce']) && $this->wp_facade->wp_verify_nonce($_REQUEST['nonce'], static::VERIFIER_NONCE_KEY) && $this->wp_facade->current_user_can('manage_options')) { $user = $this->wp_facade->wp_get_current_user(); $response = array('nonce' => $this->wp_facade->wp_create_nonce(static::VERIFIER_NONCE_KEY)); if (stripos($_SERVER['REQUEST_METHOD'], 'POST') !== false && isset($_POST['verify_action']) && 'pair' === $_POST['verify_action']) { try { $white_label_user = $this->launchkey_client->whiteLabel()->createUser($user->user_login); $response['qrcode_url'] = $white_label_user->getQrCodeUrl(); $response['manual_code'] = $white_label_user->getCode(); } catch (Exception $e) { $response['error'] = $e->getCode(); } } elseif (stripos($_SERVER['REQUEST_METHOD'], 'POST') !== false) { $response['completed'] = false; try { $username = empty($_POST['username']) ? $user->user_login : $_POST['username']; $auth_request = $this->launchkey_client->auth()->authorize($username); $this->wp_facade->update_user_meta($user->ID, 'launchkey_username', $username); $this->wp_facade->update_user_meta($user->ID, 'launchkey_auth', $auth_request->getAuthRequestId()); $this->wp_facade->update_user_meta($user->ID, 'launchkey_authorized', null); } catch (Exception $e) { $response['error'] = $e->getCode(); } } else { $db = $this->wp_facade->get_wpdb(); $value = $db->get_var($db->prepare("SELECT meta_value FROM {$db->usermeta} WHERE user_id = %s AND meta_key = 'launchkey_authorized' LIMIT 1", $user->ID)); $response['completed'] = !empty($value); } $this->wp_facade->wp_send_json($response); } }
/** * Is the current session index registered. If so, this is a replay * @return bool Registered * @throws Exception DB errors throw exceptions */ public function is_session_index_registered() { $db = $this->facade->get_wpdb(); $query = $db->prepare("SELECT COUNT(*) FROM {$db->prefix}launchkey_sso_sessions WHERE id = %s", $this->get_session_index()); $count = $db->get_var($query); if ($db->last_error) { throw new Exception(sprintf("Database Error: %s", $db->last_error)); } return $count > 0; }
/** * @param $user_id * * @return boolean */ private function get_user_authorized($user_id) { $db = $this->wp_facade->get_wpdb(); $value = $db->get_var($db->prepare("SELECT meta_value FROM {$db->usermeta} WHERE user_id = %s AND meta_key = 'launchkey_authorized' LIMIT 1", $user_id)); if ('true' === $value) { $authorized = true; } elseif ('false' === $value) { $authorized = false; } else { $authorized = null; } return $authorized; }
public function test_get_wpdb_returns_global_wpdb() { global $wpdb; $wpdb = $this; $this->assertSame($this, $this->facade->get_wpdb()); }