Split login form off to a separate page, with some explanation.
authorEevee <git@veekun.com>
Thu, 6 May 2010 07:04:37 +0000 (00:04 -0700)
committerEevee <git@veekun.com>
Thu, 6 May 2010 07:04:37 +0000 (00:04 -0700)
spline/plugins/users/__init__.py
spline/plugins/users/controllers/accounts.py
spline/plugins/users/templates/users/login.mako [new file with mode: 0644]
spline/plugins/users/templates/widgets/user_state.mako

index 4ce4465..f0c8a33 100644 (file)
@@ -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')
index e38a4cd..5f7ef20 100644 (file)
@@ -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 (file)
index 0000000..13bb0bc
--- /dev/null
@@ -0,0 +1,51 @@
+<%inherit file="/base.mako" />
+<%def name="title()">Log in</%def>
+
+<h1>Log in with OpenID</h1>
+
+% if c.error:
+<p class="error">${c.error}</p>
+% endif
+
+${h.form(url(controller='accounts', action='login_begin'), id='user')}
+    <img src="${h.static_uri('spline', 'icons/openid.png')}">
+    <input type="text" name="openid" size="30" value="${c.attempted_openid or ''}">
+    <input type="submit" value="Log in">
+${h.end_form()}
+
+
+<h1>Oh my god what is this I am so confused</h1>
+
+<p>Sorry!  Let me explain real quick.</p>
+
+<p>Instead of having to register with a username and password on every site, the idea of <a href="https://openid.net/">OpenID</a> is that you register on <em>one</em> site, and then use <em>that</em> to log in everywhere else.</p>
+
+<p>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.</p>
+
+<p>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.</p>
+
+<p>There's no registration, either; just log in, and you'll be registered.</p>
+
+<p>Here are some common sites that support OpenID login:</p>
+
+<dl>
+    <dt>LiveJournal</dt>
+    <dd>http://<code>username</code>.livejournal.com/</dd>
+    <dt>AOL/AIM</dt>
+    <dd>http://openid.aol.com/<code>screenname</code></dd>
+    <dt>Blogger</dt>
+    <dd>http://<code>blogname</code>.blogspot.com/</dd>
+    <dt>Flickr</dt>
+    <dd>http://www.flickr.com/<code>username</code></dd>
+    <dt>Yahoo!</dt>
+    <dd>http://www.yahoo.com/</dd>
+    <dt>Google</dt>
+    <dd>
+        http://www.google.com/accounts/o8/id <br>
+        You can also use http://www.google.com/profiles/<code>username</code>, but first you have to enable it at the bottom of <a href="http://www.google.com/profiles/me/editprofile?edit=t">this page</a>.
+    </dd>
+</dl>
+
+<p>Yeah, Yahoo! and Google are kinda weird.  Wikipedia has a <a href="http://en.wikipedia.org/wiki/List_of_OpenID_providers">more comprehensive list</a>.</p>
+
+<p>If you don't use any of these sites, you can also get a login from a <a href="http://openid.net/get-an-openid">dedicated OpenID provider</a>.</p>
index 06c6e70..86995dc 100644 (file)
@@ -5,9 +5,5 @@ ${h.form(url(controller='accounts', action='logout'), id='user')}
     <input type="submit" value="Log out">
 ${h.end_form()}
 % else:
-${h.form(url(controller='accounts', action='login_begin'), id='user')}
-    <img src="${h.static_uri('spline', 'icons/openid.png')}">
-    <input type="text" name="openid" size="30">
-    <input type="submit" value="Log in">
-${h.end_form()}
+<p id="user"><a href="${url(controller='accounts', action='login')}">Log in or register</a></p>
 % endif