diff --git a/trunk/yolanda/controllers/account.py b/trunk/yolanda/controllers/account.py index cb9a7b5..1e6b838 100644 --- a/trunk/yolanda/controllers/account.py +++ b/trunk/yolanda/controllers/account.py @@ -1,13 +1,51 @@ import logging - from yolanda.lib.base import * +from openid.consumer.consumer import Consumer, SUCCESS, FAILURE, DiscoveryFailure log = logging.getLogger(__name__) class AccountController(BaseController): + def __before__(self): + self.openid_session = session.get("openid_session", {}) + + # @validate(schema=something, form='login') + def login(self): + #FIXME: do not operate in stateless mode - replace store with local + # openid store (app global) to make login faster with less overhead + self.consumer = Consumer(self.openid_session, None) + openid = request.params.get('username', None) + if openid is None: + return render('/login/form.mako') + try: + authrequest = self.consumer.begin(openid) + except DiscoveryFailure, e: + return render('/login/form.mako') + + redirecturl = authrequest.redirectURL( + h.url_for('',qualified=True), + return_to=h.url_for('/account/verified',qualified=True), + immediate=False + ) + session['openid_session'] = self.openid_session + session.save() + return redirect_to(redirecturl) + + def verified(self): + #FIXME: do not operate in stateless mode - replace store with local + # openid store (app global) to make login faster with less overhead + self.consumer = Consumer(self.openid_session, None) + info = self.consumer.complete(request.params, (h.url_for('/account/verified', qualified=True))) + if info.status == SUCCESS: + session['openid'] = info.identity_url + session.save() + session.clear() + return redirect_to('/index') + else: + return redirect_to('/login') + + def logout(self): + c.title = 'logged out' + session.clear() + session.save() + return render('/login/logout.mako') - def index(self): - # Return a rendered template - # return render('/some/template.mako') - # or, Return a response - return 'account' diff --git a/trunk/yolanda/templates/xhtml/base.mako b/trunk/yolanda/templates/xhtml/base.mako index 8c8b924..a1ae017 100644 --- a/trunk/yolanda/templates/xhtml/base.mako +++ b/trunk/yolanda/templates/xhtml/base.mako @@ -42,7 +42,7 @@