changeset 49:8358634e3d75

bitsyauth/js/persona.js example/persona.html
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 30 Dec 2013 20:00:02 -0800
parents d66d6c10cfe4
children 5517ac16c9fb
files bitsyauth/js/persona.js example/persona.html
diffstat 2 files changed, 34 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/bitsyauth/js/persona.js
+++ b/bitsyauth/js/persona.js
@@ -1,41 +1,45 @@
 // setup Mozilla persona
 // requires: jquery
 
-function persona(loggedInUser) {
-  navigator.id.watch({
-  loggedInUser: loggedInUser,
-  onlogin: function(assertion) {
-    // A user has logged in! Here you need to:
-    // 1. Send the assertion to your backend for verification and to create a session.
-    // 2. Update your UI.
-    $.ajax({type: 'POST',
-            url: '/auth/login', // This is a URL on your website.
-            data: {assertion: assertion},
-            success: function(res, status, xhr) { window.location.reload(); },
-            error: function(xhr, status, err) {
-                navigator.id.logout();
-                alert("Login failure: " + err);
-            }
-           });
-  },
-  onlogout: function() {
-    // A user has logged out! Here you need to:
-    // Tear down the user's session by redirecting the user or making a call to your backend.
-    // Also, make sure loggedInUser will get set to null on the next page load.
-    // (That's a literal JavaScript null. Not false, 0, or undefined. null.)
-    //    $.ajax({
-    //  type: 'POST',
-    //  url: '/auth/logout', // This is a URL on your website.
-    //  success: function(res, status, xhr) { window.location.reload(); },
-    //  error: function(xhr, status, err) { alert("Logout failure: " + err); }
-    // });
-  }});
+function persona(loggedInUser, onloginURL, onlogoutURL) {
 
+
+    navigator.id.watch({loggedInUser: loggedInUser,
+                        onlogin: function(assertion) {
+                            // A user has logged in! Here you need to:
+                            // 1. Send the assertion to your backend for verification and to create a session.
+                            // 2. Update your UI.
+                            $.ajax({type: 'POST',
+                                    url: onloginURL, // This is a URL on your website.
+                                    data: {assertion: assertion},
+                                    success: function(res, status, xhr) { window.location.reload(); },
+                                    error: function(xhr, status, err) {
+                                        navigator.id.logout();
+                                        alert("Login failure: " + err);
+                                    }
+                                   });
+                        },
+                        onlogout: function() {
+                            // A user has logged out! Here you need to:
+                            // Tear down the user's session by redirecting the user or making a call to your backend.
+                            // Also, make sure loggedInUser will get set to null on the next page load.
+                            // (That's a literal JavaScript null. Not false, 0, or undefined. null.)
+                            $.ajax({type: 'POST',
+                                    url: onlogoutURL, // This is a URL on your website.
+                                    success: function(res, status, xhr) { window.location.reload(); },
+                                    error: function(xhr, status, err) {
+                                        alert("Logout failure: " + err);
+                                    }
+                                   });
+                        }
+                       });
+
+  // 
   var signinLink = document.getElementById('signin');
   if (signinLink) {
       signinLink.onclick = function() {
           navigator.id.request();
       };
   }
 
   var signoutLink = document.getElementById('signout');
--- a/example/persona.html
+++ b/example/persona.html
@@ -6,19 +6,17 @@
 <!-- Suppressing Compatability Mode for IE
 https://developer.mozilla.org/en-US/Persona/Quick_Setup?redirectlocale=en-US&redirectslug=Persona%2FQuick_Setup#Suppressing_Compatibility_Mode -->
 <meta http-equiv="X-UA-Compatible" content="IE=Edge">
 
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
 <script src="https://login.persona.org/include.js"></script>
 <script>
 $(document).ready(function() {
-
-var currentUser = null;
-
+});
 </script>
 </head>
 
 <body>
 <h1>
 <a href="https://login.persona.org/">Mozilla persona</a>
 <a href="http://k0s.org/hg/bitsyauth/">bitsyauth</a>
 test page