Permalink
Browse files

Allow creation of default user through web interface.

[#553 state:resolved]
  • Loading branch information...
1 parent 1fb61ad commit 53e755001e0122eb0620b630b60ab28a7be6fb2e @schof schof committed Jul 3, 2009
@@ -16,75 +16,79 @@ class ApplicationController < ActionController::Base
include EasyRoleRequirementSystem
include SslRequirement
- private
- def current_user_session
- return @current_user_session if defined?(@current_user_session)
- @current_user_session = UserSession.find
- end
+ def admin_created?
+ User.first(:include => :roles, :conditions => ["roles.name = 'admin'"])
+ end
+
+ private
+ def current_user_session
+ return @current_user_session if defined?(@current_user_session)
+ @current_user_session = UserSession.find
+ end
- def current_user
- return @current_user if defined?(@current_user)
- @current_user = current_user_session && current_user_session.user
- end
+ def current_user
+ return @current_user if defined?(@current_user)
+ @current_user = current_user_session && current_user_session.user
+ end
- def require_user
- unless current_user
- store_location
- flash[:notice] = "You must be logged in to access this page"
- redirect_to new_user_session_url
- return false
- end
+ def require_user
+ unless current_user
+ store_location
+ flash[:notice] = "You must be logged in to access this page"
+ redirect_to new_user_session_url
+ return false
end
+ end
- def require_no_user
- if current_user
- store_location
- flash[:notice] = "You must be logged out to access this page"
- redirect_to account_url
- return false
- end
+ def require_no_user
+ if current_user
+ store_location
+ flash[:notice] = "You must be logged out to access this page"
+ redirect_to account_url
+ return false
end
+ end
- def store_location
- session[:return_to] = request.request_uri
- end
+ def store_location
+ session[:return_to] = request.request_uri
+ end
- def redirect_back_or_default(default)
- redirect_to(session[:return_to] || default)
- session[:return_to] = nil
- end
+ def redirect_back_or_default(default)
+ redirect_to(session[:return_to] || default)
+ session[:return_to] = nil
+ end
- # Redirect as appropriate when an access request fails.
- #
- # The default action is to redirect to the login screen.
- #
- # Override this method in your controllers if you want to have special
- # behavior in case the user is not authorized
- # to access the requested action. For example, a popup window might
- # simply close itself.
- def access_denied
- respond_to do |format|
- format.html do
- if current_user
- flash[:error] = t("authorization_failure")
- redirect_to '/user_sessions/authorization_failure'
- next
- else
- store_location
- redirect_to login_path
- next
- end
- end
- format.xml do
- request_http_basic_authentication 'Web Password'
+ # Redirect as appropriate when an access request fails.
+ #
+ # The default action is to redirect to the login screen.
+ #
+ # Override this method in your controllers if you want to have special
+ # behavior in case the user is not authorized
+ # to access the requested action. For example, a popup window might
+ # simply close itself.
+ def access_denied
+ respond_to do |format|
+ format.html do
+ if current_user
+ flash[:error] = t("authorization_failure")
+ redirect_to '/user_sessions/authorization_failure'
+ next
+ else
+ store_location
+ redirect_to login_path
+ next
end
end
+ format.xml do
+ request_http_basic_authentication 'Web Password'
+ end
end
+ end
+
+ def instantiate_controller_and_action_names
+ @current_action = action_name
+ @current_controller = controller_name
- def instantiate_controller_and_action_names
- @current_action = action_name
- @current_controller = controller_name
-
- @taxonomies = Taxonomy.find(:all, :include => {:root => :children})
- end
+ @taxonomies = Taxonomy.find(:all, :include => {:root => :children})
+ end
end
@@ -1,6 +1,8 @@
class ProductsController < Spree::BaseController
+ before_filter :setup_admin_user
+
resource_controller
- helper :taxons
+ helper :taxons
before_filter :load_data, :only => :show
actions :show, :index
@@ -17,8 +19,13 @@ def change_image
end
private
- def load_data
-
+ def setup_admin_user
+ return if admin_created?
+ flash[:notice] = I18n.t(:please_create_user)
+ redirect_to signup_url
+ end
+
+ def load_data
return unless permalink = params[:taxon_path]
@taxon = Taxon.find_by_permalink(params[:taxon_path].join("/") + "/")
end
@@ -14,6 +14,11 @@ class UsersController < Spree::BaseController
wants.js { render :js => true.to_json }
failure.wants.html { render :new }
failure.wants.js { render :js => @user.errors.to_json }
+ end
+
+ create.after do
+ next if admin_created?
+ @user.roles << Role.find_by_name("admin")
end
show.before do
View
@@ -398,6 +398,7 @@ da:
payments: Payments
phone: Phone
place_order: Place Order
+ please_create_user: "Please create a user account"
powered_by: "Powered by"
presentation: Presentation
previous: Previous
View
@@ -398,6 +398,7 @@ de-CH:
payments: Zahlungen
phone: Telefon
place_order: "Bestellung aufgeben"
+ please_create_user: "Please create a user account"
powered_by: "Powered by"
presentation: Anzeige
previous: zurück
View
@@ -398,6 +398,7 @@ de:
payments: Zahlungen
phone: Telefon
place_order: Place Order
+ please_create_user: "Please create a user account"
powered_by: "Powered by"
presentation: Anzeige
previous: zurück
View
@@ -398,6 +398,7 @@ en-GB:
payments: Payments
phone: Phone
place_order: Place Order
+ please_create_user: "Please create a user account"
powered_by: "Powered by"
presentation: Presentation
previous: Previous
View
@@ -398,6 +398,7 @@ en-US:
payments: Payments
phone: Phone
place_order: Place Order
+ please_create_user: "Please create a user account"
powered_by: "Powered by"
presentation: Presentation
previous: Previous
View
@@ -398,6 +398,7 @@ es:
payments: Pagos
phone: Teléfono
place_order: Hacer pedido
+ please_create_user: "Please create a user account"
powered_by: "Powered by"
presentation: Presentación
previous: Anterior
View
@@ -398,6 +398,7 @@ fr-FR:
payments: Paiements
phone: Téléphone
place_order: Place Order
+ please_create_user: "Please create a user account"
powered_by: "Powered by"
presentation: Presentation
previous: Précédent
Oops, something went wrong.

0 comments on commit 53e7550

Please sign in to comment.