summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
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});
+ }
+});