diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb new file mode 100644 index 0000000..0fb2d97 --- /dev/null +++ b/app/controllers/registrations_controller.rb @@ -0,0 +1,17 @@ +class RegistrationsController < Devise::RegistrationsController + + before_action :one_user_registered?, only: [:new, :create] + + protected + + def one_user_registered? + if User.count == 1 + if user_signed_in? + redirect_to root_path + else + redirect_to new_user_session_path + end + end + end + +end diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb index 6109177..fcae998 100644 --- a/app/views/devise/shared/_links.html.erb +++ b/app/views/devise/shared/_links.html.erb @@ -23,3 +23,5 @@ <%= button_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), data: { turbo: false } %>
<% end %> <% end %> + + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 71c065d..3a6ee32 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -31,7 +31,6 @@

To-Do (In order of importance):

diff --git a/config/routes.rb b/config/routes.rb index 2199c55..14b8f30 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,10 +2,11 @@ Rails.application.routes.draw do resources :domains do resources :credentials, only: [ :new, :create, :edit, :update, :destroy] - resources :virtuals + resources :virtuals, only: [ :new, :create, :edit, :update, :destroy] end - devise_for :users + devise_for :users, controllers: { registrations: "registrations" } + # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # Defines the root path route ("/") diff --git a/test/controllers/virtuals_controller_test.rb b/test/controllers/virtuals_controller_test.rb index 446a770..1ec1ecf 100644 --- a/test/controllers/virtuals_controller_test.rb +++ b/test/controllers/virtuals_controller_test.rb @@ -3,6 +3,7 @@ require "test_helper" class VirtualsControllerTest < ActionDispatch::IntegrationTest setup do @virtual = virtuals(:one) + @domain = doamins(:one) end test "should get index" do