summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorankonym <ankonym@gmail.com>2015-10-09 13:06:42 +0200
committerankonym <ankonym@gmail.com>2015-10-13 11:47:56 +0200
commit244d6e99bd2a911c68f77ec006a852dffc7d6303 (patch)
treef3e8167908ae04cd5d3dc03aad64a4dd3de83771 /app/models
parent2541d08598c2bc4ce04f63b4ed4056ffb044a596 (diff)
Replace Coupon Code gem for invite code creation
Replacing the Coupon Code gem with base64/securerandom as suggested by Elijah.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/invite_code.rb8
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