From 285529a532743d52af94d3d571178a413dd944c8 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 27 Mar 2012 20:14:38 +0200 Subject: Implement BrowserID-based login. --- static/js/browserid.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 static/js/browserid.js (limited to 'static') diff --git a/static/js/browserid.js b/static/js/browserid.js new file mode 100644 index 0000000..dce8d42 --- /dev/null +++ b/static/js/browserid.js @@ -0,0 +1,51 @@ +// -*- js-indent-level: 2 -*- + +jQuery(function($) { + var loggedIn = function(res) { + console.log(res); + if (res.returnURI) { + window.location.assign(res.returnURI); + } else { + window.location.reload(true); + } + }; + var loggedOut = function(res) { + }; + + var gotAssertion = function(assertion) { + // got an assertion, now send it up to the server for verification + if (assertion) { + $.ajax({ + type: 'POST', + url: '/login/browserid/verify', + data: { assertion: assertion }, + success: function(res, status, xhr) { + if (res === null) { + loggedOut(); + } + else { + loggedIn(res); + } + }, + error: function(res, status, xhr) { + //console.log(res); + //console.log(status); + alert("Whoops, I failed to authenticate you! " + res.responseText); + } + }); + } else { + loggedOut(); + } + } + + $('#browserid').click(function() { + navigator.id.get(gotAssertion, {allowPersistent: true}); + return false; + }); + + // Query persistent login. + var login = $('head').attr('data-logged-in'); + if (login === "false") { + navigator.id.get(gotAssertion, {silent: true}); + } +}); -- cgit v1.2.3