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/account.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'app/models/account.rb') diff --git a/app/models/account.rb b/app/models/account.rb index af470ed..a57e3f7 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -1,7 +1,7 @@ # -# The Account model takes care of the livecycle of a user. +# The Account model takes care of the lifecycle of a user. # It composes a User record and it's identity records. -# It also allows for other engines to hook into the livecycle by +# It also allows for other engines to hook into the lifecycle by # monkeypatching the create, update and destroy methods. # There's an ActiveSupport load_hook at the end of this file to # make this more easy. @@ -19,6 +19,7 @@ class Account identity = nil user = nil user = User.new(attrs) + user.save if !user.tmp? && user.persisted? identity = user.identity -- cgit v1.2.3 From 2ce3d14cfa77f985b6849dd4431db65e9abd0226 Mon Sep 17 00:00:00 2001 From: Aya Jaff Date: Fri, 4 Sep 2015 14:01:49 +0200 Subject: Fixed the signup bug that wrongly consumes the invite code. --- app/models/account.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/models/account.rb') diff --git a/app/models/account.rb b/app/models/account.rb index a57e3f7..c398d93 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -19,8 +19,8 @@ class Account identity = nil user = nil user = User.new(attrs) - user.save + if !user.tmp? && user.persisted? identity = user.identity identity.user_id = user.id @@ -28,6 +28,9 @@ class Account identity.errors.each do |attr, msg| user.errors.add(attr, msg) end + user_invite_code = InviteCode.find_by_invite_code user.invite_code + user_invite_code.invite_count += 1 + user_invite_code.save end rescue StandardError => ex user.errors.add(:base, ex.to_s) if user -- cgit v1.2.3 From 9adbde13619de8b2c300056b062d12f0961cb710 Mon Sep 17 00:00:00 2001 From: ankonym Date: Mon, 21 Sep 2015 18:34:04 +0200 Subject: Make invite code configurable Through the config param 'invite_required', providers can decide whether users need to provide an invite code upon signup. The default setting is false. --- app/models/account.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'app/models/account.rb') diff --git a/app/models/account.rb b/app/models/account.rb index c398d93..a5cd833 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -28,9 +28,12 @@ class Account identity.errors.each do |attr, msg| user.errors.add(attr, msg) end - user_invite_code = InviteCode.find_by_invite_code user.invite_code - user_invite_code.invite_count += 1 - user_invite_code.save + + if APP_CONFIG[:invite_required] + user_invite_code = InviteCode.find_by_invite_code user.invite_code + user_invite_code.invite_count += 1 + user_invite_code.save + end end rescue StandardError => ex user.errors.add(:base, ex.to_s) if user -- cgit v1.2.3