comparison example/persona.html @ 30:0bf52646061b

example/persona.html example/persona.py setup.py
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 27 Dec 2013 11:24:23 -0800
parents 1bcb72011872
children f462dc131d57
comparison
equal deleted inserted replaced
29:1bcb72011872 30:0bf52646061b
8 <meta http-equiv="X-UA-Compatible" content="IE=Edge"> 8 <meta http-equiv="X-UA-Compatible" content="IE=Edge">
9 9
10 <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> 10 <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
11 <script src="https://login.persona.org/include.js"></script> 11 <script src="https://login.persona.org/include.js"></script>
12 <script> 12 <script>
13
14 function onload() { 13 function onload() {
15 14
16 alert("page loaded!"); 15 //alert("page loaded!");
16
17 var currentUser = null;
18
19 navigator.id.watch({
20 loggedInUser: currentUser,
21 onlogin: function(assertion) {
22 // A user has logged in! Here you need to:
23 // 1. Send the assertion to your backend for verification and to create a session.
24 // 2. Update your UI.
25 $.ajax({
26 type: 'POST',
27 url: '/auth/login', // This is a URL on your website.
28 data: {assertion: assertion},
29 success: function(res, status, xhr) { window.location.reload(); },
30 error: function(xhr, status, err) {
31 navigator.id.logout();
32 alert("Login failure: " + err);
33 }
34 });
35 },
36 onlogout: function() {
37 // A user has logged out! Here you need to:
38 // Tear down the user's session by redirecting the user or making a call to your backend.
39 // Also, make sure loggedInUser will get set to null on the next page load.
40 // (That's a literal JavaScript null. Not false, 0, or undefined. null.)
41 $.ajax({
42 type: 'POST',
43 url: '/auth/logout', // This is a URL on your website.
44 success: function(res, status, xhr) { window.location.reload(); },
45 error: function(xhr, status, err) { alert("Logout failure: " + err); }
46 });
47 }
48 });
17 49
18 var signinLink = document.getElementById('signin'); 50 var signinLink = document.getElementById('signin');
19 if (signinLink) { 51 if (signinLink) {
20 signinLink.onclick = function() { navigator.id.request(); }; 52 signinLink.onclick = function() { navigator.id.request(); };
21 } 53 }
26 } 58 }
27 } 59 }
28 </script> 60 </script>
29 </head> 61 </head>
30 62
31 <body onload="onload()"> 63 <body>
32 <h1> 64 <h1>
33 <a href="https://login.persona.org/">Mozilla persona</a> 65 <a href="https://login.persona.org/">Mozilla persona</a>
34 <a href="http://k0s.org/hg/bitsyauth/">bitsyauth</a> 66 <a href="http://k0s.org/hg/bitsyauth/">bitsyauth</a>
35 test page 67 test page
36 </h1> 68 </h1>