summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2012-03-27 20:14:38 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2012-03-27 20:15:34 +0200
commit285529a532743d52af94d3d571178a413dd944c8 (patch)
tree1d25919aba233f3cde3c98dfab0f987dafb878b0 /static
parent89e5ee140a4becefa4d4023102107727c5921efb (diff)
Implement BrowserID-based login.
Diffstat (limited to 'static')
-rw-r--r--static/js/browserid.js51
1 files changed, 51 insertions, 0 deletions
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});
+ }
+});