From 2cba7d55f9f270c552ca76d427ca65a1bcde12ec Mon Sep 17 00:00:00 2001 From: josch Date: Fri, 15 Aug 2008 00:55:22 +0000 Subject: [PATCH] added basic openid - need error message output for further work git-svn-id: http://yolanda.mister-muffin.de/svn@370 7eef14d0-6ed0-489d-bf55-20463b2d70db --- trunk/yolanda/controllers/account.py | 50 ++++++++++++++++++++++--- trunk/yolanda/templates/xhtml/base.mako | 2 +- 2 files changed, 45 insertions(+), 7 deletions(-) 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 @@

To upload videos, login.

- ${h.form(h.url_for('account_login'), method='post')} + ${h.form(h.url_for('account/login'), method='post')} ${h.text_field('username')} ${h.submit('Login (OpenID)')}