2011-07-21 20:20:15 +02:00
|
|
|
require 'yaml'
|
2011-06-24 23:48:08 +02:00
|
|
|
|
2011-07-21 20:20:15 +02:00
|
|
|
class ApplicationController < ActionController::Base
|
2011-06-24 23:48:08 +02:00
|
|
|
|
2011-08-02 23:12:17 +02:00
|
|
|
#unless config.consider_all_requests_local
|
|
|
|
# #rescue_from ActionController::RoutingError, :with => :route_not_found
|
|
|
|
# rescue_from ActiveRecord::RecordNotFound, :with => :route_not_found
|
|
|
|
#end
|
|
|
|
|
2011-07-21 20:20:15 +02:00
|
|
|
protect_from_forgery
|
2011-07-23 21:55:26 +02:00
|
|
|
before_filter :load_defaults,:set_locale,:current_user
|
2009-01-07 20:27:12 +01:00
|
|
|
|
2011-08-02 23:12:17 +02:00
|
|
|
################################# protected section ###########################################
|
|
|
|
|
2011-07-21 20:20:15 +02:00
|
|
|
protected
|
2009-09-01 14:23:05 +02:00
|
|
|
|
2011-07-21 20:20:15 +02:00
|
|
|
def load_defaults
|
2011-07-24 15:56:47 +02:00
|
|
|
$defaults ||= YAML::load(File.open(Rails.root.join('config','defaults.yml')))
|
2011-07-21 20:20:15 +02:00
|
|
|
end
|
2011-06-24 23:48:08 +02:00
|
|
|
|
2011-07-21 20:20:15 +02:00
|
|
|
def theme_resolver
|
2011-07-23 21:55:26 +02:00
|
|
|
if @current_user.nil?
|
2011-07-24 15:56:47 +02:00
|
|
|
$defaults['theme']
|
2011-07-23 21:55:26 +02:00
|
|
|
else
|
2011-07-24 22:22:13 +02:00
|
|
|
@current_user.prefs.theme || $defaults['theme']
|
2011-07-23 21:55:26 +02:00
|
|
|
end
|
2011-07-21 20:20:15 +02:00
|
|
|
end
|
2009-09-01 14:23:05 +02:00
|
|
|
|
2011-07-21 20:20:15 +02:00
|
|
|
def set_locale
|
2011-07-23 21:55:26 +02:00
|
|
|
if @current_user.nil?
|
2011-07-24 15:56:47 +02:00
|
|
|
I18n.locale = $defaults['locale'] || I18n.default_locale
|
2011-07-23 21:55:26 +02:00
|
|
|
else
|
2011-07-24 15:56:47 +02:00
|
|
|
I18n.locale = @current_user.prefs.locale || I18n.default_locale
|
2011-07-23 21:55:26 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_user
|
|
|
|
@current_user ||= User.find(session[:user_id]) if session[:user_id]
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_current_user
|
|
|
|
if @current_user.nil?
|
|
|
|
session["return_to"] = request.fullpath
|
|
|
|
redirect_to :controller=>"user", :action => "login"
|
|
|
|
return false
|
|
|
|
end
|
2011-07-21 20:20:15 +02:00
|
|
|
end
|
2009-01-07 20:27:12 +01:00
|
|
|
|
2011-07-27 20:34:30 +02:00
|
|
|
def selected_folder
|
2011-07-29 20:21:17 +02:00
|
|
|
session[:selected_folder] ? @selected_folder = session[:selected_folder] : @selected_folder = $defaults['mailbox_inbox']
|
2011-07-27 20:34:30 +02:00
|
|
|
end
|
|
|
|
|
2011-07-31 22:45:29 +02:00
|
|
|
def get_current_folders
|
|
|
|
@folders_shown = @current_user.folders.shown.order("name asc")
|
|
|
|
@current_folder = @current_user.folders.current(@selected_folder)
|
|
|
|
end
|
|
|
|
|
2011-08-02 23:12:17 +02:00
|
|
|
##################################### private section ##########################################
|
|
|
|
|
|
|
|
#private
|
|
|
|
|
|
|
|
#def route_not_found
|
|
|
|
# render :text => 'What the fuck are you looking for ?', :status => :not_found
|
|
|
|
#end
|
|
|
|
|
2009-01-07 20:27:12 +01:00
|
|
|
end
|