A platform for community discussion. Free, open, simple.
FIX: activate user even if email token is already confirmed
Arpit Jalanf07b1a5c054a
diff --git a/app/models/user.rb b/app/models/user.rbindex 464d3fe9d78..db69ef9f963 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -743,7 +743,8 @@ class User < ActiveRecord::Basedef activateif email_token = self.email_tokens.active.where(email: self.email).first- EmailToken.confirm(email_token.token)+ user = EmailToken.confirm(email_token.token)+ self.update!(active: true) if user.nil?elseself.update!(active: true)enddiff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rbindex 8e95731065f..26b3ea2fd22 100644--- a/spec/models/user_spec.rb+++ b/spec/models/user_spec.rb@@ -1619,4 +1619,21 @@ describe User doendend+ describe ".activate" do+ let!(:inactive) { Fabricate(:user, active: false) }++ it 'confirms email token and activates user' do+ inactive.activate+ inactive.reload+ expect(inactive.email_confirmed?).to eq(true)+ expect(inactive.active).to eq(true)+ end++ it 'activates user even if email token is already confirmed' do+ token = inactive.email_tokens.find_by(email: inactive.email)+ token.update_column(:confirmed, true)+ inactive.activate+ expect(inactive.active).to eq(true)+ end+ endend