Commit 5e008aa
Changed files (7)
app
controllers
views
config
spec
requests
my
app/controllers/my/mfas_controller.rb
@@ -2,6 +2,10 @@
module My
class MfasController < ApplicationController
+ def show
+ redirect_to current_user.tfa.setup? ? edit_my_mfa_path : new_my_mfa_path
+ end
+
def new
return redirect_to edit_my_mfa_path if current_user.tfa.setup?
current_user.tfa.build_secret
app/controllers/application_controller.rb
@@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base
include SamlRespondable
protect_from_forgery with: :exception
before_action :authenticate!
- helper_method :current_user
+ helper_method :current_user, :current_user?
add_flash_types :error, :warning
def render_error(status, model: nil)
app/views/layouts/application.html.erb
@@ -10,6 +10,7 @@
<%= stylesheet_pack_tag 'vendor' %>
</head>
<body>
+ <%= render partial: 'navbar' if current_user? %>
<%= render partial: 'flash' %>
<%= yield %>
</body>
app/views/my/dashboards/show.html.erb
@@ -2,12 +2,6 @@
<div class="row">
<div class="col">
<h1>Dashboard</h1>
- <% if current_user.tfa.setup? %>
- <%= link_to "TFA", edit_my_mfa_path %>
- <% else %>
- <%= link_to "Setup TFA", new_my_mfa_path %>
- <% end %>
- <%= button_to "Logout", session_path, method: :delete %>
<table class="table">
<thead>
<th>Entity ID</th>
config/routes.rb
@@ -7,7 +7,7 @@ Rails.application.routes.draw do
resources :registrations, only: [:new, :create]
namespace :my do
resource :dashboard, only: [:show]
- resource :mfa, only: [:new, :edit, :create, :destroy]
+ resource :mfa, only: [:show, :new, :edit, :create, :destroy]
end
namespace :scim do
namespace :v2, defaults: { format: :scim } do
spec/requests/my/mfas_spec.rb
@@ -6,6 +6,19 @@ RSpec.describe '/my/mfa' do
before { http_login(current_user) }
describe "GET /my/mfa" do
+ context "when MFA is set up" do
+ let(:current_user) { create(:user, :mfa_configured) }
+ before { get '/my/mfa' }
+ specify { expect(response).to redirect_to(edit_my_mfa_path) }
+ end
+
+ context "when MFA is not set up" do
+ before { get '/my/mfa' }
+ specify { expect(response).to redirect_to(new_my_mfa_path) }
+ end
+ end
+
+ describe "GET /my/mfa/new" do
context "when mfa has not been set up yet" do
before { get '/my/mfa/new' }