diff --git a/Gemfile b/Gemfile index cc92bec3d..18cfef692 100644 --- a/Gemfile +++ b/Gemfile @@ -21,6 +21,7 @@ gem 'will_paginate', '3.0.pre2' gem 'roxml', :git => 'git://github.com/Empact/roxml.git' gem 'addressable', :require => 'addressable/uri' gem 'json' +gem 'mini_fb' #Standards gem 'pubsubhubbub' diff --git a/Gemfile.lock b/Gemfile.lock index dd181b320..68cf44272 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -142,6 +142,9 @@ GEM mime-types treetop (>= 1.4.5) mime-types (1.16) + mini_fb (1.1.3) + hashie + rest-client mini_magick (2.1) subexec (~> 0.0.4) mocha (0.9.8) @@ -252,6 +255,7 @@ DEPENDENCIES jnunemaker-validatable (= 1.8.4)! json magent! + mini_fb mini_magick mocha mongo_mapper (= 0.8.4)! diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb new file mode 100644 index 000000000..567a1d144 --- /dev/null +++ b/app/controllers/services_controller.rb @@ -0,0 +1,25 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3. See +# the COPYRIGHT file. + + +class ServicesController < ApplicationController + + 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, HOST + "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 cookie so we don't need a database + cookies[:access_token] = @access_token + flash[:success] = "Authentication successful." + end + redirect_to edit_user_url current_user + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index dbb69d1a2..76ed944dd 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -13,6 +13,9 @@ class UsersController < ApplicationController @person = @user.person @profile = @user.profile @photos = Photo.find_all_by_person_id(@person.id).paginate :page => params[:page], :order => 'created_at DESC' + + @fb_access_url = MiniFB.oauth_url(FB_APP_ID, HOST + "services/create", + :scope=>MiniFB.scopes.join(",")) end def update diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index fd94b2a42..330ad7f48 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -53,6 +53,14 @@ = p.label :last_name = p.text_field :last_name, :value => @profile.last_name + %br + %br + + %h3 Connect with Facebook + + %p + = link_to "Login to Facebook", @fb_access_url + #submit_block = link_to "Cancel", root_path or diff --git a/config/environment.rb b/config/environment.rb index 385a96651..7bf59851a 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -8,7 +8,14 @@ require File.expand_path('../application', __FILE__) Haml::Template.options[:format] = :html5 Haml::Template.options[:escape_html] = true + +# Load facebook connection application credentials +fb_config = YAML::load(File.open(File.expand_path("./config/fb_config.yml"))) +FB_API_KEY = fb_config['fb_api_key'] +FB_SECRET = fb_config['fb_secret'] +FB_APP_ID = fb_config['fb_app_id'] +HOST = fb_config['host'] + # Initialize the rails application Diaspora::Application.initialize! - diff --git a/config/fb_config.yml b/config/fb_config.yml new file mode 100644 index 000000000..7b69791e5 --- /dev/null +++ b/config/fb_config.yml @@ -0,0 +1,4 @@ +fb_api_key: {dcf4e90df086cf6d3e531b31e043ff32} +fb_secret: {36917c2878d658b8c575952b6a78e3c3} +fb_app_id: {120373411325347} +host: http://localhost:3000/ diff --git a/config/routes.rb b/config/routes.rb index ae757499c..016a89bcb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,32 +5,33 @@ Diaspora::Application.routes.draw do - resources :people, :only => [:index, :show, :destroy] - resources :users, :except => [:create, :new, :show] - resources :status_messages, :only => [:create, :destroy, :show] - resources :comments, :except => [:index] - resources :requests, :except => [:edit, :update] - resources :photos, :except => [:index] + resources :people, :only => [:index, :show, :destroy] + resources :users, :except => [:create, :new, :show] + resources :status_messages, :only => [:create, :destroy, :show] + resources :comments, :except => [:index] + resources :requests, :except => [:edit, :update] + resources :photos, :except => [:index] resources :albums match 'aspects/move_friends', :to => 'aspects#move_friends', :as => 'move_friends' - match 'aspects/move_friend', :to => 'aspects#move_friend', :as => 'move_friend' - match 'aspects/manage', :to => 'aspects#manage' - resources :aspects, :except => [:edit] + match 'aspects/move_friend', :to => 'aspects#move_friend', :as => 'move_friend' + match 'aspects/manage', :to => 'aspects#manage' + resources :aspects, :except => [:edit] + match 'services/create', :to => "services#create" - match 'warzombie', :to => "dev_utilities#warzombie" - match 'zombiefriends', :to => "dev_utilities#zombiefriends" - match 'zombiefriendaccept', :to => "dev_utilities#zombiefriendaccept" - match 'set_backer_number', :to => "dev_utilities#set_backer_number" - match 'set_profile_photo', :to => "dev_utilities#set_profile_photo" + match 'warzombie', :to => "dev_utilities#warzombie" + match 'zombiefriends', :to => "dev_utilities#zombiefriends" + match 'zombiefriendaccept', :to => "dev_utilities#zombiefriendaccept" + match 'set_backer_number', :to => "dev_utilities#set_backer_number" + match 'set_profile_photo', :to => "dev_utilities#set_profile_photo" #routes for devise, not really sure you will need to mess with this in the future, lets put default, #non mutable stuff in anohter file devise_for :users, :controllers => {:registrations => "registrations"} match 'login', :to => 'devise/sessions#new', :as => "new_user_session" match 'logout', :to => 'devise/sessions#destroy', :as => "destroy_user_session" - match 'signup', :to => 'registrations#new', :as => "new_user_registration" + match 'signup', :to => 'registrations#new', :as => "new_user_registration" match 'get_to_the_choppa', :to => redirect("/signup") #public routes