From 08afa969049393059e6a5694f4c1662e13e66cff Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Sun, 23 Aug 2009 15:30:39 -0700 Subject: OpenID fixes. --- quoins/controllers.py | 14 +++++++++++--- quoins/openid_controllers.py | 32 ++++++++++++++++++++------------ quoins/templates/delete_post.html | 6 +++++- quoins/templates/post.html | 6 +++++- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/quoins/controllers.py b/quoins/controllers.py index 541d90b..e419d40 100644 --- a/quoins/controllers.py +++ b/quoins/controllers.py @@ -318,6 +318,8 @@ def post_paginate(start, posts, size): prev = prev, next = next) +ID_RE = re.compile(r'.*?/author/([^/]*)') + class BlogController(TGController): feed = Feed() pingback = Pingback() @@ -325,12 +327,17 @@ class BlogController(TGController): def __init__(self, *args, **kw): self.path = kw.pop('path', '/') self.post_paginate = kw.pop('paginate', 5) - get_name_from_id = kw.pop('get_name_from_id', lambda x: x) - self.openid = openid_controllers.OpenIDController(path=self.path+'/openid/', + get_name_from_id = kw.pop('get_name_from_id', self.get_username_from_openid) + self.openid = openid_controllers.OpenIDController(path=os.path.join(self.path, 'openid/'), + quoins=self, get_name_from_id = get_name_from_id) self.feed.blog_controller = self super(BlogController, self).__init__(*args, **kw) + def get_username_from_openid(self, id): + m = ID_RE.match(id) + return m.group(1) + def url(self, obj=None): if obj is None: u = tg.url(self.path) @@ -506,7 +513,7 @@ Comment: post = post) @expose(template="genshi:quoinstemplates.new_comment") - def new_comment(self, id): + def new_comment(self, id, **kw): post = DBSession.query(Post).get(id) if not post.allow_comments: flash('This post does not allow comments.') @@ -625,6 +632,7 @@ Comment: c.approved = True c.body = body c.url = url + c.openid = url c.name = name flash('Your comment has been posted.') self.send_comment_email(c) diff --git a/quoins/openid_controllers.py b/quoins/openid_controllers.py index 9491195..efb65c5 100644 --- a/quoins/openid_controllers.py +++ b/quoins/openid_controllers.py @@ -29,6 +29,7 @@ import types import os.path from utils import get_oid_connection +from model import * class DecideController(object): def __init__(self, oid_controller): @@ -49,11 +50,17 @@ class DecideController(object): session['oid_request']=oid_request session.save() - return dict(openid = self.oid_controller, - oid_request = oid_request, - required = sr_required, - optional = sr_optional, - ) + d = dict(openid = self.oid_controller, + oid_request = oid_request, + required = sr_required, + optional = sr_optional, + ) + + if self.oid_controller.quoins: + blog = DBSession.query(Blog).get(1) + d['blog'] = blog + d['quoins'] = self.oid_controller.quoins + return d class ResponseController(object): def __init__(self, oid_controller): @@ -81,6 +88,12 @@ class OpenIDController(TGController): 'timezone': 'Time zone', } + def __init__(self, *args, **kw): + self.get_name_from_id = kw.pop('get_name_from_id', lambda x: x) + self.path = kw.pop('path', '/') + self.quoins = kw.pop('quoins', None) + super(OpenIDController, self).__init__(*args, **kw) + def url(self, obj=None): if obj is None: u = tg.url(self.path) @@ -94,13 +107,8 @@ class OpenIDController(TGController): if port: port = ':'+port return 'http://%s%s%s'%(tg.config.get('server.webhost'), port, - self.url(obj)) + self.url(obj)) - def __init__(self, *args, **kw): - self.get_name_from_id = kw.pop('get_name_from_id', lambda x: x) - self.path = kw.pop('path', '/') - super(OpenIDController, self).__init__(*args, **kw) - def getSRegValue(self, user, field): val = None if field=='nickname': val = user.user_name @@ -132,7 +140,7 @@ class OpenIDController(TGController): store = MySQLStore(get_oid_connection()) oserver = openid.server.server.Server(store, - self.absolute_url('/openid/server')) + self.absolute_url('/server')) data = {} for field in sreg_req.required+sreg_req.optional: diff --git a/quoins/templates/delete_post.html b/quoins/templates/delete_post.html index e81500a..f664725 100644 --- a/quoins/templates/delete_post.html +++ b/quoins/templates/delete_post.html @@ -58,7 +58,11 @@   - ${comment.author_name} + + ${comment.author_name} + + ${comment.author_name} diff --git a/quoins/templates/post.html b/quoins/templates/post.html index fc606db..b0842f2 100644 --- a/quoins/templates/post.html +++ b/quoins/templates/post.html @@ -52,7 +52,11 @@   - ${comment.author_name} + + ${comment.author_name} + + ${comment.author_name} -- cgit v1.2.3