-
-
Save divoxx/594580 to your computer and use it in GitHub Desktop.
This file contains 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 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 | |
# We make an alias of profile_assoc to the generated profile_method | |
alias_method :profile_assoc, :profile | |
def profile | |
profile_assoc || 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