Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 56014a9325
Fetching contributors…

Cannot retrieve contributors at this time

file 24 lines (18 sloc) 0.679 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
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

  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)
        existing_user.update_attributes(attributes)
        existing_user
      else
        User.create(attributes)
      end
    end
  end
end
Something went wrong with that request. Please try again.