diff options
author | elijah <elijah@riseup.net> | 2016-01-10 13:48:21 -0800 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2016-01-10 13:48:21 -0800 |
commit | 23f3b872a83fe068fd32500db1ee4b112176ca7f (patch) | |
tree | 7a5e60bbddfc77d11408db23ed1bb1e0bcf14457 | |
parent | ba98c75ca83b6236bc4c953396638ea8b6d2ece2 (diff) | |
parent | be1f937ac57c4acaeda5c1377e7023b2d5766dd8 (diff) |
Merge branch 'remove_couponcode' into develop
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | Gemfile.lock | 2 | ||||
-rw-r--r-- | app/models/invite_code.rb | 13 |
3 files changed, 11 insertions, 5 deletions
@@ -13,7 +13,6 @@ end ## AUTHENTICATION gem "ruby-srp", "~> 0.2.1" gem "rails_warden" -gem "coupon_code" ## LOCALIZATION gem 'http_accept_language' diff --git a/Gemfile.lock b/Gemfile.lock index 7f5e21a..da4df87 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -92,7 +92,6 @@ GEM actionpack (~> 3.0) couchrest couchrest_model - coupon_code (0.0.1) cucumber (1.3.17) builder (>= 2.1.2) diff-lcs (>= 1.1.3) @@ -283,7 +282,6 @@ DEPENDENCIES couchrest (~> 1.1.3) couchrest_model (~> 2.0.0) couchrest_session_store (= 0.3.0) - coupon_code cucumber-rails debugger factory_girl_rails diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb index 13c3a39..5666a4f 100644 --- a/app/models/invite_code.rb +++ b/app/models/invite_code.rb @@ -1,4 +1,5 @@ -require 'coupon_code' +require 'base64' +require 'securerandom' class InviteCode < CouchRest::Model::Base use_database 'invite_codes' @@ -14,10 +15,18 @@ class InviteCode < CouchRest::Model::Base end def initialize(attributes = {}, options = {}) + if !attributes.has_key?("_id") + attributes[:id] = InviteCode.generate_invite + end + super(attributes, options) - write_attribute('invite_code', CouponCode.generate) if new? + + write_attribute('invite_code', attributes[:id]) if new? end + def self.generate_invite + Base64.encode64(SecureRandom.random_bytes).downcase.gsub(/[0oil1+_\/]/,'')[0..7].scan(/..../).join('-') + end end |