From 5ac8b0c9422e17740c3dd1df3e8123bd0234da1e Mon Sep 17 00:00:00 2001 From: Eevee Date: Thu, 6 May 2010 00:04:37 -0700 Subject: [PATCH] Split login form off to a separate page, with some explanation. --- spline/plugins/users/__init__.py | 1 + spline/plugins/users/controllers/accounts.py | 32 +++++++++++--- spline/plugins/users/templates/users/login.mako | 51 ++++++++++++++++++++++ .../users/templates/widgets/user_state.mako | 6 +-- 4 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 spline/plugins/users/templates/users/login.mako diff --git a/spline/plugins/users/__init__.py b/spline/plugins/users/__init__.py index 4ce4465..f0c8a33 100644 --- a/spline/plugins/users/__init__.py +++ b/spline/plugins/users/__init__.py @@ -14,6 +14,7 @@ import spline.plugins.users.model def add_routes_hook(map, *args, **kwargs): """Hook to inject some of our behavior into the routes configuration.""" # Login, logout + map.connect('/accounts/login', controller='accounts', action='login') map.connect('/accounts/login_begin', controller='accounts', action='login_begin') map.connect('/accounts/login_finish', controller='accounts', action='login_finish') map.connect('/accounts/logout', controller='accounts', action='logout') diff --git a/spline/plugins/users/controllers/accounts.py b/spline/plugins/users/controllers/accounts.py index e38a4cd..5f7ef20 100644 --- a/spline/plugins/users/controllers/accounts.py +++ b/spline/plugins/users/controllers/accounts.py @@ -2,6 +2,7 @@ import logging from openid.consumer.consumer import Consumer from openid.extensions.sreg import SRegRequest, SRegResponse from openid.store.filestore import FileOpenIDStore +from openid.yadis.discover import DiscoveryFailure from sqlalchemy.orm.exc import NoResultFound from pylons import config, request, response, session, tmpl_context as c, url @@ -19,17 +20,36 @@ class AccountsController(BaseController): openid_store = FileOpenIDStore('/var/tmp') - def index(self): - # Return a rendered template - # return render('/template.mako') - # or, Return a response - return str(request.headers) + request.environ.get('scheme', '') + def _bail(self, reason): + # Used for bailing on a login attempt; reshows the login page + c.error = reason + c.attempted_openid = request.params.get('openid', '') + return render('/users/login.mako') + + + def login(self): + c.error = None + c.attempted_openid = None + return render('/users/login.mako') def login_begin(self): """Step one of logging in with OpenID; we redirect to the provider""" cons = Consumer(session=session, store=self.openid_store) - auth_request = cons.begin(request.params['openid']) + + try: + openid_url = request.params['openid'] + except KeyError: + return self._bail("Gotta enter an OpenID to log in.") + + try: + auth_request = cons.begin(openid_url) + except DiscoveryFailure: + return self._bail( + "Can't connect to '{0}'. You sure it's an OpenID?" + .format(openid_url) + ) + sreg_req = SRegRequest(optional=['nickname', 'email', 'dob', 'gender', 'country', 'language', 'timezone']) auth_request.addExtension(sreg_req) diff --git a/spline/plugins/users/templates/users/login.mako b/spline/plugins/users/templates/users/login.mako new file mode 100644 index 0000000..13bb0bc --- /dev/null +++ b/spline/plugins/users/templates/users/login.mako @@ -0,0 +1,51 @@ +<%inherit file="/base.mako" /> +<%def name="title()">Log in + +

Log in with OpenID

+ +% if c.error: +

${c.error}

+% endif + +${h.form(url(controller='accounts', action='login_begin'), id='user')} + + + +${h.end_form()} + + +

Oh my god what is this I am so confused

+ +

Sorry! Let me explain real quick.

+ +

Instead of having to register with a username and password on every site, the idea of OpenID is that you register on one site, and then use that to log in everywhere else.

+ +

You don't need a separate ID card for everything you do in real life, because you can show a government ID, and the government confirms that they already know who you are. This is pretty much the same thing.

+ +

Enter the URL to a site you own in the login box, and I'll go ask that site if it knows who you are. (Most sites will also ask you to confirm that you want to login here.) If it says yes, you're logged in here.

+ +

There's no registration, either; just log in, and you'll be registered.

+ +

Here are some common sites that support OpenID login:

+ +
+
LiveJournal
+
http://username.livejournal.com/
+
AOL/AIM
+
http://openid.aol.com/screenname
+
Blogger
+
http://blogname.blogspot.com/
+
Flickr
+
http://www.flickr.com/username
+
Yahoo!
+
http://www.yahoo.com/
+
Google
+
+ http://www.google.com/accounts/o8/id
+ You can also use http://www.google.com/profiles/username, but first you have to enable it at the bottom of this page. +
+
+ +

Yeah, Yahoo! and Google are kinda weird. Wikipedia has a more comprehensive list.

+ +

If you don't use any of these sites, you can also get a login from a dedicated OpenID provider.

diff --git a/spline/plugins/users/templates/widgets/user_state.mako b/spline/plugins/users/templates/widgets/user_state.mako index 06c6e70..86995dc 100644 --- a/spline/plugins/users/templates/widgets/user_state.mako +++ b/spline/plugins/users/templates/widgets/user_state.mako @@ -5,9 +5,5 @@ ${h.form(url(controller='accounts', action='logout'), id='user')} ${h.end_form()} % else: -${h.form(url(controller='accounts', action='login_begin'), id='user')} - - - -${h.end_form()} +

Log in or register

% endif -- 2.7.4