Skip to content
Extraits de code Groupes Projets
Valider 1075c4f9 rédigé par zhitomirskiyi's avatar zhitomirskiyi
Parcourir les fichiers

Merge branch 'master' of github.com:diaspora/diaspora

parents 0e2c20d8 ff13cad1
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 191 ajouts et 171 suppressions
# Configuration files
config/app_config.yml
config/fb_config.yml
config/oauth_keys.yml
config/initializers/secret_token.rb
.bundle
vendor/bundle/*
......
......@@ -9,6 +9,10 @@ gem "chef"
gem 'devise', '1.1.3'
gem 'devise-mongo_mapper', :git => 'git://github.com/collectiveidea/devise-mongo_mapper'
gem 'devise_invitable', '~> 0.3.4'
#Authentication
gem 'omniauth'
gem 'twitter'
#Mongo
gem 'mongo_mapper', :branch => 'rails3', :git => 'git://github.com/jnunemaker/mongomapper.git'
gem 'bson_ext', '1.1'
......
......@@ -169,6 +169,9 @@ GEM
factory_girl_rails (1.0)
factory_girl (~> 1.3)
rails (>= 3.0.0.beta4)
faraday (0.4.6)
addressable (>= 2.1.1)
rack (>= 1.0.1)
ffi (0.6.3)
rake (>= 0.8.7)
gherkin (2.2.9)
......@@ -178,6 +181,8 @@ GEM
hashie (0.4.0)
highline (1.6.1)
http_connection (1.4.0)
httparty (0.6.1)
crack (= 0.1.8)
i18n (0.4.1)
json (1.4.6)
json_pure (1.4.6)
......@@ -205,6 +210,8 @@ GEM
moneta (0.6.0)
mongo (1.1)
bson (>= 1.0.5)
multi_json (0.0.4)
net-ldap (0.1.1)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
......@@ -213,6 +220,33 @@ GEM
net-ssh-gateway (1.0.1)
net-ssh (>= 1.99.1)
nokogiri (1.4.3.1)
oa-basic (0.1.5)
multi_json (~> 0.0.2)
nokogiri (~> 1.4.2)
oa-core (= 0.1.5)
rest-client (~> 1.6.0)
oa-core (0.1.5)
rack (~> 1.1)
oa-enterprise (0.1.5)
net-ldap (~> 0.1.1)
nokogiri (~> 1.4.2)
oa-core (= 0.1.5)
pyu-ruby-sasl (~> 0.0.3.1)
rubyntlm (~> 0.1.1)
oa-oauth (0.1.5)
multi_json (~> 0.0.2)
nokogiri (~> 1.4.2)
oa-core (= 0.1.5)
oauth (~> 0.4.0)
oauth2 (~> 0.0.10)
oa-openid (0.1.5)
oa-core (= 0.1.5)
rack-openid (~> 1.1.1)
ruby-openid-apps-discovery
oauth (0.4.3)
oauth2 (0.0.13)
faraday (~> 0.4.1)
multi_json (>= 0.0.4)
ohai (0.5.8)
extlib
json (>= 1.4.4, <= 1.4.6)
......@@ -220,15 +254,25 @@ GEM
mixlib-config
mixlib-log
systemu
omniauth (0.1.5)
oa-basic (= 0.1.5)
oa-core (= 0.1.5)
oa-enterprise (= 0.1.5)
oa-oauth (= 0.1.5)
oa-openid (= 0.1.5)
plucky (0.3.6)
mongo (~> 1.1)
polyglot (0.3.1)
pubsubhubbub (0.1.1)
em-http-request (>= 0.1.5)
eventmachine (>= 0.12.9)
pyu-ruby-sasl (0.0.3.2)
rack (1.2.1)
rack-mount (0.6.13)
rack (>= 1.0.0)
rack-openid (1.1.2)
rack (>= 0.4)
ruby-openid (>= 2.0.3)
rack-test (0.5.6)
rack (>= 1.0)
rails (3.0.1)
......@@ -264,6 +308,10 @@ GEM
ruby-debug-base (~> 0.10.3.0)
ruby-debug-base (0.10.3)
linecache (>= 0.3)
ruby-openid (2.1.8)
ruby-openid-apps-discovery (1.2.0)
ruby-openid (>= 2.1.7)
rubyntlm (0.1.1)
rubyzip (0.9.4)
selenium-webdriver (0.0.29)
childprocess (>= 0.0.7)
......@@ -280,6 +328,11 @@ GEM
thor (0.14.3)
treetop (1.4.8)
polyglot (>= 0.3.1)
twitter (0.9.12)
hashie (~> 0.4.0)
httparty (~> 0.6.1)
multi_json (~> 0.0.4)
oauth (~> 0.4.3)
tzinfo (0.3.23)
uuidtools (2.1.1)
warden (0.10.7)
......@@ -318,6 +371,7 @@ DEPENDENCIES
mini_magick
mocha
mongo_mapper!
omniauth
pubsubhubbub
rails (>= 3.0.0)
redfinger!
......@@ -327,5 +381,6 @@ DEPENDENCIES
ruby-debug
sprinkle!
thin
twitter
webmock
will_paginate (= 3.0.pre2)
......@@ -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,16 +43,4 @@ class ApplicationController < ActionController::Base
@invites = current_user.invites
end
end
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
......@@ -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
......
......@@ -4,37 +4,42 @@
class ServicesController < ApplicationController
before_filter :authenticate_user!
def create
puts 'services/create'
p params
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)
p access_token_hash
@access_token = access_token_hash["access_token"]
# 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."
end
redirect_to edit_user_url current_user
def index
@services = current_user.services
end
def destroy
warden.session[:access_token] = nil
warden.session[:user_id] = nil
redirect_to edit_user_url current_user
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
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
flash[:notice] = "Authentication successful."
redirect_to services_url
end
def destroy
@service = current_user.services.find(params[:id])
@service.destroy
flash[:notice] = "Successfully destroyed authentication."
redirect_to services_url
end
end
......@@ -9,13 +9,13 @@ class StatusMessagesController < ApplicationController
respond_to :json, :only => :show
def create
data = clean_hash params[:status_message]
if logged_into_fb? && params[:status_message][:public] == '1'
current_user.post_to_message_fb(params[:status_message][:message], @access_token)
end
public_flag = params[:status_message][:public]
public_flag.to_s.match(/(true)/) ? public_flag = true : public_flag = false
params[:status_message][:public] = public_flag
@status_message = current_user.post(:status_message, data)
data = clean_hash params[:status_message]
message = params[:status_message][:message]
status_message = current_user.post(:status_message, data)
render :nothing => true
end
......@@ -27,11 +27,7 @@ class StatusMessagesController < ApplicationController
def show
@status_message = current_user.find_visible_post_by_id params[:id]
unless @status_message
render :status => 404
else
respond_with @status_message
end
respond_with @status_message
end
private
......
......@@ -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
......
......@@ -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
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class FbStatus
include MongoMapper::Document
key :graph_id, String
key :author_id, String
key :author_name, String
key :message, String
key :updated_time, Time
timestamps!
validates_presence_of :graph_id,:author_id,:author_name,:message,:updated_time
def self.from_api(hash)
#just keeping them in memory for now
self.new(
:graph_id => hash['id'],
:author_id => hash['from']['id'],
:author_name => hash['from']['name'],
:message => hash['message'],
:updated_time => Time.parse(hash['updated_time'])
)
end
end
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Service
include MongoMapper::Document
belongs_to :user
key :provider, String
key :uid, String
key :access_token, String
key :access_secret, String
key :nickname, String
end
......@@ -61,6 +61,8 @@ class User
many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post'
many :aspects, :class_name => 'Aspect', :dependent => :destroy
many :services, :class_name => "Service"
#after_create :seed_aspects
before_destroy :unfriend_everyone, :remove_person
......@@ -149,21 +151,29 @@ class User
aspect_ids = validate_aspect_permissions(aspect_ids)
intitial_post(class_name, aspect_ids, options)
post = build_post(class_name, options)
post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid)
push_to_aspects(post, aspect_ids)
if options[:public] == true
self.services.each do |service|
self.send("post_to_#{service.provider}".to_sym, service, post.message)
end
end
post
end
def post_to_message_fb(message, access_token)
id = 'me'
type = 'feed'
def post_to_facebook(service, message)
Rails.logger.info("Sending a message: #{message} to Facebook")
EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{access_token}").post
EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{service.access_token}").post
end
def intitial_post(class_name, aspect_ids, options = {})
post = build_post(class_name, options)
post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid)
push_to_aspects(post, aspect_ids)
post
def post_to_twitter(service, message)
oauth = Twitter::OAuth.new(SERVICES['twitter']['consumer_token'], SERVICES['twitter']['consumer_secret'])
oauth.authorize_from_access(service.access_token, service.access_secret)
client = Twitter::Base.new(oauth)
client.update(message)
end
def update_post(post, post_hash = {})
......
-# 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" if SERVICES['twitter']['consumer_key']!= ""
%h4= link_to "Connect to facebook", "/auth/facebook" if SERVICES['facebook']['app_id'] !=""
......@@ -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'
......
......@@ -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();'
......@@ -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
......@@ -33,7 +35,7 @@
- if aspect == :all
.public_toggle
= status.check_box( :public, :value => false )
= status.check_box( :public, {}, true, false )
make public
= link_to '(?)', "#question_mark_pane", :class => 'question_mark'
......
-# 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
%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'
......@@ -56,9 +56,9 @@ namespace :deploy do
run "ln -s -f #{shared_path}/app_config.yml #{current_path}/config/app_config.yml"
end
task :symlink_fb_config do
run "touch #{shared_path}/fb_config.yml"
run "ln -s -f #{shared_path}/fb_config.yml #{current_path}/config/fb_config.yml"
task :symlink_oauth_keys_config do
run "touch #{shared_path}/oauth_keys.yml"
run "ln -s -f #{shared_path}/oauth_keys.yml #{current_path}/config/oauth_keys.yml"
end
task :start do
......@@ -157,4 +157,4 @@ namespace :db do
end
after "deploy:symlink", "deploy:symlink_images", "deploy:symlink_bundle", 'deploy:symlink_config', 'deploy:symlink_fb_config'
after "deploy:symlink", "deploy:symlink_images", "deploy:symlink_bundle", 'deploy:symlink_config', 'deploy:symlink_oauth_keys_config'
fb_api_key: {dcf4e90df086cf6d3e531b31e043ff32}
fb_secret: {7fe864834726f8a5e65bc93928b99a53}
fb_app_id: {120373411325347}
host: http://localhost:3000/
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter