Skip to content

Instantly share code, notes, and snippets.

@mmurray
Created September 23, 2010 23:10
Show Gist options
  • Save mmurray/594579 to your computer and use it in GitHub Desktop.
Save mmurray/594579 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable, :token_authenticatable,
:oauthable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :has_username, :is_admin, :profile
validates :username, :presence => true
validates_uniqueness_of :username
has_one :profile
def profile
super || build_profile
end
def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
data = ActiveSupport::JSON.decode(access_token.get('https://graph.facebook.com/me?'))
if user = User.find_by_email(data["email"])
user
else
# Create an user with a stub password.
u = User.create!(:email => data["email"], :password => Devise.friendly_token, :username => Devise.friendly_token, :has_username => false)
u.skip_confirmation!
u
end
end
def to_s
self.profile.avatar.url
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment