Node.js Recipes: A Problem-Solution Approach by Cory Gackenheimer

Node.js Recipes: A Problem-Solution Approach by Cory Gackenheimer

Author:Cory Gackenheimer [Gackenheimer, Cory]
Language: eng
Format: epub, pdf
Tags: Computers, Web, Web Programming, Programming Languages, General
ISBN: 9781430260585
Google: 1efBnQEACAAJ
Amazon: 1430260580
Publisher: Apress
Published: 2013-10-16T04:00:00+00:00


Listing 6-23. Binding to a Persona Login and Logout

document.querySelector("#login").addEventListener("click", function() {

navigator.id.request();

}, false);

document.querySelector("#logout").addEventListener("click", function() {

navigator.id.logout();

}, false);

Persona also needs you to implement a watch function that will listen for these events. When one is detected, it will send an XMLHttpRequest to the /persona/verify or /persona/logout routes in your Express.js application.

Listing 6-24. Persona Navigator watch Method

navigator.id.watch({

onlogin: function(assertion) {

var xhr = new XMLHttpRequest();

xhr.open("POST", "/persona/verify", true);

xhr.setRequestHeader("Content-Type", "application/json");

xhr.addEventListener("loadend", function(e) {

var data = JSON.parse(this.responseText);

if (data && data.status === "okay") {

console.log("You have been logged in as: " + data.email);

}

}, false);



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.