* Dropped all references to Resque * Moved all jobs under app/workers since that's the Sidekiq convention * Renamed Jobs module to Worker to match new location * Adapted all jobs to Sidekiq * Replaced all enqueue calls with perform_async * Dropped Resque hacks from specs and features, replaced with sidekig/testing in RSpec and sidekig/testing/inline in Cucumber * Updated scripts to start a Sidekiq server * Inline Sidekiq sinatra app * Let Sidekiq create the actual Redis instance * Workaround already initialized constant warnings in service models * Resolved ToDo in one job definition by creating proper exception clases for some errors in receiving posts * Added sidekiq section to configuration to make it completly configurable to the user * Add Sidekiq middleware for clean backtraces * Delay HttpMulti retry to give offline pods a chance to come back up * Do not retry on GUID already taken and alike errors * Be graceful about deleted posts in GatherOEmbedData
71 lines
2.4 KiB
Ruby
71 lines
2.4 KiB
Ruby
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
|
# licensed under the Affero General Public License version 3 or later. See
|
|
# the COPYRIGHT file.
|
|
|
|
class ServicesController < ApplicationController
|
|
# We need to take a raw POST from an omniauth provider with no authenticity token.
|
|
# See https://github.com/intridea/omniauth/issues/203
|
|
# See also http://www.communityguides.eu/articles/16
|
|
skip_before_filter :verify_authenticity_token, :only => :create
|
|
|
|
before_filter :authenticate_user!
|
|
|
|
respond_to :html
|
|
respond_to :json, :only => :inviter
|
|
|
|
def index
|
|
@services = current_user.services
|
|
end
|
|
|
|
def create
|
|
auth = request.env['omniauth.auth']
|
|
|
|
toke = auth['credentials']['token']
|
|
secret = auth['credentials']['secret']
|
|
|
|
provider = auth['provider']
|
|
user = auth['info']
|
|
|
|
service = "Services::#{provider.camelize}".constantize.new(:nickname => user['nickname'],
|
|
:access_token => toke,
|
|
:access_secret => secret,
|
|
:uid => auth['uid'])
|
|
current_user.services << service
|
|
|
|
if service.persisted?
|
|
fetch_photo = current_user.profile[:image_url].blank?
|
|
|
|
current_user.update_profile(current_user.profile.from_omniauth_hash(user))
|
|
Workers::FetchProfilePhoto.perform_async(current_user.id, service.id, user["image"]) if fetch_photo
|
|
|
|
flash[:notice] = I18n.t 'services.create.success'
|
|
else
|
|
flash[:error] = I18n.t 'services.create.failure'
|
|
|
|
if existing_service = Service.where(:type => service.type.to_s, :uid => service.uid).first
|
|
flash[:error] << I18n.t('services.create.already_authorized',
|
|
:diaspora_id => existing_service.user.profile.diaspora_handle,
|
|
:service_name => provider.camelize )
|
|
end
|
|
end
|
|
|
|
if request.env['omniauth.origin'].nil?
|
|
render :text => ("<script>window.close()</script>")
|
|
else
|
|
redirect_to request.env['omniauth.origin']
|
|
end
|
|
end
|
|
|
|
def failure
|
|
Rails.logger.info "error in oauth #{params.inspect}"
|
|
flash[:error] = t('services.failure.error')
|
|
redirect_to services_url
|
|
end
|
|
|
|
def destroy
|
|
@service = current_user.services.find(params[:id])
|
|
@service.destroy
|
|
flash[:notice] = I18n.t 'services.destroy.success'
|
|
redirect_to services_url
|
|
end
|
|
end
|