Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View invite.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
require 'digest/sha1'
 
class Invite < ActiveRecord::Base
validates_presence_of :email, :on => :save, :message => "can't be blank"
validates_uniqueness_of :email, :on => :save, :message => "is already registered"
 
named_scope :unsent_invitations, :conditions => {:redeemed_at => nil, :invite_code => nil}
 
def invited?
!!self.invite_code && !!self.invited_at
end
def invite!
self.invite_code = Digest::SHA1.hexdigest("--#{Time.now.utc.to_s}--#{self.email}--")
self.invited_at = Time.now.utc
self.save!
end
def self.find_redeemable(invite_code)
self.find(:first, :conditions => {:redeemed_at => nil, :invite_code => invite_code})
end
 
def redeemed!
self.redeemed_at = Time.now.utc
self.save!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.