/** * Callback handler to process white label pairing via AJAX * * @since 1.0.0 */ public function white_label_pair_callback() { if (isset($_POST['nonce'])) { // If there is no nonce, ignore the request if ($this->wp_facade->wp_verify_nonce($_POST['nonce'], LaunchKey_WP_User_Profile::NONCE_KEY)) { // If there is a valid nonce if ($user = $this->wp_facade->wp_get_current_user()) { // and a current logged in user try { // Create a LaunchKey White Label user with the WordPress username as the unique identifer $pair_response = $this->launchkey_client->whiteLabel()->createUser($user->user_login); // Set the WordPress username as the LaunchKey username for subsequent login attempts $this->wp_facade->update_user_meta($user->ID, 'launchkey_username', $user->user_login); // Set up the response with the QR Code URL and manual pairing codes $response = array('qrcode' => $pair_response->getQrCodeUrl(), 'code' => $pair_response->getCode()); } catch (\LaunchKey\SDK\Service\Exception\CommunicationError $e) { // Communication error response $response = array('error' => 'There was a communication error encountered during the pairing process. Please try again later'); } catch (\LaunchKey\SDK\Service\Exception\InvalidCredentialsError $e) { // Invalid credentials response $response = array('error' => 'There was an error encountered during the pairing process caused by a misconfiguration. Please contact the administrator.'); } catch (\Exception $e) { // General error response $response = array('error' => 'There was an error encountered during the pairing process. Please contact the administrator.'); } // Add a new nonce to the response to allow another request $response['nonce'] = $this->wp_facade->wp_create_nonce(LaunchKey_WP_User_Profile::NONCE_KEY); // Set the headers for the AJAX response $this->wp_facade->wp_send_json($response); } } } }
/** * Compile the data that will be used by the front end to generate a QR Code for WordPress auto-config. * @since 1.4.0 */ public function wizard_easy_setup_qr_code() { if (isset($_POST['nonce'])) { if ($this->wp_facade->wp_verify_nonce($_POST['nonce'], static::WIZARD_NONCE_KEY) && $this->wp_facade->current_user_can('manage_options')) { $lk_nonce = $this->launchkey_client->auth()->nonce(); $this->update_option(static::EASY_SETUP_OPTION, array('nonce' => $lk_nonce, 'username' => $this->wp_facade->wp_get_current_user()->user_login)); $payload = json_encode(array('nonce' => $lk_nonce->getNonce(), 'payload' => array('callback_url' => $this->admin->get_callback_url(), 'rocket_name' => $this->wp_facade->get_bloginfo('name')))); $qr_data = base64_encode($payload); $response['nonce'] = $this->wp_facade->wp_create_nonce(static::WIZARD_NONCE_KEY); $response['qr_code'] = $qr_data; } else { $response['errors'] = $this->wp_facade->__("An error occurred submitting the page. Please refresh the page and submit again."); } $this->wp_facade->wp_send_json($response); } }
public function wizard_submit_ajax() { if (isset($_POST['nonce'])) { if ($this->wp_facade->wp_verify_nonce($_POST['nonce'], static::WIZARD_NONCE_KEY)) { list($options, $errors) = $this->admin->check_option($_POST); if ($errors) { $response["errors"] = $errors; } else { $this->wp_facade->update_option(LaunchKey_WP_Admin::OPTION_KEY, $options); } $response['nonce'] = $this->wp_facade->wp_create_nonce(static::WIZARD_NONCE_KEY); } else { $response["errors"] = $this->wp_facade->__("An error occurred submitting the page. Please refresh the page and submit again."); } $this->wp_facade->wp_send_json($response); } }