function handle_register_request() { # Get session ID if (!isset($_COOKIE["vf_session_id"])) { return new WP_Error("verifyne", "No active session. Please try again."); } # Construct purpose global $current_user; get_currentuserinfo(); $blog_title = get_bloginfo('name'); $username = $current_user->user_login; $purpose = "Connect identity with Wordpress account: " . $username . "@" . $blog_title; # Load a new QR code and inject the javascript logic $ticket_data = Wordpress_Verifyne_API::get_new_ticket($purpose); # Check for errors if (is_wp_error($ticket_data)) { return $ticket_data; } $tid = $ticket_data["ticketid"]; # Store session id as transient, valid for 15 minutes set_transient($tid, array("session" => $_COOKIE["vf_session_id"], "ticket" => $ticket_data, 900)); # Show QR image print "<div class='verifyne-qr-container'><img class='verifyne-qr-image' src='" . $ticket_data["qr"] . "'></div>"; # Show status DIV print "<div id='verifyne-state-div'>Ready</div>"; # Which page to load if the ticket has been authenticated $authenticated_redir = add_query_arg(array("action" => "vf_verify", "ticketid" => urlencode($tid))); # When a ticket expired we just call vf_show again to generate a new ticket $expired_redir = add_query_arg("action", "vf_register"); # Inject JavaScript logic Wordpress_Verifyne_API::print_javascript_logic($ticket_data["ticketid"], $authenticated_redir, $expired_redir); }
/** * Called when the user clicked the verifyne button to show the QR code. * * @return Nothing. Prints an error message on the page if something goes wrong. */ function handle_show_request() { # Get blog title $blog_title = get_bloginfo('name'); # Construct purpose $purpose = "Wordpress Login to " . $blog_title; # Load a new QR code $ticket_data = Wordpress_Verifyne_API::get_new_ticket($purpose); # Check for errors if (is_wp_error($ticket_data)) { print "<div id='verifyne-state-div' class='verifyne-center'>" . $ticket_data->get_error_message() . "</div>"; return; } $tid = $ticket_data["ticketid"]; # Store session id as transient, valid for 15 minutes set_transient($tid, array("session" => $_COOKIE["vf_session_id"], "ticket" => $ticket_data, 900)); # Which page to load if the ticket has been authenticated $authenticated_redir = add_query_arg(array("action" => "vf_verify", "ticketid" => urlencode($tid))); # When a ticket expired we just call vf_show again to generate a new ticket $expired_redir = add_query_arg("action", "vf_show"); ?> <div class='verifyne-qr-container verifyne-center'> <img class='verifyne-qr-image' src='<?php echo $ticket_data["qr"]; ?> '> </div> <div id='verifyne-state-div' class='verifyne-center'>Ready</div> <?php # Inject JavaScript logic Wordpress_Verifyne_API::print_javascript_logic($tid, $authenticated_redir, $expired_redir); }