annotate example/persona.html @ 41:d4522af2c6e5

refactor
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 28 Dec 2013 12:56:06 -0800
parents cb1d21648588
children 54a53bbe5be9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
f462dc131d57 example/persona.html
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
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
cb1d21648588 count clicks the hard way
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
13 var nclicks = 0;
cb1d21648588 count clicks the hard way
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
14
33
67439bcdac48 example/persona.html
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
15 $(document).ready(function() {
28
0f57029d663d example/persona.html
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
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
0f57029d663d example/persona.html
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
49
41
d4522af2c6e5 refactor
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
50
23
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
51 var signinLink = document.getElementById('signin');
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
52 if (signinLink) {
41
d4522af2c6e5 refactor
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
53 signinLink.onclick = function() {
d4522af2c6e5 refactor
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
54 navigator.id.request();
40
cb1d21648588 count clicks the hard way
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
55 nclicks += 1;
41
d4522af2c6e5 refactor
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
56 $('#clickcounter').append('<li>This is click ' + nclicks + '</li>');
40
cb1d21648588 count clicks the hard way
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
57 };
23
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
58 }
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
59
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
60 var signoutLink = document.getElementById('signout');
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
61 if (signoutLink) {
37
6b5946843928 example/persona.html example/wsgibrowserid.py
Jeff Hammel <jhammel@mozilla.com>
parents: 34
diff changeset
62 signoutLink.onclick = function() { navigator.id.logout(); };
23
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
63 }
33
67439bcdac48 example/persona.html
Jeff Hammel <jhammel@mozilla.com>
parents: 32
diff changeset
64 });
23
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
65 </script>
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
66 </head>
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
67
30
0bf52646061b example/persona.html example/persona.py setup.py
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
68 <body>
23
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
69 <h1>
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
70 <a href="https://login.persona.org/">Mozilla persona</a>
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
71 <a href="http://k0s.org/hg/bitsyauth/">bitsyauth</a>
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
72 test page
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
73 </h1>
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
74
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 <a id="signin">sign in</a>
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
77 </div>
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
78
40
cb1d21648588 count clicks the hard way
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
79 <ul id="clickcounter">
cb1d21648588 count clicks the hard way
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
80 </ul>
cb1d21648588 count clicks the hard way
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
81
23
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
82 <h2>Resources</h2>
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
83 <ul>
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
84 <li>
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
85 <a href="https://developer.mozilla.org/en-US/Persona/branding">
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
86 branding
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
87 </a>:
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
88 buttons and what not
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
89 </li>
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
90 </ul>
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
91
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
92 </body>
21124b238feb stub persona/browserid example
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
93 </html>