2.0.2 • Published 11 years ago

docpad-plugin-persona v2.0.2

Weekly downloads
8
License
-
Repository
github
Last release
11 years ago

IN PROGRESS. NON-FUNCTIONAL.

docpad-plugin-persona

The express-persona npm module as a docpad plugin.

Mozilla Persona, formerly called BrowserID, is self described as: "a cross-browser login system for the Web that's easy to use and easy to deploy. It works on all major browsers, and you can get started today."

This docpad plugin uses jsdom to query the DOM for ".persona-btn" on the renderDocument docpad event. If it finds it, it'll create a script tag that is the express-persona script:

var loginButton = document.querySelectorAll('.persona-btn');

loginButton.addEventListener("click", function() {
  navigator.id.get(function(assertion) {
    if (!assertion) {
      return;
    }

    var xhr = new XMLHttpRequest();
    xhr.open("POST", "/persona/verify", true);
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.addEventListener("loadend", function(e) {
      try {
        var data = JSON.parse(this.response);
        if (data.status === "okay") {
          // the email address the user logged in with
          console.log(data.email);
        } else {
          console.log("Login failed because " + data.reason);
        }
      } catch (ex) {
        // oh no, we didn't get valid JSON from the server
      }
    }, false);
    xhr.send(JSON.stringify({
      assertion: assertion
    }));
  });
}, false);

The "Sign in" button comes in three color options:

Along with a script tag being created, a link tag will be created as well linking the appripiate css file to create a CSS3 Sign In button.


Dependencies

License

Licensed under the incredibly permissive MIT License Copyright © 2013 MDM Inc.