diff options
author | James E. Blair <corvus@gnu.org> | 2009-08-23 15:30:39 -0700 |
---|---|---|
committer | James E. Blair <corvus@gnu.org> | 2009-08-23 15:30:39 -0700 |
commit | 08afa969049393059e6a5694f4c1662e13e66cff (patch) | |
tree | b363a162763db225d1601ea129fa1b0a905a844b | |
parent | a9c8b10d07f910b01af32e21afd34e8b6c6ebf6f (diff) |
OpenID fixes.
-rw-r--r-- | quoins/controllers.py | 14 | ||||
-rw-r--r-- | quoins/openid_controllers.py | 32 | ||||
-rw-r--r-- | quoins/templates/delete_post.html | 6 | ||||
-rw-r--r-- | 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): | |||
318 | prev = prev, | 318 | prev = prev, |
319 | next = next) | 319 | next = next) |
320 | 320 | ||
321 | ID_RE = re.compile(r'.*?/author/([^/]*)') | ||
322 | |||
321 | class BlogController(TGController): | 323 | class BlogController(TGController): |
322 | feed = Feed() | 324 | feed = Feed() |
323 | pingback = Pingback() | 325 | pingback = Pingback() |
@@ -325,12 +327,17 @@ class BlogController(TGController): | |||
325 | def __init__(self, *args, **kw): | 327 | def __init__(self, *args, **kw): |
326 | self.path = kw.pop('path', '/') | 328 | self.path = kw.pop('path', '/') |
327 | self.post_paginate = kw.pop('paginate', 5) | 329 | self.post_paginate = kw.pop('paginate', 5) |
328 | get_name_from_id = kw.pop('get_name_from_id', lambda x: x) | 330 | get_name_from_id = kw.pop('get_name_from_id', self.get_username_from_openid) |
329 | self.openid = openid_controllers.OpenIDController(path=self.path+'/openid/', | 331 | self.openid = openid_controllers.OpenIDController(path=os.path.join(self.path, 'openid/'), |
332 | quoins=self, | ||
330 | get_name_from_id = get_name_from_id) | 333 | get_name_from_id = get_name_from_id) |
331 | self.feed.blog_controller = self | 334 | self.feed.blog_controller = self |
332 | super(BlogController, self).__init__(*args, **kw) | 335 | super(BlogController, self).__init__(*args, **kw) |
333 | 336 | ||
337 | def get_username_from_openid(self, id): | ||
338 | m = ID_RE.match(id) | ||
339 | return m.group(1) | ||
340 | |||
334 | def url(self, obj=None): | 341 | def url(self, obj=None): |
335 | if obj is None: | 342 | if obj is None: |
336 | u = tg.url(self.path) | 343 | u = tg.url(self.path) |
@@ -506,7 +513,7 @@ Comment: | |||
506 | post = post) | 513 | post = post) |
507 | 514 | ||
508 | @expose(template="genshi:quoinstemplates.new_comment") | 515 | @expose(template="genshi:quoinstemplates.new_comment") |
509 | def new_comment(self, id): | 516 | def new_comment(self, id, **kw): |
510 | post = DBSession.query(Post).get(id) | 517 | post = DBSession.query(Post).get(id) |
511 | if not post.allow_comments: | 518 | if not post.allow_comments: |
512 | flash('This post does not allow comments.') | 519 | flash('This post does not allow comments.') |
@@ -625,6 +632,7 @@ Comment: | |||
625 | c.approved = True | 632 | c.approved = True |
626 | c.body = body | 633 | c.body = body |
627 | c.url = url | 634 | c.url = url |
635 | c.openid = url | ||
628 | c.name = name | 636 | c.name = name |
629 | flash('Your comment has been posted.') | 637 | flash('Your comment has been posted.') |
630 | self.send_comment_email(c) | 638 | 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 | |||
29 | import os.path | 29 | import os.path |
30 | 30 | ||
31 | from utils import get_oid_connection | 31 | from utils import get_oid_connection |
32 | from model import * | ||
32 | 33 | ||
33 | class DecideController(object): | 34 | class DecideController(object): |
34 | def __init__(self, oid_controller): | 35 | def __init__(self, oid_controller): |
@@ -49,11 +50,17 @@ class DecideController(object): | |||
49 | session['oid_request']=oid_request | 50 | session['oid_request']=oid_request |
50 | session.save() | 51 | session.save() |
51 | 52 | ||
52 | return dict(openid = self.oid_controller, | 53 | d = dict(openid = self.oid_controller, |
53 | oid_request = oid_request, | 54 | oid_request = oid_request, |
54 | required = sr_required, | 55 | required = sr_required, |
55 | optional = sr_optional, | 56 | optional = sr_optional, |
56 | ) | 57 | ) |
58 | |||
59 | if self.oid_controller.quoins: | ||
60 | blog = DBSession.query(Blog).get(1) | ||
61 | d['blog'] = blog | ||
62 | d['quoins'] = self.oid_controller.quoins | ||
63 | return d | ||
57 | 64 | ||
58 | class ResponseController(object): | 65 | class ResponseController(object): |
59 | def __init__(self, oid_controller): | 66 | def __init__(self, oid_controller): |
@@ -81,6 +88,12 @@ class OpenIDController(TGController): | |||
81 | 'timezone': 'Time zone', | 88 | 'timezone': 'Time zone', |
82 | } | 89 | } |
83 | 90 | ||
91 | def __init__(self, *args, **kw): | ||
92 | self.get_name_from_id = kw.pop('get_name_from_id', lambda x: x) | ||
93 | self.path = kw.pop('path', '/') | ||
94 | self.quoins = kw.pop('quoins', None) | ||
95 | super(OpenIDController, self).__init__(*args, **kw) | ||
96 | |||
84 | def url(self, obj=None): | 97 | def url(self, obj=None): |
85 | if obj is None: | 98 | if obj is None: |
86 | u = tg.url(self.path) | 99 | u = tg.url(self.path) |
@@ -94,13 +107,8 @@ class OpenIDController(TGController): | |||
94 | if port: | 107 | if port: |
95 | port = ':'+port | 108 | port = ':'+port |
96 | return 'http://%s%s%s'%(tg.config.get('server.webhost'), port, | 109 | return 'http://%s%s%s'%(tg.config.get('server.webhost'), port, |
97 | self.url(obj)) | 110 | self.url(obj)) |
98 | 111 | ||
99 | def __init__(self, *args, **kw): | ||
100 | self.get_name_from_id = kw.pop('get_name_from_id', lambda x: x) | ||
101 | self.path = kw.pop('path', '/') | ||
102 | super(OpenIDController, self).__init__(*args, **kw) | ||
103 | |||
104 | def getSRegValue(self, user, field): | 112 | def getSRegValue(self, user, field): |
105 | val = None | 113 | val = None |
106 | if field=='nickname': val = user.user_name | 114 | if field=='nickname': val = user.user_name |
@@ -132,7 +140,7 @@ class OpenIDController(TGController): | |||
132 | 140 | ||
133 | store = MySQLStore(get_oid_connection()) | 141 | store = MySQLStore(get_oid_connection()) |
134 | oserver = openid.server.server.Server(store, | 142 | oserver = openid.server.server.Server(store, |
135 | self.absolute_url('/openid/server')) | 143 | self.absolute_url('/server')) |
136 | 144 | ||
137 | data = {} | 145 | data = {} |
138 | for field in sreg_req.required+sreg_req.optional: | 146 | 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 @@ | |||
58 | </span> | 58 | </span> |
59 | | 59 | |
60 | <span class="blog-comment-user" py:if="quoins.comment_author_url(comment)"> | 60 | <span class="blog-comment-user" py:if="quoins.comment_author_url(comment)"> |
61 | <a href="${quoins.comment_author_url(comment)}" rel="nofollow">${comment.author_name}</a> | 61 | <a href="${quoins.comment_author_url(comment)}" rel="nofollow"> |
62 | ${comment.author_name} | ||
63 | <img py:if="comment.openid" | ||
64 | src="${tg.url('/images/openid_small_logo.png')}" /> | ||
65 | </a> | ||
62 | </span> | 66 | </span> |
63 | <span class="blog-comment-user" py:if="not quoins.comment_author_url(comment)"> | 67 | <span class="blog-comment-user" py:if="not quoins.comment_author_url(comment)"> |
64 | ${comment.author_name} | 68 | ${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 @@ | |||
52 | </span> | 52 | </span> |
53 | | 53 | |
54 | <span class="blog-comment-user" py:if="quoins.comment_author_url(comment)"> | 54 | <span class="blog-comment-user" py:if="quoins.comment_author_url(comment)"> |
55 | <a href="${quoins.comment_author_url(comment)}" rel="nofollow">${comment.author_name}</a> | 55 | <a href="${quoins.comment_author_url(comment)}" rel="nofollow"> |
56 | ${comment.author_name} | ||
57 | <img py:if="comment.openid" | ||
58 | src="${tg.url('/images/openid_small_logo.png')}" /> | ||
59 | </a> | ||
56 | </span> | 60 | </span> |
57 | <span class="blog-comment-user" py:if="not quoins.comment_author_url(comment)"> | 61 | <span class="blog-comment-user" py:if="not quoins.comment_author_url(comment)"> |
58 | ${comment.author_name} | 62 | ${comment.author_name} |