Permalink
Browse files

Moving to Joe's computer.

  • Loading branch information...
1 parent 6d202fa commit daf2ea412456552b492d8dc5ee8e0e6abd82bdee Mike Simpson committed Dec 21, 2012
Showing with 25 additions and 4 deletions.
  1. +21 −0 app/models/user.rb
  2. +3 −3 config/initializers/devise.rb
  3. +1 −1 config/routes.rb
View
21 app/models/user.rb
@@ -9,4 +9,25 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :nickname, :provider, :uid
+
+ def self.new_with_session(params, session)
+ super.tap do |user|
+ if data = session["devise.github_data"] && session["devise.github_data"]["extra"]["raw_info"]
+ user.email = data["email"] if user.email.blank?
+ end
+ end
+ end
+
+ 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]
+ )
+ end
+ user
+ end
end
View
6 config/initializers/devise.rb
@@ -4,7 +4,7 @@
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
- config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
+ config.mailer_sender = "joe.peck@scimedsolutions.com"
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
@@ -16,7 +16,7 @@
require 'devise/orm/active_record'
require "omniauth-github"
- config.omniauth :facebook, "APP_ID", "APP_SECRET"
+ config.omniauth :github, "APP_ID", "APP_SECRET"
# ==> Configuration for any authentication mechanism
# Configure which keys are used when authenticating a user. The default is
@@ -232,4 +232,4 @@
# When using omniauth, Devise cannot automatically set Omniauth path,
# so you need to do it manually. For the users scope, it would be:
# config.omniauth_path_prefix = "/my_engine/users/auth"
-end
+end
View
2 config/routes.rb
@@ -1,6 +1,6 @@
Temptd::Application.routes.draw do
- devise_for :users
+ devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
resources :events
resources :votes

0 comments on commit daf2ea4

Please sign in to comment.