diff options
author | ankonym <ankonym@gmail.com> | 2015-10-09 13:06:42 +0200 |
---|---|---|
committer | ankonym <ankonym@gmail.com> | 2015-10-13 11:47:56 +0200 |
commit | 244d6e99bd2a911c68f77ec006a852dffc7d6303 (patch) | |
tree | f3e8167908ae04cd5d3dc03aad64a4dd3de83771 | |
parent | 2541d08598c2bc4ce04f63b4ed4056ffb044a596 (diff) |
Replace Coupon Code gem for invite code creation
Replacing the Coupon Code gem with base64/securerandom as suggested by Elijah.
-rw-r--r-- | app/models/invite_code.rb | 8 | ||||
-rw-r--r-- | lib/tasks/invite_code.rake | 1 |
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 + |