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
This commit is contained in:
josch 2008-08-15 00:55:22 +00:00
parent cd9b5f9565
commit 2cba7d55f9
2 changed files with 45 additions and 7 deletions

View file

@ -1,13 +1,51 @@
import logging import logging
from yolanda.lib.base import * from yolanda.lib.base import *
from openid.consumer.consumer import Consumer, SUCCESS, FAILURE, DiscoveryFailure
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class AccountController(BaseController): 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'

View file

@ -42,7 +42,7 @@
<h1>To upload videos, login.</h1> <h1>To upload videos, login.</h1>
${h.form(h.url_for('account_login'), method='post')} ${h.form(h.url_for('account/login'), method='post')}
${h.text_field('username')} ${h.text_field('username')}
${h.submit('Login (OpenID)')} ${h.submit('Login (OpenID)')}