Skip to content

Commit

Permalink
Merge pull request #57 from centosadmin/develop
Browse files Browse the repository at this point in the history
Release 1.5.0
  • Loading branch information
vladislav-yashin authored Mar 19, 2018
2 parents a711ed2 + ccbdba7 commit 1827d04
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.5.0

* Use Telegram login
* Fix "Code sent" message
* Fix RQRCode::QRCodeRunTimeError

# 1.4.0

* Update telegram-bot-ruby
Expand Down
7 changes: 5 additions & 2 deletions app/views/account/init_2fa.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
<div id="init2FAFormAuthSources">
<% Redmine2FA.active_protocols.each do |protocol| %>
<div class="authSource">
<%= radio_button_tag 'protocol', protocol, false, data: { protocol: protocol } %>
<%= radio_button_tag 'protocol', protocol, (protocol == 'telegram' ? true : false), data: { protocol: protocol } %>
<%= label_tag "protocol_#{protocol}", t("redmine_2fa.protocols.#{protocol}") %>
</div>
<% end %>
</div>
<% end %>
<table>
<% Redmine2FA.active_protocols.each do |protocol| %>
<% if Redmine2FA.active_protocols.include?('telegram') %>
<%= render "account/init_2fa/telegram" %>
<% end %>
<% (Redmine2FA.active_protocols - ['telegram']).each do |protocol| %>
<%= render "account/init_2fa/#{protocol}", style: 'display: none' %>
<% end %>
</table>
Expand Down
8 changes: 3 additions & 5 deletions app/views/account/init_2fa/_telegram.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<tr class="instruction2FA telegramInstruction" style="<%= style %>">
<td colspan="3">
<%= t 'redmine_2fa.second_authentications.telegram.instruction_html', bot_name: Setting.plugin_redmine_telegram_common['bot_name'] %>
</td>
</tr>
<div align="center" class="instruction2FA telegramInstruction">
<%= render partial: 'telegram_login/widget' %>
</div>
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ en:
auth_code: 'Authorization code'
resend:
link: 'Resend code'
instruction_html: 'Code sent by <a href="https://telegram.me/%{bot_name}" target="_blank">%{bot_name}</a> (need to be in your contacts list).<br><br>Code resending is possible after 5 seconds <span id="otpCodeResendTimer">%{timeout}</span> секунд.'
instruction_html: 'Code sent. Code resending is possible after <span id="otpCodeResendTimer">%{timeout}</span> seconds.'
notice:
auth_code:
invalid: 'Wrong authorization code'
Expand Down
2 changes: 1 addition & 1 deletion config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ru:
auth_code: 'Код подтверждения'
resend:
link: 'Отправить повторно'
instruction_html: 'Код отправлен ботом <a href="https://telegram.me/%{bot_name}" target="_blank">%{bot_name}</a> (необходимо добавить в контакты).<br><br>Повторная отправка кода возможна через <span id="otpCodeResendTimer">%{timeout}</span> секунд.'
instruction_html: 'Код отправлен. Повторная отправка кода возможна через <span id="otpCodeResendTimer">%{timeout}</span> секунд.'
notice:
auth_code:
invalid: 'Неверный код подтверждения'
Expand Down
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

Redmine::Plugin.register :redmine_2fa do
name 'Redmine 2FA'
version '1.4.0'
version '1.5.0'
url 'https://github.com/centosadmin/redmine_2fa'
description 'Two-factor authorization for Redmine'
author 'Southbridge'
Expand Down
2 changes: 0 additions & 2 deletions lib/redmine_2fa/code_sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ def send_code

def define_sender
case user&.two_fa&.auth_method_name
when 'Telegram'
CodeSender::TelegramSender.new(user)
when 'SMS'
CodeSender::SMSSender.new(user)
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ def password_authentication
if Redmine2FA.switched_off? || @user.ignore_2fa? || @user.two_factor_authenticable?
super
else
@qr = RQRCode::QRCode.new(@user.provisioning_uri("#{@user.login}", issuer: "#{Setting.host_name}"), size: 10, level: :h)
render 'account/init_2fa'
begin
qr_size ||= 10
@qr = RQRCode::QRCode.new(@user.provisioning_uri("#{@user.login}", issuer: "#{Setting.host_name}"), size: qr_size, level: :h)
render 'account/init_2fa'
rescue RQRCode::QRCodeRunTimeError => e
retry unless (qr_size += 1) > 20
raise e
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def password_authentication
if Redmine2FA.switched_on? && !@user.ignore_2fa? && @user.two_factor_authenticable?
send_code
flash[:error] = sender.errors.join(', ') if sender.errors.present?
render 'account/otp'
render(@user.two_fa&.name == 'Telegram' ? 'telegram_login/index' : 'account/otp')
else
super
end
Expand Down
2 changes: 1 addition & 1 deletion test/unit/redmine_2fa/code_sender_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Redmine2FA::CodeSenderTest < ActiveSupport::TestCase
should 'be TelegramSender' do
@user.two_fa = auth_sources(:telegram)
@sender = Redmine2FA::CodeSender.new(@user)
assert @sender.sender.is_a?(Redmine2FA::CodeSender::TelegramSender)
assert @sender.sender.is_a?(Redmine2FA::CodeSender::NullSender)
end

should 'be SMSSender' do
Expand Down

0 comments on commit 1827d04

Please sign in to comment.