66f433176a
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
26 lines
561 B
Ruby
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
|