summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/invite_code.rb5
-rw-r--r--lib/tasks/invite_code.rake21
2 files changed, 16 insertions, 10 deletions
diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb
index 30a6498..8f69582 100644
--- a/app/models/invite_code.rb
+++ b/app/models/invite_code.rb
@@ -1,4 +1,3 @@
-require 'coupon_code'
class InviteCode < CouchRest::Model::Base
use_database 'invite_codes'
@@ -14,9 +13,11 @@ class InviteCode < CouchRest::Model::Base
def initialize(attributes = {}, options = {})
super(attributes, options)
- write_attribute('invite_code', CouponCode.generate) if new?
end
+ def set_invite_code(code)
+ write_attribute(:invite_code, code)
+ end
end
diff --git a/lib/tasks/invite_code.rake b/lib/tasks/invite_code.rake
index f3bafac..b379d3a 100644
--- a/lib/tasks/invite_code.rake
+++ b/lib/tasks/invite_code.rake
@@ -1,16 +1,21 @@
-
+require 'base64'
+require 'securerandom'
desc "Generate a batch of invite codes"
-task :generate_invites, [:n] => :environment do |task, args|
+task :generate_invites, [:n, :u] => :environment do |task, args|
+
+ codes = args.n
+ codes = codes.to_i
- codes = args.n
- codes = codes.to_i
+ if args.u != nil
+ max_uses = args.u
+ end
- codes.times do |x|
+ codes.times do |x|
x = InviteCode.new
+ x.max_uses = max_uses
x.save
- puts "#{x.invite_code} Code generated."
-
+ puts x.invite_code
end
-end
+end