mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-02-07 08:01:02 -05:00
Reconnecting stale flickr auth tokens
This commit is contained in:
committed by
Brenda Wallace
parent
32414cb409
commit
60c74ddff3
@@ -92,8 +92,16 @@ class PhotosController < ApplicationController
|
||||
|
||||
def retrieve_from_flickr
|
||||
@flickr_auth = current_member.auth('flickr')
|
||||
return if @flickr_auth.nil?
|
||||
|
||||
|
||||
if ! current_member.flickr_auth_valid?
|
||||
current_member.remove_stale_flickr_auth
|
||||
@please_reconnect_flickr = true
|
||||
return
|
||||
end
|
||||
|
||||
@current_set = params[:set]
|
||||
return unless @flickr_auth
|
||||
|
||||
page = params[:page] || 1
|
||||
|
||||
|
||||
@@ -19,6 +19,24 @@ module MemberFlickr
|
||||
@flickr
|
||||
end
|
||||
|
||||
def flickr_auth_valid?
|
||||
# no flickr token saved for this member
|
||||
return false if flickr.nil?
|
||||
|
||||
# test the token/secret we have
|
||||
flickr.test.login # This throws exception if fails
|
||||
|
||||
# success!
|
||||
true
|
||||
rescue FlickRaw::FailedResponse, FlickRaw::OAuthClient::FailedResponse
|
||||
# token for this user doesn't work
|
||||
false
|
||||
end
|
||||
|
||||
def remove_stale_flickr_auth
|
||||
authentications.find_by(provider: "flickr")&.delete
|
||||
end
|
||||
|
||||
# Fetches a collection of photos from Flickr
|
||||
# Returns a [[page of photos], total] pair.
|
||||
# Total is needed for pagination.
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
- content_for :title, "New Photo"
|
||||
|
||||
%h1 New Photo
|
||||
%h2 Choose photo for #{link_to @item, @item}
|
||||
|
||||
- if @flickr_auth
|
||||
|
||||
- if @please_reconnect_flickr
|
||||
%h2 Please reconnect your flickr account
|
||||
|
||||
%p the token has expired or been revoked.
|
||||
|
||||
= link_to '/members/auth/flickr', class: "btn btn-lg" do
|
||||
= icon 'fab', 'flickr'
|
||||
Reconnect Flickr
|
||||
|
||||
|
||||
- elsif @flickr_auth
|
||||
%h2 Choose photo for #{link_to @item, @item}
|
||||
%p
|
||||
Connected to Flickr as
|
||||
= succeed "." do
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
Rails.application.config.middleware.use OmniAuth::Builder do
|
||||
provider :twitter, ENV['GROWSTUFF_TWITTER_KEY'], ENV['GROWSTUFF_TWITTER_SECRET']
|
||||
provider :flickr, ENV['GROWSTUFF_FLICKR_KEY'], ENV['GROWSTUFF_FLICKR_SECRET']
|
||||
provider :flickr, ENV['GROWSTUFF_FLICKR_KEY'], ENV['GROWSTUFF_FLICKR_SECRET'], scope: 'read'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user