diff options
author | Azul <azul@riseup.net> | 2017-10-24 12:12:26 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2017-10-24 12:12:26 +0200 |
commit | 3a1a6fde9a1fc2ea2a8f081a9d2578ec718bdd32 (patch) | |
tree | 319fce57d780e4cdfb519a5f607466724814c1dc /app | |
parent | 522d632c2c1337c7af96befc4e6a9faab160e976 (diff) |
fix: also remove invite codes used for tmp users
fixes #8807
Diffstat (limited to 'app')
-rw-r--r-- | app/models/account.rb | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 4442a68..4db69e8 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -34,31 +34,25 @@ class Account user.save # this is not very atomic, but we do the best we can: - if !user.is_tmp? && user.persisted? + return user unless user.persisted? + if !user.is_tmp? identity = user.identity identity.user_id = user.id identity.save identity.errors.each do |attr, msg| user.errors.add(attr, msg) end - if user.invite_required? - user_invite_code = InviteCode.find_by_invite_code user.invite_code - if user.is_test? && user_invite_code.max_uses == 1 - user_invite_code.destroy - else - user_invite_code.invite_count += 1 - user_invite_code.save - end - end end + consume_invite_code_for_user(user) if user.invite_required? + return user rescue VALIDATION_FAILED => ex user.errors.add(:base, ex.to_s) if user + return user ensure if creation_problem?(user, identity) user.destroy if user && user.persisted? identity.destroy if identity && identity.persisted? end - return user end def update(attrs) @@ -113,6 +107,16 @@ class Account protected + def self.consume_invite_code_for_user(user) + invite_code = InviteCode.find_by_invite_code user.invite_code + if user.is_test? && invite_code.max_uses == 1 + invite_code.destroy + else + invite_code.invite_count += 1 + invite_code.save + end + end + def update_login(login) return unless login.present? @old_identity = Identity.for(@user) |