Mercurial > hg > bitsyauth
changeset 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 | 6af220013aa1 |
files | example/persona.html example/persona.py setup.py |
diffstat | 3 files changed, 46 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/example/persona.html Thu Dec 26 23:44:43 2013 -0800 +++ b/example/persona.html Fri Dec 27 11:24:23 2013 -0800 @@ -10,10 +10,42 @@ <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> <script src="https://login.persona.org/include.js"></script> <script> - function onload() { -alert("page loaded!"); +//alert("page loaded!"); + +var currentUser = null; + +navigator.id.watch({ + loggedInUser: currentUser, + 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); } + }); + } +}); var signinLink = document.getElementById('signin'); if (signinLink) { @@ -28,7 +60,7 @@ </script> </head> -<body onload="onload()"> +<body> <h1> <a href="https://login.persona.org/">Mozilla persona</a> <a href="http://k0s.org/hg/bitsyauth/">bitsyauth</a>
--- a/example/persona.py Thu Dec 26 23:44:43 2013 -0800 +++ b/example/persona.py Fri Dec 27 11:24:23 2013 -0800 @@ -20,9 +20,14 @@ assert os.path.exists(self.page), "File '%s' not found" % self.page self.page = open(self.page, 'r').read() def __call__(self, environ, start_response): - start_response("200 OK", [('Content-Type', 'text/html'), - ('Content-Length', str(len(self.page)))]) - return [self.page] + method = environ['REQUEST_METHOD'] + if method == 'GET': + start_response("200 OK", [('Content-Type', 'text/html'), + ('Content-Length', str(len(self.page)))]) + body = self.page + elif method == 'POST': + body = '\n'.join([]) + return [body] def main(args=sys.argv[1:]):
--- a/setup.py Thu Dec 26 23:44:43 2013 -0800 +++ b/setup.py Fri Dec 27 11:24:23 2013 -0800 @@ -1,4 +1,4 @@ -from setuptools import setup, find_packages +from setuptools import setup version = '0.1.2' @@ -13,7 +13,7 @@ author_email='k0scist@gmail.com', url='http://k0s.org/hg/bitsyauth', license='GPL', - packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), + packages=['bitsyauth'], include_package_data=True, zip_safe=False, install_requires=['Paste', @@ -21,6 +21,7 @@ 'markup', # TO DEPRECATE 'skimpygimpy', 'PyBrowserID', + 'WebOb', ], dependency_links=[ 'http://svn.pythonpaste.org/Paste/trunk#egg=Paste',