Permalink
Browse files

WORK IN PROGRESS - Omniauth

  • Loading branch information...
1 parent fedcbf5 commit 94a464e53f489549178ecafc8c59d6af9fa0e746 Joe Peck committed Dec 21, 2012
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
+// Place all the styles related to the omniauth_callbacks controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,2 @@
+class OmniauthCallbacksController < Devise::OmniauthCallbacksController
+end
@@ -1,5 +1,8 @@
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def github
+
+
+ debugger
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.find_for_github_oauth(request.env["omniauth.auth"], current_user)
@@ -0,0 +1,2 @@
+module OmniauthCallbacksHelper
+end
View
@@ -22,11 +22,11 @@ def self.find_for_github_oauth(auth, signed_in_resource=nil)
user = User.where(:provider => auth.provider, :uid => auth.uid).first
unless user
user = User.create(nickname:auth.extra.raw_info.name,
- provider:auth.provider,
- uid:auth.uid,
- email:auth.info.email,
- password:Devise.friendly_token[0,20]
- )
+ provider:auth.provider,
+ uid:auth.uid,
+ email:auth.info.email,
+ password:Devise.friendly_token[0,20]
+ )
end
user
end
@@ -7,6 +7,9 @@
<%= csrf_meta_tags %>
</head>
<body>
+ <p><%= link_to "Sign in with Github", user_omniauth_authorize_path(:github) %></p>
+ <p class="notice"><%= notice %></p>
+ <p class="alert"><%= alert %></p>
<%= yield %>
</body>
</html>
@@ -1,5 +1,10 @@
Temptd::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
+
+ CLIENT_ID="4ed181654f694955a301"
+ CLIENT_SECRET="7b251ce80b9f09c93423d615ae0ffff4b7523b4f"
+
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
@@ -16,7 +16,7 @@
require 'devise/orm/active_record'
require "omniauth-github"
- config.omniauth :github, "APP_ID", "APP_SECRET"
+ config.omniauth :github, CLIENT_ID, CLIENT_SECRET
# ==> Configuration for any authentication mechanism
# Configure which keys are used when authenticating a user. The default is
View
@@ -1,6 +1,17 @@
Temptd::Application.routes.draw do
- devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
+ # devise_for :users
+ # devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
+ # devise_scope :users do
+ # get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
+ # end
+ #
+ # match "/auth/:provider/callback" => "devise/sessions#create"
+
+ devise_for :users, path_names: {sign_in: "login", sign_out: "logout"}, controllers: {omniauth_callbacks: "omniauth_callbacks"}
+
+
+
resources :events
resources :votes
@@ -0,0 +1,53 @@
+class AddDeviseToUsers < ActiveRecord::Migration
+ def self.up
+ change_table(:users) do |t|
+ ## Database authenticatable
+ t.string :email, :null => false, :default => ""
+ t.string :encrypted_password, :null => false, :default => ""
+
+ ## Recoverable
+ t.string :reset_password_token
+ t.datetime :reset_password_sent_at
+
+ ## Rememberable
+ t.datetime :remember_created_at
+
+ ## Trackable
+ t.integer :sign_in_count, :default => 0
+ t.datetime :current_sign_in_at
+ t.datetime :last_sign_in_at
+ t.string :current_sign_in_ip
+ t.string :last_sign_in_ip
+
+ ## Confirmable
+ # t.string :confirmation_token
+ # t.datetime :confirmed_at
+ # t.datetime :confirmation_sent_at
+ # t.string :unconfirmed_email # Only if using reconfirmable
+
+ ## Lockable
+ # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
+ # t.datetime :locked_at
+
+ ## Token authenticatable
+ # t.string :authentication_token
+
+
+ # Uncomment below if timestamps were not included in your original model.
+ # t.timestamps
+ end
+
+ add_index :users, :email, :unique => true
+ add_index :users, :reset_password_token, :unique => true
+ # add_index :users, :confirmation_token, :unique => true
+ # add_index :users, :unlock_token, :unique => true
+ # add_index :users, :authentication_token, :unique => true
+ end
+
+ def self.down
+ # By default, we don't want to make any assumption about how to roll back a migration when your
+ # model already existed. Please edit below which fields you would like to remove in this migration.
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe OmniauthCallbacksController do
+
+end
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the OmniauthCallbacksHelper. For example:
+#
+# describe OmniauthCallbacksHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe OmniauthCallbacksHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end

0 comments on commit 94a464e

Please sign in to comment.