Browse files

stuff

  • Loading branch information...
1 parent e34d786 commit bf83683aa149b393b9c7c8ae463a1d69bef2b51e Holden Thomas committed Nov 6, 2010
Showing with 89 additions and 15 deletions.
  1. +42 −7 app/controllers/users/omniauth_callbacks_controller.rb
  2. +1 −0 app/models/user.rb
  3. +3 −0 app/models/user_token.rb
  4. +4 −0 app/views/devise/registrations/edit.html.erb
  5. +10 −7 app/views/devise/shared/_links.erb
  6. +5 −0 config/initializers/devise.rb
  7. +15 −0 db/migrate/20101106080918_create_user_tokens.rb
  8. +9 −1 db/schema.rb
  9. BIN public/images/social-icons/aol_128.png
  10. BIN public/images/social-icons/aol_256.png
  11. BIN public/images/social-icons/aol_32.png
  12. BIN public/images/social-icons/aol_64.png
  13. BIN public/images/social-icons/basecamp_128.png
  14. BIN public/images/social-icons/basecamp_256.png
  15. BIN public/images/social-icons/basecamp_32.png
  16. BIN public/images/social-icons/basecamp_64.png
  17. BIN public/images/social-icons/campfire_128.png
  18. BIN public/images/social-icons/campfire_256.png
  19. BIN public/images/social-icons/campfire_32.png
  20. BIN public/images/social-icons/campfire_64.png
  21. BIN public/images/social-icons/facebook_128.png
  22. BIN public/images/social-icons/facebook_256.png
  23. BIN public/images/social-icons/facebook_32.png
  24. BIN public/images/social-icons/facebook_64.png
  25. BIN public/images/social-icons/github_128.png
  26. BIN public/images/social-icons/github_256.png
  27. BIN public/images/social-icons/github_32.png
  28. BIN public/images/social-icons/github_64.png
  29. BIN public/images/social-icons/google_128 copy.png
  30. BIN public/images/social-icons/google_128.png
  31. BIN public/images/social-icons/google_256 copy.png
  32. BIN public/images/social-icons/google_256.png
  33. BIN public/images/social-icons/google_32.png
  34. BIN public/images/social-icons/google_64 copy.png
  35. BIN public/images/social-icons/google_apps_32.png
  36. BIN public/images/social-icons/google_apps_64.png
  37. BIN public/images/social-icons/linkedin_128.png
  38. BIN public/images/social-icons/linkedin_256.png
  39. BIN public/images/social-icons/linkedin_32.png
  40. BIN public/images/social-icons/linkedin_64.png
  41. BIN public/images/social-icons/myspace_128.png
  42. BIN public/images/social-icons/myspace_256.png
  43. BIN public/images/social-icons/myspace_32.png
  44. BIN public/images/social-icons/myspace_64.png
  45. BIN public/images/social-icons/openid_128.png
  46. BIN public/images/social-icons/openid_256.png
  47. BIN public/images/social-icons/openid_32.png
  48. BIN public/images/social-icons/openid_64.png
  49. BIN public/images/social-icons/presently_128.png
  50. BIN public/images/social-icons/presently_256.png
  51. BIN public/images/social-icons/presently_32.png
  52. BIN public/images/social-icons/presently_64.png
  53. BIN public/images/social-icons/twitter_128.png
  54. BIN public/images/social-icons/twitter_256.png
  55. BIN public/images/social-icons/twitter_32.png
  56. BIN public/images/social-icons/twitter_64.png
  57. BIN public/images/social-icons/yahoo_128.png
  58. BIN public/images/social-icons/yahoo_256.png
  59. BIN public/images/social-icons/yahoo_32.png
  60. BIN public/images/social-icons/yahoo_64.png
View
49 app/controllers/users/omniauth_callbacks_controller.rb
@@ -2,14 +2,49 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
# # You need to implement the method below in your model
# @user = User.find_for_facebook_oauth(env["omniauth.auth"], current_user)
- @user = User.find(1)
- #
- if @user.persisted?
- flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
- sign_in_and_redirect @user, :event => :authentication
+ # @user = User.find(1)
+ # #
+ # if @user.persisted?
+ # flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
+ # sign_in_and_redirect @user, :event => :authentication
+ # else
+ # session["devise.facebook_data"] = env["omniauth.auth"]
+ # redirect_to new_user_registration_url
+ # end
+ do_everything_in_one_callback_instead_of_ten
+ end
+
+ def twitter
+ do_everything_in_one_callback_instead_of_ten
+ end
+
+ def google_apps
+ do_everything_in_one_callback_instead_of_ten
+ end
+
+ def do_everything_in_one_callback_instead_of_ten
+ omniauth = request.env["omniauth.auth"]
+
+ if current_user #if the user has an account and wants to add more authentications
+ auth = env["omniauth.auth"]
+ current_user.user_tokens.find_or_create_by_provider_and_uid(auth['provider'], auth['uid'])
+ flash[:notice] = "Authentication successful"
+ redirect_to edit_user_registration_path
else
- session["devise.facebook_data"] = env["omniauth.auth"]
- redirect_to new_user_registration_url
+ #find and logged them in
+ authentication = UserToken.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
+
+ if authentication
+ flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => omniauth['provider']
+ sign_in_and_redirect(:user, authentication.user)
+ #sign_in_and_redirect @user, :event => :authentication
+ #render :text => env["omniauth.auth"].to_yaml
+ else
+ #no account exists
+ session["devise.facebook_data"] = env["omniauth.auth"]
+ redirect_to new_user_registration_url
+ end
end
end
+
end
View
1 app/models/user.rb
@@ -1,4 +1,5 @@
class User < ActiveRecord::Base
+ has_many :user_tokens
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable,
View
3 app/models/user_token.rb
@@ -0,0 +1,3 @@
+class UserToken < ActiveRecord::Base
+ belongs_to :user
+end
View
4 app/views/devise/registrations/edit.html.erb
@@ -18,6 +18,10 @@
<p><%= f.submit "Update" %></p>
<% end %>
+Add some omniauth goodness:
+
+<%= render :partial => "devise/shared/links" %>
+
<h3>Cancel my account</h3>
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
View
17 app/views/devise/shared/_links.erb
@@ -6,10 +6,6 @@
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end -%>
-<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
- <%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
-<% end -%>
-
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>
@@ -19,7 +15,14 @@
<% end -%>
<%- if devise_mapping.omniauthable? %>
- <%- resource_class.omniauth_providers.each do |provider| %>
- <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
- <% end -%>
+ <ul id="social-icons">
+ <%- resource_class.omniauth_providers.each do |provider| %>
+ <li><%= link_to image_tag("social-icons/#{provider}_32.png", :alt => "Sign in with #{provider.to_s.titleize}"), omniauth_authorize_path(resource_name, provider) %></li>
+ <% end -%>
+ </ul>
+ <div class="clear"></div>
+<% end -%>
+
+<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
+ <%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
View
5 config/initializers/devise.rb
@@ -1,5 +1,8 @@
# Use this hook to configure devise mailer, warden hooks and so forth. The first
# four configuration values can also be set straight in your models.
+
+require 'openid/store/filesystem'
+
Devise.setup do |config|
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in DeviseMailer.
@@ -133,6 +136,8 @@
#config.omniauth :facebook, "APP_ID", "APP_SECRET"
config.omniauth :facebook, "147749211905466", "b682557c3bc08512d09ebc4b848d8d93"
+ config.omniauth :twitter, "fno1nY6Vx8G80mNFXKPukg", "UnTQrcu2nPG5bqTS3KYdRPkQ2wKgSZz4uBC1RRpRD0"
+ config.omniauth :google_apps, OpenID::Store::Filesystem.new('/tmp'), :domain => 'gmail.com'
#
# config.warden do |manager|
# manager.oauth(:twitter) do |twitter|
View
15 db/migrate/20101106080918_create_user_tokens.rb
@@ -0,0 +1,15 @@
+class CreateUserTokens < ActiveRecord::Migration
+ def self.up
+ create_table :user_tokens do |t|
+ t.integer :user_id
+ t.string :provider
+ t.string :uid
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :user_tokens
+ end
+end
View
10 db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20101105152716) do
+ActiveRecord::Schema.define(:version => 20101106080918) do
create_table "monkeys", :force => true do |t|
t.string "name"
@@ -19,6 +19,14 @@
t.datetime "updated_at"
end
+ create_table "user_tokens", :force => true do |t|
+ t.integer "user_id"
+ t.string "provider"
+ t.string "uid"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
View
BIN public/images/social-icons/aol_128.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/aol_256.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/aol_32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/aol_64.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/basecamp_128.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/basecamp_256.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/basecamp_32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/basecamp_64.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/campfire_128.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/campfire_256.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/campfire_32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/campfire_64.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/facebook_128.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/facebook_256.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/facebook_32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/facebook_64.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/github_128.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/github_256.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/github_32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/github_64.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/google_128 copy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/google_128.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/google_256 copy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/google_256.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/google_32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN public/images/social-icons/google_64 copy.png
Diff not rendered.
View
BIN public/images/social-icons/google_apps_32.png
Diff not rendered.
View
BIN public/images/social-icons/google_apps_64.png
Diff not rendered.
View
BIN public/images/social-icons/linkedin_128.png
Diff not rendered.
View
BIN public/images/social-icons/linkedin_256.png
Diff not rendered.
View
BIN public/images/social-icons/linkedin_32.png
Diff not rendered.
View
BIN public/images/social-icons/linkedin_64.png
Diff not rendered.
View
BIN public/images/social-icons/myspace_128.png
Diff not rendered.
View
BIN public/images/social-icons/myspace_256.png
Diff not rendered.
View
BIN public/images/social-icons/myspace_32.png
Diff not rendered.
View
BIN public/images/social-icons/myspace_64.png
Diff not rendered.
View
BIN public/images/social-icons/openid_128.png
Diff not rendered.
View
BIN public/images/social-icons/openid_256.png
Diff not rendered.
View
BIN public/images/social-icons/openid_32.png
Diff not rendered.
View
BIN public/images/social-icons/openid_64.png
Diff not rendered.
View
BIN public/images/social-icons/presently_128.png
Diff not rendered.
View
BIN public/images/social-icons/presently_256.png
Diff not rendered.
View
BIN public/images/social-icons/presently_32.png
Diff not rendered.
View
BIN public/images/social-icons/presently_64.png
Diff not rendered.
View
BIN public/images/social-icons/twitter_128.png
Diff not rendered.
View
BIN public/images/social-icons/twitter_256.png
Diff not rendered.
View
BIN public/images/social-icons/twitter_32.png
Diff not rendered.
View
BIN public/images/social-icons/twitter_64.png
Diff not rendered.
View
BIN public/images/social-icons/yahoo_128.png
Diff not rendered.
View
BIN public/images/social-icons/yahoo_256.png
Diff not rendered.
View
BIN public/images/social-icons/yahoo_32.png
Diff not rendered.
View
BIN public/images/social-icons/yahoo_64.png
Diff not rendered.

0 comments on commit bf83683

Please sign in to comment.