Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 29th, 2012  |  syntax: None  |  size: 2.07 KB  |  views: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. devise_scope :user do
  2.     get 'sign_up', to: 'members#new', controllers: {registrations: "members"}
  3.     get 'partners/sign_up', to: 'content_partners#new', controllers: {registrations: "content_partners"}
  4.   end
  5.   devise_for :users, controllers: {omniauth_callbacks: "omniauth_callbacks"}
  6.        
  7. require "omniauth-twitter"
  8.    config.omniauth :twitter, 'CONSUMER_KEY', 'CONSUMER_SECRET'
  9.        
  10. gem "omniauth", "~> 1.1.1"
  11. gem "omniauth-twitter", "~> 0.0.14"
  12.        
  13. class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  14.   def all
  15.     user = User.from_omniauth(request.env["omniauth.auth"])
  16.     if user.persisted?
  17.       flash.notice = "Signed in!"
  18.       sign_in_and_redirect user
  19.     else
  20.       session["devise.user_attributes"] = user.attributes
  21.       redirect_to sign_up_path
  22.     end
  23.   end
  24.   alias_method :twitter, :all
  25. end
  26.        
  27. def self.from_omniauth(auth)
  28.     where(auth.slice(:provider, :uid)).first_or_create do |user|
  29.       user.provider = auth.provider
  30.       user.uid = auth.uid
  31.     end
  32.   end
  33.  
  34.   def self.new_with_session(params, session)
  35.     if session["devise.user_attributes"]
  36.       new(session["devise.user_attributes"], without_protection: true) do |user|
  37.         user.attributes = params
  38.         user.valid?
  39.       end
  40.     else
  41.       super
  42.     end
  43.   end
  44.        
  45. <%= link_to "or Sign up with Twitter", user_omniauth_authorize_path(:twitter) %>
  46.        
  47. Started GET "/users/auth/twitter" for 127.0.0.1 at 2012-12-11 15:54:01 +0000
  48. (twitter) Callback phase initiated.
  49.  
  50.  
  51. Started GET "/users/auth/twitter/callback?oauth_token=****blanked****&oauth_verifier=****blanked****" for 127.0.0.1 at 2012-12-11 15:54:03 +0000
  52. Processing by OmniauthCallbacksController#twitter as HTML
  53.   Parameters: {"oauth_token"=>"****blanked****", "oauth_verifier"=>"****blanked****"}
  54.   User Load (0.5ms)  SELECT "users".* FROM "users" WHERE "users"."provider" = 'twitter' AND "users"."uid" = '803184474' LIMIT 1
  55.    (0.1ms)  BEGIN
  56.   User Exists (0.4ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" IS NULL LIMIT 1
  57.    (0.2ms)  ROLLBACK
  58. Redirected to http://localhost:3000/sign_up
  59. Completed 302 Found in 8ms (ActiveRecord: 1.3ms)
clone this paste RAW Paste Data