Skip to content

Commit

Permalink
Reset 2fa for admin.
Browse files Browse the repository at this point in the history
  • Loading branch information
ipcross committed Jan 10, 2017
1 parent d7080f9 commit fae4bff
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/controllers/second_authentications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class SecondAuthenticationsController < ApplicationController
unloadable

def destroy
User.current.reset_second_auth
User.find(params[:id]).reset_second_auth
flash[:notice] = l(:notice_2fa_reset)
redirect_to my_account_path
redirect_to(:back)
end
end
7 changes: 7 additions & 0 deletions app/views/second_authentications/_link_to_reset.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script type="text/javascript">
$(document).ready(function($) {
if($(".controller-users.action-edit").length > 0) {
$($("#content .contextual")[0]).append('<%= j render 'second_authentications/reset', user: @user %>');
}
});
</script>
2 changes: 1 addition & 1 deletion app/views/second_authentications/_reset.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<% if user.two_factor_authenticable? or user.ignore_2fa? %>
<%= link_to l(:link_2fa_reset), second_authentication_reset_path, method: :delete, class: 'icon icon-not-ok' %>
<%= link_to l(:link_2fa_reset), second_authentication_reset_path(user), method: :delete, class: 'icon icon-not-ok' %>
<% end %>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# 2FA management

delete 'reset', to: 'second_authentications#destroy', as: 'second_authentication_reset'
delete 'reset/:id', to: 'second_authentications#destroy', as: 'second_authentication_reset'

# 2FA step

Expand Down
3 changes: 2 additions & 1 deletion lib/redmine_2fa/hooks/view_my_account_contextual_hook.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module Redmine2FA
module Hooks
class ViewMyAccountContextualHook < Redmine::Hook::ViewListener
render_on :view_my_account_contextual, partial: 'second_authentications/reset'
render_on :view_my_account_contextual, partial: 'second_authentications/reset', user: @user
render_on :view_users_form, partial: 'second_authentications/link_to_reset'
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class RedmineTelegramConnectionsControllerTest < ActionController::TestCase
setup do
post :create,
user_id: 2, user_email: @user.mail,
telegram_id: 123, token: @telegram_account.token
telegram_id: 123, token: @telegram_account.token,
plugin: 'plugin_redmine_2fa'
end

should 'set telegram account to user' do
Expand Down
3 changes: 2 additions & 1 deletion test/integration/routing/second_authentications_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require File.expand_path('../../../test_helper', __FILE__)
class SecondAuthenticationsTest < Redmine::RoutingTest
def test_second_authentications
should_route 'DELETE redmine_2fa/reset' => 'second_authentications#destroy'
assert_routing({ method: 'delete', path: '/redmine_2fa/reset/id' },
controller: 'second_authentications', action: 'destroy', id: 'id')
end
end

0 comments on commit fae4bff

Please sign in to comment.