Mercurial > hg > bitsyauth
comparison example/persona.html @ 45:54a53bbe5be9
bitsyauth/__init__.py example/persona.html
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Sun, 29 Dec 2013 20:20:38 -0800 |
| parents | d4522af2c6e5 |
| children | d66d6c10cfe4 |
comparison
equal
deleted
inserted
replaced
| 44:158b469a10e9 | 45:54a53bbe5be9 |
|---|---|
| 20 loggedInUser: currentUser, | 20 loggedInUser: currentUser, |
| 21 onlogin: function(assertion) { | 21 onlogin: function(assertion) { |
| 22 // A user has logged in! Here you need to: | 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. | 23 // 1. Send the assertion to your backend for verification and to create a session. |
| 24 // 2. Update your UI. | 24 // 2. Update your UI. |
| 25 $.ajax({ | 25 $.ajax({type: 'POST', |
| 26 type: 'POST', | 26 url: '/auth/login', // This is a URL on your website. |
| 27 url: '/auth/login', // This is a URL on your website. | 27 data: {assertion: assertion}, |
| 28 data: {assertion: assertion}, | 28 success: function(res, status, xhr) { window.location.reload(); }, |
| 29 success: function(res, status, xhr) { window.location.reload(); }, | 29 error: function(xhr, status, err) { |
| 30 error: function(xhr, status, err) { | 30 navigator.id.logout(); |
| 31 navigator.id.logout(); | 31 alert("Login failure: " + err); |
| 32 alert("Login failure: " + err); | 32 } |
| 33 } | |
| 34 }); | 33 }); |
| 35 }, | 34 }, |
| 36 onlogout: function() { | 35 onlogout: function() { |
| 37 // A user has logged out! Here you need to: | 36 // 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. | 37 // 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. | 38 // 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.) | 39 // (That's a literal JavaScript null. Not false, 0, or undefined. null.) |
| 41 $.ajax({ | 40 // $.ajax({ |
| 42 type: 'POST', | 41 // type: 'POST', |
| 43 url: '/auth/logout', // This is a URL on your website. | 42 // url: '/auth/logout', // This is a URL on your website. |
| 44 success: function(res, status, xhr) { window.location.reload(); }, | 43 // success: function(res, status, xhr) { window.location.reload(); }, |
| 45 error: function(xhr, status, err) { alert("Logout failure: " + err); } | 44 // error: function(xhr, status, err) { alert("Logout failure: " + err); } |
| 46 }); | 45 // }); |
| 47 } | 46 } |
| 48 }); | 47 }); |
| 49 | 48 |
| 50 | 49 |
| 51 var signinLink = document.getElementById('signin'); | 50 var signinLink = document.getElementById('signin'); |
