Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View omniauth_callbacks_controller.rb
1 2 3 4 5 6 7 8 9 10 11 12 13
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
 
def all
user = User.from_omniauth(request.env["omniauth.auth"])
if user.persisted?
sign_in_and_redirect @user, :event => :authentication
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_path(@user)
end
end
alias_method :twitter, :all
end
View omniauth_callbacks_controller.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
class User < ActiveRecord::Base
attr_accessible :username, :email, :password, :password_confirmation, :remember_me
attr_accessible :title, :body
validates_confirmation_of :password
validates_presence_of :password, :on => :create
validates_presence_of :email, :on => :create
validates_presence_of :username, :on => :create
validates_uniqueness_of :email
validates_uniqueness_of :username
has_many :articles, :order => "created_at DESC"
has_many :comments
# Include default devise modules. Others available are:
# :token_authenticatable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :omniauthable,
:recoverable, :rememberable, :trackable, :validatable
 
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.username = auth.info.nickname
end
end
 
def self.new_with_session(params, session)
if session["devise.user_attritubes"]
new(session["devise.user_attributes"], without_protection: true) do |user|
user.attributes = params
user.valid?
end
else
super
end
end
 
def password_required?
super && provider.blank?
end
 
 
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.