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 request, response, session, tmpl_context as c, url, h
-from pylons.controllers.util import abort, redirect
+from pylons import request, response, session, tmpl_context as c, url
+from pylons.controllers.util import abort, redirect, redirect_to
from routes import url_for, request_config
from floof.lib.base import BaseController, render
+import floof.lib.helpers as h
from floof.model.users import IdentityURL, User
log = logging.getLogger(__name__)
openid_store = FileOpenIDStore('/var/tmp')
def login(self):
+ c.bogus_identity_url = request.params.get('bogus_identity_url', None)
return render('/account/login.mako')
def login_begin(self):
"""Step one of logging in with OpenID; we redirect to the provider"""
+ identity_url = request.params['identity_url']
cons = Consumer(session=session, store=self.openid_store)
- auth_request = cons.begin(request.params['identity_url'])
+ try:
+ auth_request = cons.begin(identity_url)
+ except DiscoveryFailure:
+ redirect_to(controller='account', action='login',
+ bogus_identity_url=identity_url)
+
sreg_req = SRegRequest(optional=['nickname', 'email', 'dob', 'gender',
'country', 'language', 'timezone'])
auth_request.addExtension(sreg_req)
input[type='button'], input[type='submit'], input[type='reset'] { cursor: pointer; }
+/* Misc. classes */
+.error { color: #c00000; font-weight: bold; }
+
/* General form layout */
dl.form { margin: 1em 0; padding-left: 1em; border-left: 0.5em solid gray; }
dl.form dt { padding-bottom: 0.25em; font-style: italic; }
/* Login */
form#big-login { text-align: center; }
form#big-login input { font-size: 2em; margin: 0 auto; }
-form#big-login input#identity-url { width: 20em; padding-left: 16px; }
+form#big-login input#identity-url { width: 20em; }
dl#openid_examples { overflow: hidden /* new float context */; }
dl#openid_examples > dt { float: left; clear: left; width: 15.5em; margin-right: 0.5em; text-align: right; color: #2457a0; }
<p>You can log in or register with any <a href="http://openid.net/"><img src="/icons/openid.png" alt=""> OpenID</a>.</p>
<form action="${url(controller='account', action='login_begin')}" method="POST" id="big-login">
+% if c.bogus_identity_url:
+<p class="error">This isn't a valid OpenID, sorry.</p>
+% endif
<p>
- <input type="text" name="identity_url" id="identity-url">
+ <input type="text" name="identity_url" id="identity-url" value="${c.bogus_identity_url}">
<input type="submit" value="Log in">
</p>
</form>