mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FIX: send new email activation token if the original token expired
This commit is contained in:
parent
94f05a40de
commit
10b8e43a92
2 changed files with 35 additions and 1 deletions
|
@ -43,10 +43,13 @@ end
|
|||
|
||||
class EmailActivator < UserActivator
|
||||
def activate
|
||||
email_token = user.email_tokens.unconfirmed.active.first
|
||||
email_token = user.email_tokens.create(email: user.email) if email_token.nil?
|
||||
|
||||
Jobs.enqueue(:user_email,
|
||||
type: :signup,
|
||||
user_id: user.id,
|
||||
email_token: user.email_tokens.first.token
|
||||
email_token: email_token.token
|
||||
)
|
||||
I18n.t("login.activate_email", email: user.email)
|
||||
end
|
||||
|
|
31
spec/services/user_activator_spec.rb
Normal file
31
spec/services/user_activator_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe UserActivator do
|
||||
|
||||
describe 'email_activator' do
|
||||
|
||||
it 'does not create new email token unless required' do
|
||||
SiteSetting.email_token_valid_hours = 24
|
||||
user = Fabricate(:user)
|
||||
activator = EmailActivator.new(user, nil, nil, nil)
|
||||
|
||||
Jobs.expects(:enqueue).with(:user_email, has_entries(type: :signup, email_token: user.email_tokens.first.token))
|
||||
activator.activate
|
||||
end
|
||||
|
||||
it 'creates and send new email token if the existing token expired' do
|
||||
SiteSetting.email_token_valid_hours = 24
|
||||
user = Fabricate(:user)
|
||||
email_token = user.email_tokens.first
|
||||
email_token.update_column(:created_at, 48.hours.ago)
|
||||
activator = EmailActivator.new(user, nil, nil, nil)
|
||||
|
||||
Jobs.expects(:enqueue).with(:user_email, has_entries(type: :signup))
|
||||
Jobs.expects(:enqueue).with(:user_email, has_entries(type: :signup, email_token: email_token.token)).never
|
||||
activator.activate
|
||||
|
||||
user.reload
|
||||
expect(user.email_tokens.last.created_at).to be_within_one_second_of(Time.zone.now)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue