Skip to content

Instantly share code, notes, and snippets.

@Vinay50
Created May 4, 2013 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vinay50/5518614 to your computer and use it in GitHub Desktop.
Save Vinay50/5518614 to your computer and use it in GitHub Desktop.
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
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