Skip to content

Instantly share code, notes, and snippets.

@austenito
Created June 23, 2012 21:21
Show Gist options
  • Save austenito/2980061 to your computer and use it in GitHub Desktop.
Save austenito/2980061 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
devise :recoverable, :trackable, :omniauthable
attr_accessible :name, :provider, :uid, :email, :access_token
has_many :deal_groups, :foreign_key => "owner_id"
has_one :payment
has_many :deal_group_users
def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
uid = auth["uid"]
provider = auth["provider"]
user = User.where(:provider => provider, :uid => uid).first
unless user
user = User.create!(:name => auth["extra"]["raw_info"]["name"],
:provider => provider,
:uid => uid,
:email => auth["info"]["email"],
:access_token => auth["credentials"]["token"])
end
user
end
def create_deal_group(link)
deal = Deal.find_or_create_from_link(link)
deal_group = DealGroup.new(:deal => deal)
deal_groups << deal_group
deal_group_users << DealGroupUser.new(:deal_group => deal_group)
deal_group
end
def set_payment(stripe_token)
customer = Stripe::Customer.create( :card => stripe_token,
:description => email)
self.payment = Payment.create(:customer_id => customer.id,
:stripe_token => stripe_token,
:last_four_digits => customer.active_card.last4,
:card_type => customer.active_card.type)
payment
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment