From 393291de60c4f29bb03bad596bb60c1e0648e6e7 Mon Sep 17 00:00:00 2001 From: ankonym Date: Thu, 13 Aug 2015 15:28:02 +0200 Subject: Add invite code model --- app/models/invite_code.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 app/models/invite_code.rb (limited to 'app/models/invite_code.rb') diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb new file mode 100644 index 0000000..b9f6f33 --- /dev/null +++ b/app/models/invite_code.rb @@ -0,0 +1,10 @@ +class InviteCode < CouchRest::Model::Base + use_database 'invite_codes' + property :invite_code, String + timestamps! + + design do + view :by__id + end +end + -- cgit v1.2.3 From 8b9b2a0c3c8457024d99d0794416c59cb245a513 Mon Sep 17 00:00:00 2001 From: ankonym Date: Thu, 13 Aug 2015 17:24:02 +0200 Subject: Changed invite code query to look for invite_code string instead of id --- app/models/invite_code.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/invite_code.rb') diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb index b9f6f33..751b28e 100644 --- a/app/models/invite_code.rb +++ b/app/models/invite_code.rb @@ -4,7 +4,7 @@ class InviteCode < CouchRest::Model::Base timestamps! design do - view :by__id + view :by_invite_code end end -- cgit v1.2.3 From 0543217b433a8f4809f08018c1a11c20119fa85d Mon Sep 17 00:00:00 2001 From: ankonym Date: Fri, 21 Aug 2015 17:49:36 +0200 Subject: assign random invite code when creating new invite codes --- app/models/invite_code.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'app/models/invite_code.rb') diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb index 751b28e..d52436f 100644 --- a/app/models/invite_code.rb +++ b/app/models/invite_code.rb @@ -1,10 +1,19 @@ +require 'coupon_code' + class InviteCode < CouchRest::Model::Base use_database 'invite_codes' - property :invite_code, String + property :invite_code, String, :read_only => true timestamps! design do view :by_invite_code end + + def initialize(attributes = {}, options = {}) + super(attributes, options) + write_attribute('invite_code', CouponCode.generate) if new? + end + end + -- cgit v1.2.3 From 45c3fadd930a474951bd918a50e1ea2b00af75c7 Mon Sep 17 00:00:00 2001 From: ankonym Date: Tue, 25 Aug 2015 14:11:00 +0200 Subject: Make sure codes can only be used once, fix validations We introduced a count on invite codes to make sure that (at the moment) codes can only be used once. (The code will also allow multi-use codes in the future.) Also, some of our validations weren't validating against the correct data, which is now fixed. --- app/models/invite_code.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app/models/invite_code.rb') diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb index d52436f..30a6498 100644 --- a/app/models/invite_code.rb +++ b/app/models/invite_code.rb @@ -3,10 +3,13 @@ require 'coupon_code' class InviteCode < CouchRest::Model::Base use_database 'invite_codes' property :invite_code, String, :read_only => true + property :invite_count, Integer, :default => 0, :accessible => true + timestamps! design do view :by_invite_code + view :by_invite_count end def initialize(attributes = {}, options = {}) -- cgit v1.2.3