Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: c896e2a918
Fetching contributors…

Cannot retrieve contributors at this time

34 lines (25 sloc) 0.978 kb
class User < ActiveRecord::Base
attr_accessible :gh_id, :gh_email, :gh_name, :gh_avatar_url, :gh_oauth_token, :gh_url, :gh_username
has_many :gists, :dependent => :destroy
scope :last_fetched_before, lambda { |since| where(["last_gh_fetch < ?", since])}
class << self
def authenticate(auth)
attributes = {
gh_id: auth.uid, gh_oauth_token: auth.credentials.token, gh_username: auth.info.nickname, gh_name: auth.info.name,
gh_email: auth.info.email, gh_avatar_url: auth.info.image, gh_url: auth.info.urls.GitHub
}
if(existing_user = User.where(gh_id: auth.uid).first)
log({ns: self, fn: __method__}, existing_user)
existing_user.update_attributes(attributes)
existing_user
else
new_user = User.create(attributes)
log({ns: self, fn: __method__}, new_user)
new_user
end
end
end
def to_log
{ user: gh_username, user_id: id, user_email: gh_email }
end
end
Jump to Line
Something went wrong with that request. Please try again.