Project

General

Profile

Download (1.76 KB) Statistics
| Branch: | Tag: | Revision:

root / app / controllers / application.rb @ a579432b

1
# Filters added to this controller apply to all controllers in the application.
2
# Likewise, all the methods added will be available for all controllers.
3

    
4
require 'gettext/rails'
5
require 'exif'
6
require 'utils'
7
require 'mycyma'
8

    
9
#Mime::Type.register "image/svg+xml", :svg
10

    
11
class ApplicationController < ActionController::Base
12
  helper :all # include all helpers, all the time
13

    
14
  rescue_from RestfulSupport::ResourceNotFound, :with => :render_404
15
  rescue_from RestfulSupport::UnrelatedResources, :with => :render_404
16

    
17
  # See ActionController::RequestForgeryProtection for details
18
  # Uncomment the :secret if you're not using the cookie session store
19
  protect_from_forgery # :secret => '86f01f14fc184c81bf152965a2bccb88'
20

    
21
  filter_parameter_logging :password
22

    
23
  init_gettext MyCyma::Info::app_name
24

    
25
  def initialize
26
    super
27

    
28
    @config = MyCyma::Config.instance
29
  end
30

    
31
  def render_404
32
    render :template => "common/404", :layout => ! request.xhr?, :status => :not_found
33
    return false
34
  end
35

    
36
  def login_required
37
    return true if session[:user_id]
38

    
39
    flash[:warning] = _('Please login to continue')
40
    session[:return_to] = request.request_uri
41
    redirect_to :controller => "/logon", :action => "login"
42
    return false
43
  end
44

    
45
  def admin_required
46
    return true if login_required and current_user.admin
47

    
48
    @reject_reason = "You are not an Admin !"
49
    render :template => "common/403", :layout => ! request.xhr?, :status => :forbidden
50
    return false
51
  end
52

    
53
  def current_user
54
    @current_user ||= ((session[:user_id] && User.find_by_id(session[:user_id])) || nil)
55
  end
56

    
57
  def redirect_to_stored
58
    if return_to = session[:return_to]
59
      session[:return_to] = nil
60
      redirect_to(return_to)
61
    else
62
      redirect_to :controller => 'welcome', :action => 'index'
63
    end
64
  end
65
end
(2-2/5)