Created
June 23, 2013 03:54
-
-
Save subhashb/5843734 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
# Include default devise modules. Others available are: | |
# :token_authenticatable, :confirmable, | |
# :lockable, :timeoutable | |
devise :database_authenticatable, :registerable, | |
:recoverable, :rememberable, :trackable, :validatable, | |
:omniauthable | |
def full_name | |
([first_name, last_name] - ['']).compact.join(' ') | |
end | |
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_attributes"] | |
new(session["devise.user_attributes"]) do |user| | |
user.attributes = params | |
user.valid? | |
end | |
else | |
super | |
end | |
end | |
def password_required? | |
super && provider.blank? | |
end | |
def update_with_password(params, *options) | |
if encrypted_password.blank? | |
update_attributes(params, *options) | |
else | |
super | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment