Skip to content

Commit

Permalink
Creating redirect for initial user creation per #65
Browse files Browse the repository at this point in the history
  • Loading branch information
augustf committed May 2, 2012
1 parent 8fa88ff commit 25bc48c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_locale
before_filter :check_for_initial_install

def set_locale
if user_signed_in? && current_user.locale != ""
Expand All @@ -9,4 +10,12 @@ def set_locale

I18n.locale = session[:locale] || I18n.default_locale
end

#If there are no users defined yet, redirect to create the first admin user
def check_for_initial_install
if User.all.empty?

This comment has been minimized.

Copy link
@bamnet

bamnet May 3, 2012

Member

I'm concerned over the latency implications of a User.all.empty? check being executed on every page. The longer term fix is probably to move this into a setting (setup_complete) which we know we'll cache heavily in the future.

A short-term measure could first check if a user is logged in, since a logged in user means we already have users in the system.

This comment has been minimized.

Copy link
@augustf

augustf May 3, 2012

Author Member

Yeah-that was careless of me; I'll look to take a much more conservative approach.

redirect_to new_user_registration_path
end
end

end
8 changes: 8 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,13 @@ class Application < Rails::Application

# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'

#exempt these methods from the initial install check to prevent redirect loops
config.to_prepare do
Devise::RegistrationsController.skip_before_filter :check_for_initial_install
Concerto::UsersController.skip_before_filter :check_for_initial_install
end


end
end

0 comments on commit 25bc48c

Please sign in to comment.