diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/models/invite_code.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb index 701b663..30d32d6 100644 --- a/app/models/invite_code.rb +++ b/app/models/invite_code.rb @@ -1,3 +1,5 @@ +require 'base64' +require 'securerandom' class InviteCode < CouchRest::Model::Base use_database 'invite_codes' @@ -13,10 +15,14 @@ class InviteCode < CouchRest::Model::Base def initialize(attributes = {}, options = {}) super(attributes, options) - write_attribute('invite_code', CouponCode.generate) if new? + write_attribute('invite_code', generate_invite) if new? end + def generate_invite + Base64.encode64(SecureRandom.random_bytes).downcase.gsub(/[0oil1+_\/]/,'')[0..7].scan(/..../).join('-') + end + def set_invite_code(code) write_attribute(:invite_code, code) end |