OmniauthService -> Service. Cleaned up views.

This commit is contained in:
danielvincent 2010-10-25 16:17:19 -07:00
parent 3d302f8db7
commit b2e8ebd0bc
18 changed files with 94 additions and 191 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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"

View file

@ -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'

View file

@ -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();'

View file

@ -2,9 +2,11 @@
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
- content_for :head do
:javascript
$("div.public_toggle input").live("click", function(evt){
if("#{@logged_in}" == "false" && $(this).attr('checked') == true){
if($(this).attr('checked') == true){
$(".question_mark").click();
};
});

View file

@ -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

View file

@ -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'

View file

@ -9,9 +9,9 @@ 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",
@ -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"

View file

@ -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 }

View file

@ -57,11 +57,11 @@ 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(:uid) { |token| "00000#{token}" }
service.sequence(:access_token) { |token| "12345#{token}" }
service.sequence(:access_secret) { |token| "98765#{token}" }
end