summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/invite_code.rb8
-rw-r--r--lib/tasks/invite_code.rake1
2 files changed, 8 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
diff --git a/lib/tasks/invite_code.rake b/lib/tasks/invite_code.rake
index b379d3a..fa397bb 100644
--- a/lib/tasks/invite_code.rake
+++ b/lib/tasks/invite_code.rake
@@ -19,3 +19,4 @@ task :generate_invites, [:n, :u] => :environment do |task, args|
end
end
+