journalduhacker/app/models/invitation_request.rb
joshua stein 66f433176a add an invitiation request queue
the user tree is pretty big to look through now, so let users submit
a request for an invitation, which logged-in users can browse and
instantly send invites to
2013-10-18 15:49:20 -05:00

26 lines
561 B
Ruby

class InvitationRequest < ActiveRecord::Base
attr_accessible nil
validates :name, :presence => true
validates :email, :format => { :with => /\A[^@ ]+@[^@ ]+\.[^@ ]+\Z/ }
before_validation :create_code
after_create :send_email
def create_code
(1...10).each do |tries|
if tries == 10
raise "too many hash collisions"
end
if !InvitationRequest.find_by_code(self.code = Utils.random_str(15))
break
end
end
end
def send_email
InvitationRequestMailer.invitation_request(self).deliver
end
end