From 26478403e2efeb2906510ea74509e2870cc3e06e Mon Sep 17 00:00:00 2001 From: danielvincent Date: Wed, 22 Sep 2010 17:14:58 -0700 Subject: [PATCH] DG IZ; connecting/disconnecting from fb --- app/controllers/application_controller.rb | 2 +- app/controllers/services_controller.rb | 11 +++++++++-- app/views/users/edit.html.haml | 15 ++++++++------- config/routes.rb | 1 + 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0060a8989..2fecb4f90 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -39,7 +39,7 @@ class ApplicationController < ActionController::Base end def fb_user_info - @access_token = cookies[:access_token] + @access_token = session[:access_token] @logged_in = @access_token.present? end diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index b254b0a63..ab654e739 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -16,10 +16,17 @@ class ServicesController < ApplicationController @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 + # but for now, we'll just keep it in the session so we don't need a database + session[:access_token] = @access_token flash[:success] = "Authentication successful." end redirect_to edit_user_url current_user end + + def destroy + session[:access_token] = nil + session[:user_id] = nil + redirect_to edit_user_url current_url + end + end diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index bfb4e92e1..924b0f72f 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -60,13 +60,14 @@ %h2 Services %h3 Facebook - - - if @logged_in - Logged in to facebook as - - @response_hash = MiniFB.get(@access_token, @id, :type => "user") - = @response_hash[:user][:name] - %p - = link_to "Login to Facebook", @fb_access_url + %p + - if @logged_in + Connected to facebook as + - @response_hash = MiniFB.get(@access_token, 'me') + = @response_hash[:name] + = link_to "Disconnect from Facebook", services_destroy_path + - else + = link_to "Connect to Facebook", @fb_access_url #submit_block diff --git a/config/routes.rb b/config/routes.rb index 016a89bcb..57e58e9aa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,6 +19,7 @@ Diaspora::Application.routes.draw do resources :aspects, :except => [:edit] match 'services/create', :to => "services#create" + match 'services/destroy', :to => "services#destroy" match 'warzombie', :to => "dev_utilities#warzombie" match 'zombiefriends', :to => "dev_utilities#zombiefriends"