mailr/app/controllers/application_controller.rb

47 lines
1,016 B
Ruby
Raw Normal View History

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-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
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
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
end