root/app/controllers/application.rb @ 5c2a70ab
b689e231 | Marc Dequènes (Duck) | # Filters added to this controller apply to all controllers in the application.
|
|
# Likewise, all the methods added will be available for all controllers.
|
|||
require 'gettext/rails'
|
|||
require 'exif'
|
|||
require 'utils'
|
|||
require 'mycyma'
|
|||
#Mime::Type.register "image/svg+xml", :svg
|
|||
class ApplicationController < ActionController::Base
|
|||
helper :all # include all helpers, all the time
|
|||
rescue_from RestfulSupport::ResourceNotFound, :with => :render_404
|
|||
rescue_from RestfulSupport::UnrelatedResources, :with => :render_404
|
|||
c60df68a | Marc Dequènes (Duck) | rescue_from ActiveRecord::RecordNotFound, :with => :render_404
|
|
b689e231 | Marc Dequènes (Duck) | ||
# See ActionController::RequestForgeryProtection for details
|
|||
# Uncomment the :secret if you're not using the cookie session store
|
|||
085f01eb | Marc Dequènes (Duck) | protect_from_forgery :secret => MyCyma::Config.instance.session_secret
|
|
b689e231 | Marc Dequènes (Duck) | ||
d0ff9068 | Marc Dequènes (Duck) | filter_parameter_logging :password
|
|
b689e231 | Marc Dequènes (Duck) | init_gettext MyCyma::Info::app_name
|
|
73f2fc18 | Marc Dequènes (Duck) | before_init_gettext :ensure_prefered_language
|
|
b689e231 | Marc Dequènes (Duck) | def initialize
|
|
super
|
|||
@config = MyCyma::Config.instance
|
|||
end
|
|||
def render_404
|
|||
render :template => "common/404", :layout => ! request.xhr?, :status => :not_found
|
|||
return false
|
|||
end
|
|||
d0ff9068 | Marc Dequènes (Duck) | ||
def login_required
|
|||
a579432b | Marc Dequènes (Duck) | return true if session[:user_id]
|
|
d0ff9068 | Marc Dequènes (Duck) | flash[:warning] = _('Please login to continue')
|
|
session[:return_to] = request.request_uri
|
|||
redirect_to :controller => "/logon", :action => "login"
|
|||
return false
|
|||
end
|
|||
a579432b | Marc Dequènes (Duck) | def admin_required
|
|
return true if login_required and current_user.admin
|
|||
@reject_reason = "You are not an Admin !"
|
|||
render :template => "common/403", :layout => ! request.xhr?, :status => :forbidden
|
|||
return false
|
|||
end
|
|||
d0ff9068 | Marc Dequènes (Duck) | def current_user
|
|
@current_user ||= ((session[:user_id] && User.find_by_id(session[:user_id])) || nil)
|
|||
end
|
|||
def redirect_to_stored
|
|||
if return_to = session[:return_to]
|
|||
session[:return_to] = nil
|
|||
redirect_to(return_to)
|
|||
else
|
|||
redirect_to :controller => 'welcome', :action => 'index'
|
|||
end
|
|||
end
|
|||
73f2fc18 | Marc Dequènes (Duck) | ||
def ensure_prefered_language
|
|||
@config.switch_locale(current_user.prefered_language) if current_user
|
|||
end
|
|||
b689e231 | Marc Dequènes (Duck) | end
|