OmniauthService -> Service. Cleaned up views.
This commit is contained in:
parent
3d302f8db7
commit
b2e8ebd0bc
18 changed files with 94 additions and 191 deletions
|
|
@ -8,7 +8,6 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
before_filter :set_friends_and_status, :except => [:create, :update]
|
before_filter :set_friends_and_status, :except => [:create, :update]
|
||||||
before_filter :count_requests
|
before_filter :count_requests
|
||||||
before_filter :fb_user_info
|
|
||||||
before_filter :set_invites
|
before_filter :set_invites
|
||||||
|
|
||||||
layout :layout_by_resource
|
layout :layout_by_resource
|
||||||
|
|
@ -44,17 +43,4 @@ class ApplicationController < ActionController::Base
|
||||||
@invites = current_user.invites
|
@invites = current_user.invites
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,6 @@ class AspectsController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@posts = current_user.visible_posts(:by_members_of => :all).paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC'
|
@posts = current_user.visible_posts(:by_members_of => :all).paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC'
|
||||||
@aspect = :all
|
@aspect = :all
|
||||||
|
|
||||||
@fb_access_url = MiniFB.oauth_url(FB_APP_ID, APP_CONFIG[:pod_url] + "services/create",
|
|
||||||
:scope=>MiniFB.scopes.join(","))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
@ -56,15 +53,6 @@ class AspectsController < ApplicationController
|
||||||
end
|
end
|
||||||
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
|
def manage
|
||||||
@aspect = :manage
|
@aspect = :manage
|
||||||
@remote_requests = current_user.requests_for_me
|
@remote_requests = current_user.requests_for_me
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -4,36 +4,42 @@
|
||||||
|
|
||||||
|
|
||||||
class ServicesController < ApplicationController
|
class ServicesController < ApplicationController
|
||||||
|
before_filter :authenticate_user!
|
||||||
|
|
||||||
|
def index
|
||||||
|
@services = current_user.services
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
puts 'services/create'
|
auth = request.env['omniauth.auth']
|
||||||
p params
|
|
||||||
|
|
||||||
code = params['code'] # Facebooks verification string
|
provider = auth['provider']
|
||||||
if code
|
user = auth['user_info']
|
||||||
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"]
|
|
||||||
|
|
||||||
# TODO: This is where you'd want to store the token in your database
|
if provider == 'twitter'
|
||||||
# but for now, we'll just keep it in the session so we don't need a database
|
access_token = auth['extra']['access_token']
|
||||||
warden.session[:access_token] = @access_token
|
current_user.services.create(:nickname => user['nickname'],
|
||||||
flash[:success] = "Authentication successful."
|
: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
|
end
|
||||||
redirect_to edit_user_url current_user
|
|
||||||
|
|
||||||
|
flash[:notice] = "Authentication successful."
|
||||||
|
redirect_to services_url
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
warden.session[:access_token] = nil
|
@service = current_user.services.find(params[:id])
|
||||||
warden.session[:user_id] = nil
|
@service.destroy
|
||||||
redirect_to edit_user_url current_user
|
flash[:notice] = "Successfully destroyed authentication."
|
||||||
|
redirect_to services_url
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,6 @@ class UsersController < ApplicationController
|
||||||
@person = @user.person
|
@person = @user.person
|
||||||
@profile = @user.person.profile
|
@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'
|
@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
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
|
|
||||||
|
|
@ -78,9 +78,4 @@ module ApplicationHelper
|
||||||
def post_yield_tag(post)
|
def post_yield_tag(post)
|
||||||
(':' + post.id.to_s).to_sym
|
(':' + post.id.to_s).to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
def connected_fb_as token
|
|
||||||
response_hash = MiniFB.get(token, 'me')
|
|
||||||
"Connected to facebook as #{response_hash[:name]}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class OmniauthService
|
class Service
|
||||||
include MongoMapper::Document
|
include MongoMapper::Document
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
@ -61,7 +61,7 @@ class User
|
||||||
many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post'
|
many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post'
|
||||||
many :aspects, :class_name => 'Aspect', :dependent => :destroy
|
many :aspects, :class_name => 'Aspect', :dependent => :destroy
|
||||||
|
|
||||||
many :services, :class_name => "OmniauthService"
|
many :services, :class_name => "Service"
|
||||||
|
|
||||||
#after_create :seed_aspects
|
#after_create :seed_aspects
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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"
|
|
||||||
|
|
||||||
28
app/views/services/index.html.haml
Normal file
28
app/views/services/index.html.haml
Normal 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"
|
||||||
|
|
||||||
|
|
@ -15,11 +15,6 @@
|
||||||
- for friend in @friends
|
- for friend in @friends
|
||||||
= person_image_link(friend)
|
= 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)
|
-unless (@aspect == :all)
|
||||||
= link_to (image_tag('add_friend_button.png', :title => "add to #{@aspect}")), "#add_request_pane", :id => 'add_request_button'
|
= link_to (image_tag('add_friend_button.png', :title => "add to #{@aspect}")), "#add_request_pane", :id => 'add_request_button'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,14 @@
|
||||||
Public messages will be available for others outside of Diaspora to see.
|
Public messages will be available for others outside of Diaspora to see.
|
||||||
%br
|
%br
|
||||||
%br
|
%br
|
||||||
- if @logged_in
|
|
||||||
= connected_fb_as(@access_token)
|
- if current_user.services
|
||||||
- else
|
- for service in current_user.services
|
||||||
= link_to "Connect to Facebook", @fb_access_url
|
= "logged in to #{service.provider}"
|
||||||
|
%br
|
||||||
|
|
||||||
|
= link_to "manage connected services", services_path
|
||||||
|
|
||||||
%br
|
%br
|
||||||
%br
|
%br
|
||||||
= link_to "OK", '#', :class => "button", :onClick => '$.fancybox.close();'
|
= link_to "OK", '#', :class => "button", :onClick => '$.fancybox.close();'
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,22 @@
|
||||||
-# licensed under the Affero General Public License version 3 or later. See
|
-# licensed under the Affero General Public License version 3 or later. See
|
||||||
-# the COPYRIGHT file.
|
-# 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){
|
- content_for :head do
|
||||||
$("#publisher .options_and_submit").hide();
|
: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
|
#publisher
|
||||||
= owner_image_tag
|
= owner_image_tag
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
%ul#settings_nav
|
%ul#settings_nav
|
||||||
%li=link_to 'Profile', '#', :class => 'profile'
|
%li=link_to 'Profile', '#', :class => 'profile'
|
||||||
%li=link_to 'Account', '#', :class => 'account'
|
%li=link_to 'Account', '#', :class => 'account'
|
||||||
%li=link_to 'Services', '#', :class => 'services'
|
%li=link_to 'Services', services_path
|
||||||
|
|
||||||
.span-19.prepend-5.last
|
.span-19.prepend-5.last
|
||||||
#profile.settings_pane{:style=>"display:block;"}
|
#profile.settings_pane{:style=>"display:block;"}
|
||||||
|
|
@ -27,6 +27,3 @@
|
||||||
#account.settings_pane
|
#account.settings_pane
|
||||||
= render 'users/account'
|
= render 'users/account'
|
||||||
|
|
||||||
#services.settings_pane
|
|
||||||
= render 'users/services'
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,13 @@ Diaspora::Application.routes.draw do
|
||||||
resources :requests, :except => [:edit, :update]
|
resources :requests, :except => [:edit, :update]
|
||||||
resources :photos, :except => [:index]
|
resources :photos, :except => [:index]
|
||||||
resources :albums
|
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",
|
devise_for :users, :controllers => {:registrations => "registrations",
|
||||||
:password => "devise/passwords",
|
:password => "devise/passwords",
|
||||||
:invitations => "invitations"}
|
:invitations => "invitations"}
|
||||||
# added public route to user
|
# added public route to user
|
||||||
match 'public/:username', :to => 'users#public'
|
match 'public/:username', :to => 'users#public'
|
||||||
match 'users/export', :to => 'users#export'
|
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/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/remove_from_aspect',:to => 'aspects#remove_from_aspect', :as => 'remove_from_aspect'
|
||||||
match 'aspects/manage', :to => 'aspects#manage'
|
match 'aspects/manage', :to => 'aspects#manage'
|
||||||
match 'aspects/public', :to => 'aspects#public'
|
|
||||||
resources :aspects, :except => [:edit]
|
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 'warzombie', :to => "dev_utilities#warzombie"
|
||||||
match 'zombiefriends', :to => "dev_utilities#zombiefriends"
|
match 'zombiefriends', :to => "dev_utilities#zombiefriends"
|
||||||
match 'zombiefriendaccept', :to => "dev_utilities#zombiefriendaccept"
|
match 'zombiefriendaccept', :to => "dev_utilities#zombiefriendaccept"
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,15 @@
|
||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe OmniauthServicesController do
|
describe ServicesController do
|
||||||
render_views
|
render_views
|
||||||
let(:user) { Factory(:user) }
|
let(:user) { Factory(:user) }
|
||||||
let!(:aspect) { user.aspect(:name => "lame-os") }
|
let!(:aspect) { user.aspect(:name => "lame-os") }
|
||||||
|
|
||||||
let!(:service1) {a = Factory(:omniauth_service); user.services << a; a}
|
let!(:service1) {a = Factory(:service); user.services << a; a}
|
||||||
let!(:service2) {a = Factory(:omniauth_service); user.services << a; a}
|
let!(:service2) {a = Factory(:service); user.services << a; a}
|
||||||
let!(:service3) {a = Factory(:omniauth_service); user.services << a; a}
|
let!(:service3) {a = Factory(:service); user.services << a; a}
|
||||||
let!(:service4) {a = Factory(:omniauth_service); user.services << a; a}
|
let!(:service4) {a = Factory(:service); user.services << a; a}
|
||||||
|
|
||||||
let(:mock_access_token) { Object.new }
|
let(:mock_access_token) { Object.new }
|
||||||
|
|
||||||
|
|
@ -57,12 +57,12 @@ Factory.define :photo do |p|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Factory.define :omniauth_service do |service|
|
Factory.define :service do |service|
|
||||||
service.nickname "sirrobertking"
|
service.nickname "sirrobertking"
|
||||||
service.provider "twitter"
|
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_token) { |token| "12345#{token}" }
|
||||||
service.sequence(:access_secret) { |token| "98765#{token}" }
|
service.sequence(:access_secret) { |token| "98765#{token}" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue