mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FIX: activate user even if email token is already confirmed
This commit is contained in:
parent
8ae2c4555a
commit
f07b1a5c05
2 changed files with 19 additions and 1 deletions
|
@ -743,7 +743,8 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
def activate
|
def activate
|
||||||
if email_token = self.email_tokens.active.where(email: self.email).first
|
if 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?
|
||||||
else
|
else
|
||||||
self.update!(active: true)
|
self.update!(active: true)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1619,4 +1619,21 @@ describe User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue