Skip to content

Commit 326979a

Browse files
tonoyansergey-devttonoyansergey-devt
andauthored
[TBT-453] Fix confirmation email expiry format (#352)
* TBT-453 Show remaining time in hours instead Date Time in UTC * TBT-453 Fix Time usage syntax * TBT-453 Fix Time usage syntax * TBT-453 Test 1st solution * TBT-453 Test 1st solution * TBT-453 Apply 2nd solution * TBT-453 Modify spec * TBT-453 Modify spec * TBT-453 Modify spec * TBT-453 Removed unused import --------- Co-authored-by: tonoyansergey-devt <ssergey.tonoyan@devtactics.net>
1 parent 3e57b67 commit 326979a

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

lib/travis/addons/user_confirmation/mailer/user_confirmation_mailer.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ def account_activated(*params)
2323
def confirm_account(*params)
2424
receivers = params[0]
2525
options = params[1]
26-
@owner, @confirmation_url, @token_valid_to = options.values_at(:owner, :confirmation_url, :token_valid_to)
26+
@owner, @confirmation_url = options.values_at(:owner, :confirmation_url)
27+
28+
minutes_valid_for = ENV['CONFIRMATION_TOKEN_VALID_FOR'].to_i
29+
minutes_valid_for = 0 if minutes_valid_for.negative?
30+
@token_valid_to = minutes_valid_for == 1 ? '1 minute' : "#{minutes_valid_for} minutes"
2731
subject = 'Travis CI: Confirm your account.'
2832
mail(from: from, to: to(receivers), subject: subject,
2933
template_path: 'user_confirmation_mailer')

lib/travis/addons/user_confirmation/mailer/views/user_confirmation_mailer/confirm_account.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
</p>
77
<p><a id="account-activated-button" href="<%=@confirmation_url%>" target="_blank">Confirm your account</a></p>
88
<br/>
9-
<p>Note: you must confirm your account in order to run builds on Travis CI. The confirmation link will expire after <br><%= @token_valid_to %></p>
9+
<p>Note: you must confirm your account in order to run builds on Travis CI. The confirmation link will expire after <%= @token_valid_to %></p>
1010
</td>
1111
</tr>

spec/addons/user_confirmation/mailer/user_confirmation_mailer_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
end
2020

2121
describe '#confirm_account' do
22+
before { ENV['CONFIRMATION_TOKEN_VALID_FOR'] = '60' }
2223
let(:params) do
2324
{
2425
owner: { name: 'My Name' },
2526
confirmation_url: 'https://confirm.me.plx',
26-
token_valid_to: '2021-02-08 14:14:14'
27+
token_valid_to: (Time.now.utc + 60 * 60).strftime('%Y-%m-%d %H:%M:%S')
2728
}
2829
end
2930
subject(:mail) { described_class.confirm_account(recipients, **params) }
30-
3131
it 'contains the right data' do
3232
expect(mail.to(recipients)).to eq(recipients)
3333
expect(mail.from).to eq(['no-reply@travis-ci.com'])
@@ -37,7 +37,7 @@
3737
expect(mail.body)
3838
.to match('<p><a id="account-activated-button" href="https://confirm.me.plx" target="_blank">Confirm your account</a></p>')
3939
expect(mail.body)
40-
.to match('<p>Note: you must confirm your account in order to run builds on Travis CI. The confirmation link will expire after <br>2021-02-08 14:14:14</p>')
40+
.to match('<p>Note: you must confirm your account in order to run builds on Travis CI. The confirmation link will expire after 60 minutes</p>')
4141
end
4242
end
4343
end

0 commit comments

Comments
 (0)