From 322b3ccfdbee70b7a4fc5ea90a63716417031181 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20K=C3=B6gl?= Date: Sun, 10 Mar 2013 17:59:02 +0100 Subject: [PATCH] Flattr auth dynamically uses http(s) for callback --- mygpo/core/tasks.py | 6 +++--- mygpo/flattr.py | 8 ++++++-- mygpo/share/views.py | 2 +- mygpo/web/views/episode.py | 3 ++- mygpo/web/views/podcast.py | 3 ++- mygpo/web/views/settings.py | 4 ++-- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/mygpo/core/tasks.py b/mygpo/core/tasks.py index a1e7853b..6c974415 100644 --- a/mygpo/core/tasks.py +++ b/mygpo/core/tasks.py @@ -15,10 +15,10 @@ from mygpo.db.couchdb.episode_state import episode_state_for_user_episode, \ @celery.task(max_retries=5, default_retry_delay=60) -def flattr_thing(user, thing_id, domain, thing_type): +def flattr_thing(user, thing_id, domain, is_secure, thing_type): """ Task to flattr a thing """ - flattr = Flattr(user, domain) + flattr = Flattr(user, domain, is_secure) if thing_type == 'Podcast': thing = podcast_by_id(thing_id) @@ -51,7 +51,7 @@ def auto_flattr_episode(user, episode_id): In addition to the flattring itself, it also records the event """ - success, msg = flattr_thing(user, episode_id, None, 'Episode') + success, msg = flattr_thing(user, episode_id, None, False, 'Episode') if not success: return False diff --git a/mygpo/flattr.py b/mygpo/flattr.py index d38389c8..e5bf3f77 100644 --- a/mygpo/flattr.py +++ b/mygpo/flattr.py @@ -35,13 +35,17 @@ class Flattr(object): THING_INFO_URL_TEMPLATE = API_BASE + '/things/lookup/?url=%(url)s' - def __init__(self, user, domain): + def __init__(self, user, domain, is_secure): self.user = user self.domain = domain + self.is_secure = is_secure def _get_callback(self): - return 'https://' + self.domain + reverse('flattr-token') + return 'http{s}://{domain}{callback}'.format( + s='s' if self.is_secure else '', + domain=self.domain, + callback=reverse('flattr-token')) def request(self, url, data=None): diff --git a/mygpo/share/views.py b/mygpo/share/views.py index bb454cfc..2693ae7c 100644 --- a/mygpo/share/views.py +++ b/mygpo/share/views.py @@ -96,7 +96,7 @@ def list_show(request, plist, owner): max_subscribers = max([p.subscriber_count() for p in podcasts] + [0]) thing = plist.get_flattr_thing(site.domain, owner.username) - flattr = Flattr(owner, site.domain) + flattr = Flattr(owner, site.domain, request.is_secure()) flattr_autosubmit = flattr.get_autosubmit_url(thing) return render(request, 'list.html', { diff --git a/mygpo/web/views/episode.py b/mygpo/web/views/episode.py index 506c64c3..254cc0d6 100644 --- a/mygpo/web/views/episode.py +++ b/mygpo/web/views/episode.py @@ -249,7 +249,8 @@ def flattr_episode(request, episode): site = RequestSite(request) # Flattr via the tasks queue, but wait for the result - task = flattr_thing.delay(user, episode._id, site.domain, 'Episode') + task = flattr_thing.delay(user, episode._id, site.domain, + request.is_secure(), 'Episode') success, msg = task.get() if success: diff --git a/mygpo/web/views/podcast.py b/mygpo/web/views/podcast.py index 73e93b24..ea3cc089 100644 --- a/mygpo/web/views/podcast.py +++ b/mygpo/web/views/podcast.py @@ -343,7 +343,8 @@ def flattr_podcast(request, podcast): site = RequestSite(request) # do flattring via the tasks queue, but wait for the result - task = flattr_thing.delay(user, podcast.get_id(), site.domain, 'Podcast') + task = flattr_thing.delay(user, podcast.get_id(), site.domain, + request.is_secure(), 'Podcast') success, msg = task.get() if success: diff --git a/mygpo/web/views/settings.py b/mygpo/web/views/settings.py index 01ff6146..b12b9160 100644 --- a/mygpo/web/views/settings.py +++ b/mygpo/web/views/settings.py @@ -54,7 +54,7 @@ def account(request): if request.method == 'GET': site = RequestSite(request) - flattr = Flattr(request.user, site.domain) + flattr = Flattr(request.user, site.domain, request.is_secure()) userpage_token = request.user.get_token('userpage_token') profile_form = ProfileForm({ @@ -169,7 +169,7 @@ class FlattrTokenView(View): user = request.user site = RequestSite(request) - flattr = Flattr(user, site.domain) + flattr = Flattr(user, site.domain, request.is_secure()) url = request.build_absolute_uri() token = flattr.process_retrieved_code(url) -- 2.11.4.GIT