Fixed multi coop routing and changed config accessors.

This commit is contained in:
benni 2012-08-24 19:52:38 +02:00
parent 2860a3ca44
commit ec2e761e7f
28 changed files with 124 additions and 88 deletions

View file

@ -5,8 +5,6 @@ class ApplicationController < ActionController::Base
before_filter :select_foodcoop, :authenticate, :store_controller, :items_per_page, :set_redirect_to
after_filter :remove_controller
helper_method :current_user
# Returns the controller handling the current request.
def self.current
Thread.current[:application_controller]
@ -18,10 +16,11 @@ class ApplicationController < ActionController::Base
# check if there is a valid session and return the logged-in user (its object)
if session[:user_id] and params[:foodcoop]
# for shared-host installations. check if the cookie-subdomain fits to request.
@current_user ||= User.find_by_id(session[:user_id]) if params[:foodcoop] == Foodsoft.env
@current_user ||= User.find_by_id(session[:user_id]) if session[:scope] == FoodsoftConfig.scope
end
end
helper_method :current_user
def deny_access
self.return_to = request.request_uri
redirect_to login_url, :alert => 'Access denied!'
@ -104,28 +103,22 @@ class ApplicationController < ActionController::Base
# It uses the subdomain to select the appropriate section in the config files
# Use this method as a before filter (first filter!) in ApplicationController
def select_foodcoop
if Foodsoft.config[:multi_coop_install]
if !params[:foodcoop].blank?
if FoodsoftConfig[:multi_coop_install]
if params[:foodcoop].present?
begin
# Set Config
Foodsoft.env = params[:foodcoop]
# Set database-connection
ActiveRecord::Base.establish_connection(Foodsoft.database)
# Set Config and database connection
FoodsoftConfig.select_foodcoop params[:foodcoop]
rescue => error
flash[:error] = error.to_s
redirect_to root_path
redirect_to root_url, alert: error.message
end
else
redirect_to root_path
redirect_to root_url
end
else
# Deactivate routing filter
RoutingFilter::Foodcoop.active = false
end
end
def items_per_page
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
if params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100
@per_page = params[:per_page].to_i
else
@per_page = 20
@ -143,4 +136,9 @@ class ApplicationController < ActionController::Base
end
default
end
# Always stay in foodcoop url scope
def default_url_options(options = {})
{foodcoop: FoodsoftConfig.scope}
end
end

View file

@ -127,13 +127,13 @@ class OrdersController < ApplicationController
def text_fax_template
order = Order.find(params[:id])
supplier = order.supplier
contact = Foodsoft.config[:contact].symbolize_keys
text = "Bestellung für" + " #{Foodsoft.config[:name]}"
contact = FoodsoftConfig[:contact].symbolize_keys
text = "Bestellung für" + " #{FoodsoftConfig[:name]}"
text += "\n" + "Kundennummer" + ": #{supplier.customer_number}" unless supplier.customer_number.blank?
text += "\n" + "Liefertag" + ": "
text += "\n\n#{supplier.name}\n#{supplier.address}\nFAX: #{supplier.fax}\n\n"
text += "****** " + "Versandadresse" + "\n\n"
text += "#{Foodsoft.config[:name]}\n#{contact[:street]}\n#{contact[:zip_code]} #{contact[:city]}\n\n"
text += "#{FoodsoftConfig[:name]}\n#{contact[:street]}\n#{contact[:zip_code]} #{contact[:city]}\n\n"
text += "****** " + "Artikel" + "\n\n"
text += "Nummer" + " " + "Menge" + " " + "Name" + "\n"
# now display all ordered articles

View file

@ -10,6 +10,7 @@ class SessionsController < ApplicationController
user = User.authenticate(params[:nick], params[:password])
if user
session[:user_id] = user.id
session[:scope] = FoodsoftConfig.scope # Save scope in session to not allow switching between foodcoops with one account
redirect_to session['return_to'] || root_url, :notice => "Logged in!"
else
flash.now.alert = "Invalid email or password"