diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d61cb193d..df08808ae 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -8,7 +8,6 @@ class ApplicationController < ActionController::Base before_filter :set_friends_and_status, :except => [:create, :update] before_filter :count_requests - before_filter :fb_user_info before_filter :set_invites layout :layout_by_resource @@ -44,17 +43,4 @@ class ApplicationController < ActionController::Base @invites = current_user.invites end end - - ## take this out - def fb_user_info - if current_user - @access_token = warden.session[:access_token] - @logged_in = @access_token.present? - end - end - def logged_into_fb? - @logged_in - end - ## - end diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index ddde8a725..0129c0abf 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -11,9 +11,6 @@ class AspectsController < ApplicationController def index @posts = current_user.visible_posts(:by_members_of => :all).paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC' @aspect = :all - - @fb_access_url = MiniFB.oauth_url(FB_APP_ID, APP_CONFIG[:pod_url] + "services/create", - :scope=>MiniFB.scopes.join(",")) end def create @@ -56,15 +53,6 @@ class AspectsController < ApplicationController end end - def public - # @fb_access_url = MiniFB.oauth_url(FB_APP_ID, APP_CONFIG[:pod_url] + "services/create", - # :scope=>MiniFB.scopes.join(",")) - - @posts = current_user.visible_posts(:person_id => current_user.person.id, :public => true).paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC' - - respond_with @aspect - end - def manage @aspect = :manage @remote_requests = current_user.requests_for_me diff --git a/app/controllers/omniauth_services_controller.rb b/app/controllers/omniauth_services_controller.rb deleted file mode 100644 index d7659236e..000000000 --- a/app/controllers/omniauth_services_controller.rb +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - - -class OmniauthServicesController < ApplicationController - before_filter :authenticate_user! - - def index - @services = current_user.services - end - - def create - auth = request.env['omniauth.auth'] - - provider = auth['provider'] - user = auth['user_info'] - - if provider == 'twitter' - access_token = auth['extra']['access_token'] - current_user.services.create(:nickname => user['nickname'], - :access_token => access_token.token, - :access_secret => access_token.secret, - :provider => provider, - :uid => auth['uid']) - - elsif provider == 'facebook' - current_user.services.create(:nickname => user['nickname'], - :access_token => auth['credentials']['token'], - :provider => provider, - :uid => auth['uid']) - end - - - flash[:notice] = "Authentication successful." - redirect_to omniauth_services_url - end - - def destroy - @service = current_user.services.find(params[:id]) - @service.destroy - flash[:notice] = "Successfully destroyed authentication." - redirect_to omniauth_services_url - end -end diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 29da09872..7c5da42a7 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -4,36 +4,42 @@ class ServicesController < ApplicationController + before_filter :authenticate_user! + + def index + @services = current_user.services + end def create - puts 'services/create' - p params + auth = request.env['omniauth.auth'] - code = params['code'] # Facebooks verification string - if code - access_token_hash = MiniFB.oauth_access_token(FB_APP_ID, APP_CONFIG[:pod_url] + "services/create", FB_SECRET, code) - @access_token = access_token_hash["access_token"] + provider = auth['provider'] + user = auth['user_info'] - # TODO: This is where you'd want to store the token in your database - # but for now, we'll just keep it in the session so we don't need a database - warden.session[:access_token] = @access_token - flash[:success] = "Authentication successful." + if provider == 'twitter' + access_token = auth['extra']['access_token'] + current_user.services.create(:nickname => user['nickname'], + :access_token => access_token.token, + :access_secret => access_token.secret, + :provider => provider, + :uid => auth['uid']) + + elsif provider == 'facebook' + current_user.services.create(:nickname => user['nickname'], + :access_token => auth['credentials']['token'], + :provider => provider, + :uid => auth['uid']) end - redirect_to edit_user_url current_user + + + flash[:notice] = "Authentication successful." + redirect_to services_url end def destroy - warden.session[:access_token] = nil - warden.session[:user_id] = nil - redirect_to edit_user_url current_user + @service = current_user.services.find(params[:id]) + @service.destroy + flash[:notice] = "Successfully destroyed authentication." + redirect_to services_url end - - def fb_post - id = 'me' - type = 'feed' - - @res = MiniFB.post(@access_token, id, :type=>type, :metadata=>true, :params=>params) - redirect_to edit_user_url current_user - end - end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index aacff8504..9c1bb3e9c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -19,9 +19,6 @@ class UsersController < ApplicationController @person = @user.person @profile = @user.person.profile @photos = current_user.visible_posts(:person_id => current_user.person.id, :_type => 'Photo').paginate :page => params[:page], :order => 'created_at DESC' - - @fb_access_url = MiniFB.oauth_url(FB_APP_ID, APP_CONFIG[:pod_url] + "services/create", - :scope=>MiniFB.scopes.join(",")) end def update diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8851f3c8e..869d49a98 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -78,9 +78,4 @@ module ApplicationHelper def post_yield_tag(post) (':' + post.id.to_s).to_sym end - - def connected_fb_as token - response_hash = MiniFB.get(token, 'me') - "Connected to facebook as #{response_hash[:name]}" - end end diff --git a/app/models/omniauth_service.rb b/app/models/service.rb similarity index 93% rename from app/models/omniauth_service.rb rename to app/models/service.rb index d30ab9f7d..1b64f013e 100644 --- a/app/models/omniauth_service.rb +++ b/app/models/service.rb @@ -2,7 +2,7 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -class OmniauthService +class Service include MongoMapper::Document belongs_to :user diff --git a/app/models/user.rb b/app/models/user.rb index a52201fa0..48420e577 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -61,7 +61,7 @@ class User many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post' many :aspects, :class_name => 'Aspect', :dependent => :destroy - many :services, :class_name => "OmniauthService" + many :services, :class_name => "Service" #after_create :seed_aspects diff --git a/app/views/omniauth_services/index.html.haml b/app/views/omniauth_services/index.html.haml deleted file mode 100644 index 7d7e7c13f..000000000 --- a/app/views/omniauth_services/index.html.haml +++ /dev/null @@ -1,19 +0,0 @@ --# Copyright (c) 2010, Diaspora Inc. This file is --# licensed under the Affero General Public License version 3 or later. See --# the COPYRIGHT file. - -%h2 - Services - -%ul#stream - - for service in @services - %h3 - %b= service.provider - logged in as - %b - = service.nickname - = link_to "disconnect", service, :confirm => "disconnect #{service.provider}?", :method => :delete - -%h4= link_to "Connect to twitter", "/auth/twitter" -%h4= link_to "Connect to facebook", "/auth/facebook" - diff --git a/app/views/services/index.html.haml b/app/views/services/index.html.haml new file mode 100644 index 000000000..ea375e9ac --- /dev/null +++ b/app/views/services/index.html.haml @@ -0,0 +1,28 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +#section_header + %h2 + Settings + %ul#settings_nav + %li=link_to 'Profile', '#', :class => 'profile' + %li=link_to 'Account', '#', :class => 'account' + %li=link_to 'Services', services_path + +.span-19.prepend-5.last + %h2 + Services + + %ul#stream + - for service in @services + %h3 + %b= service.provider + logged in as + %b + = service.nickname + = link_to "disconnect", service, :confirm => "disconnect #{service.provider}?", :method => :delete + + %h4= link_to "Connect to twitter", "/auth/twitter" + %h4= link_to "Connect to facebook", "/auth/facebook" + diff --git a/app/views/shared/_aspect_friends.haml b/app/views/shared/_aspect_friends.haml index c44d88e6b..f4b2f06f7 100644 --- a/app/views/shared/_aspect_friends.haml +++ b/app/views/shared/_aspect_friends.haml @@ -15,11 +15,6 @@ - for friend in @friends = person_image_link(friend) - - if @logged_in && (@aspect == :public) - %h3 Facebook Friends - - @fb_friends = MiniFB.get(@access_token, 'me', :type => "friends") - - @fb_friends[:data].each do |friend| - = image_tag( "http://graph.facebook.com/#{friend[:id]}/picture" ) -unless (@aspect == :all) = link_to (image_tag('add_friend_button.png', :title => "add to #{@aspect}")), "#add_request_pane", :id => 'add_request_button' diff --git a/app/views/shared/_public_explain.haml b/app/views/shared/_public_explain.haml index ca1a2b1d7..3d7e7f644 100644 --- a/app/views/shared/_public_explain.haml +++ b/app/views/shared/_public_explain.haml @@ -9,10 +9,14 @@ Public messages will be available for others outside of Diaspora to see. %br %br - - if @logged_in - = connected_fb_as(@access_token) - - else - = link_to "Connect to Facebook", @fb_access_url + + - if current_user.services + - for service in current_user.services + = "logged in to #{service.provider}" + %br + + = link_to "manage connected services", services_path + %br %br = link_to "OK", '#', :class => "button", :onClick => '$.fancybox.close();' diff --git a/app/views/shared/_publisher.haml b/app/views/shared/_publisher.haml index 56ac9e440..5e3be8f2a 100644 --- a/app/views/shared/_publisher.haml +++ b/app/views/shared/_publisher.haml @@ -2,20 +2,22 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -:javascript - $("div.public_toggle input").live("click", function(evt){ - if("#{@logged_in}" == "false" && $(this).attr('checked') == true){ - $(".question_mark").click(); - }; - }); - - $("#publisher textarea, #publisher input").live("focus", function(evt){ - $("#publisher .options_and_submit").fadeIn(50); - }); - $("#publisher form").live("submit", function(evt){ - $("#publisher .options_and_submit").hide(); - }); +- content_for :head do + :javascript + $("div.public_toggle input").live("click", function(evt){ + if($(this).attr('checked') == true){ + $(".question_mark").click(); + }; + }); + + $("#publisher textarea, #publisher input").live("focus", function(evt){ + $("#publisher .options_and_submit").fadeIn(50); + }); + + $("#publisher form").live("submit", function(evt){ + $("#publisher .options_and_submit").hide(); + }); #publisher = owner_image_tag diff --git a/app/views/users/_services.haml b/app/views/users/_services.haml deleted file mode 100644 index a9a6d7977..000000000 --- a/app/views/users/_services.haml +++ /dev/null @@ -1,26 +0,0 @@ --# Copyright (c) 2010, Diaspora Inc. This file is --# licensed under the Affero General Public License version 3 or later. See --# the COPYRIGHT file. - - -%h2 Services - -- if FACEBOOK - %h3 Facebook - %p - - if @logged_in - = connected_fb_as(@access_token) - - %p - - @fb_friends = MiniFB.get(@access_token, 'me', :type => "friends") - - @fb_friends[:data].each do |friend| - = image_tag( "http://graph.facebook.com/#{friend[:id]}/picture" ) - - = link_to "Disconnect from Facebook", services_destroy_path - - else - = link_to "Connect to Facebook", @fb_access_url - - #content_bottom - .back - = link_to "⇧ home", root_path - diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index 48b266c09..104a9e8fd 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -18,7 +18,7 @@ %ul#settings_nav %li=link_to 'Profile', '#', :class => 'profile' %li=link_to 'Account', '#', :class => 'account' - %li=link_to 'Services', '#', :class => 'services' + %li=link_to 'Services', services_path .span-19.prepend-5.last #profile.settings_pane{:style=>"display:block;"} @@ -27,6 +27,3 @@ #account.settings_pane = render 'users/account' - #services.settings_pane - = render 'users/services' - diff --git a/config/routes.rb b/config/routes.rb index 470193a74..b9b05ca65 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,13 +9,13 @@ Diaspora::Application.routes.draw do resources :requests, :except => [:edit, :update] resources :photos, :except => [:index] resources :albums - resources :omniauth_services + resources :services - match '/auth/:provider/callback' => 'omniauth_services#create' + match '/auth/:provider/callback' => 'services#create' devise_for :users, :controllers => {:registrations => "registrations", :password => "devise/passwords", - :invitations => "invitations"} + :invitations => "invitations"} # added public route to user match 'public/:username', :to => 'users#public' match 'users/export', :to => 'users#export' @@ -27,13 +27,8 @@ Diaspora::Application.routes.draw do match 'aspects/add_to_aspect',:to => 'aspects#add_to_aspect', :as => 'add_to_aspect' match 'aspects/remove_from_aspect',:to => 'aspects#remove_from_aspect', :as => 'remove_from_aspect' match 'aspects/manage', :to => 'aspects#manage' - match 'aspects/public', :to => 'aspects#public' resources :aspects, :except => [:edit] - match 'services/create', :to => "services#create" - match 'services/destroy', :to => "services#destroy" - match 'services/fb_post', :to => "services#fb_post" - match 'warzombie', :to => "dev_utilities#warzombie" match 'zombiefriends', :to => "dev_utilities#zombiefriends" match 'zombiefriendaccept', :to => "dev_utilities#zombiefriendaccept" diff --git a/spec/controllers/omniauth_services_controller_spec.rb b/spec/controllers/services_controller_spec.rb similarity index 78% rename from spec/controllers/omniauth_services_controller_spec.rb rename to spec/controllers/services_controller_spec.rb index b72426eba..0c19c1e23 100644 --- a/spec/controllers/omniauth_services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -4,15 +4,15 @@ require 'spec_helper' -describe OmniauthServicesController do +describe ServicesController do render_views let(:user) { Factory(:user) } let!(:aspect) { user.aspect(:name => "lame-os") } - let!(:service1) {a = Factory(:omniauth_service); user.services << a; a} - let!(:service2) {a = Factory(:omniauth_service); user.services << a; a} - let!(:service3) {a = Factory(:omniauth_service); user.services << a; a} - let!(:service4) {a = Factory(:omniauth_service); user.services << a; a} + let!(:service1) {a = Factory(:service); user.services << a; a} + let!(:service2) {a = Factory(:service); user.services << a; a} + let!(:service3) {a = Factory(:service); user.services << a; a} + let!(:service4) {a = Factory(:service); user.services << a; a} let(:mock_access_token) { Object.new } diff --git a/spec/factories.rb b/spec/factories.rb index b64cbbc5e..32d747937 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -57,12 +57,12 @@ Factory.define :photo do |p| end -Factory.define :omniauth_service do |service| +Factory.define :service do |service| service.nickname "sirrobertking" service.provider "twitter" - service.sequence(:uid) { |token| "000#{token}" } - service.sequence(:access_token) { |token| "12345#{token}" } + service.sequence(:uid) { |token| "00000#{token}" } + service.sequence(:access_token) { |token| "12345#{token}" } service.sequence(:access_secret) { |token| "98765#{token}" } end