Mercurial > hg > bitsyauth
annotate example/persona.html @ 40:cb1d21648588
count clicks the hard way
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 27 Dec 2013 20:13:04 -0800 |
parents | 6b5946843928 |
children | d4522af2c6e5 |
rev | line source |
---|---|
23
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 <html> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 <head> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 <title>bistyauth Mozilla persona test page</title> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 <!-- Suppressing Compatability Mode for IE |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 https://developer.mozilla.org/en-US/Persona/Quick_Setup?redirectlocale=en-US&redirectslug=Persona%2FQuick_Setup#Suppressing_Compatibility_Mode --> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 <meta http-equiv="X-UA-Compatible" content="IE=Edge"> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 |
32 | 10 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> |
23
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 <script src="https://login.persona.org/include.js"></script> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 <script> |
40 | 13 var nclicks = 0; |
14 | |
33 | 15 $(document).ready(function() { |
28 | 16 |
30
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
17 var currentUser = null; |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
18 |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
19 navigator.id.watch({ |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
20 loggedInUser: currentUser, |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
21 onlogin: function(assertion) { |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
22 // A user has logged in! Here you need to: |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
23 // 1. Send the assertion to your backend for verification and to create a session. |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
24 // 2. Update your UI. |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
25 $.ajax({ |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
26 type: 'POST', |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
27 url: '/auth/login', // This is a URL on your website. |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
28 data: {assertion: assertion}, |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
29 success: function(res, status, xhr) { window.location.reload(); }, |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
30 error: function(xhr, status, err) { |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
31 navigator.id.logout(); |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
32 alert("Login failure: " + err); |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
33 } |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
34 }); |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
35 }, |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
36 onlogout: function() { |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
37 // A user has logged out! Here you need to: |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
38 // Tear down the user's session by redirecting the user or making a call to your backend. |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
39 // Also, make sure loggedInUser will get set to null on the next page load. |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
40 // (That's a literal JavaScript null. Not false, 0, or undefined. null.) |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
41 $.ajax({ |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
42 type: 'POST', |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
43 url: '/auth/logout', // This is a URL on your website. |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
44 success: function(res, status, xhr) { window.location.reload(); }, |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
45 error: function(xhr, status, err) { alert("Logout failure: " + err); } |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
46 }); |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
47 } |
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
48 }); |
28 | 49 |
23
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
50 var signinLink = document.getElementById('signin'); |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
51 if (signinLink) { |
40 | 52 signinLink.onclick = function() { navigator.id.request(); |
53 nclicks += 1; | |
54 $('clickcounter').append('<li>This is click ' + nclicks + '</li>'); | |
55 }; | |
23
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
56 } |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
57 |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
58 var signoutLink = document.getElementById('signout'); |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
59 if (signoutLink) { |
37
6b5946843928
example/persona.html example/wsgibrowserid.py
Jeff Hammel <jhammel@mozilla.com>
parents:
34
diff
changeset
|
60 signoutLink.onclick = function() { navigator.id.logout(); }; |
23
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
61 } |
33 | 62 }); |
23
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
63 </script> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
64 </head> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
65 |
30
0bf52646061b
example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents:
29
diff
changeset
|
66 <body> |
23
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
67 <h1> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
68 <a href="https://login.persona.org/">Mozilla persona</a> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
69 <a href="http://k0s.org/hg/bitsyauth/">bitsyauth</a> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
70 test page |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
71 </h1> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
72 |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
73 <div> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
74 <a id="signin">sign in</a> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
75 </div> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
76 |
40 | 77 <ul id="clickcounter"> |
78 </ul> | |
79 | |
23
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
80 <h2>Resources</h2> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
81 <ul> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
82 <li> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
83 <a href="https://developer.mozilla.org/en-US/Persona/branding"> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
84 branding |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
85 </a>: |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
86 buttons and what not |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
87 </li> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
88 </ul> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
89 |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
90 </body> |
21124b238feb
stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
91 </html> |