# Engenharia de Software 2007.1 # Copyright (C) 2007, Adriano, Alinson, Andre, Rafael e Bustamante # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. require 'yaml' class ApplicationController < ActionController::Base include AuthenticationSystem before_filter :startup around_filter :set_timezone # Força o login para algumas áreas do sistema before_filter :require_login, :only => [ :edit, :new, :create, :update, :delete, :destroy, :download ] protected def rescue_action(exception) # Acesso negado if exception.is_a?(AccessDenied) respond_to do |format| format.html { render :file => "#{RAILS_ROOT}/public/401.html", :status => 401 } format.xml { head 401 } end # Erro de validacao elsif exception.is_a?(ActiveRecord::RecordInvalid) respond_to do |format| format.html { render :action => (exception.record.new_record? ? 'new' : 'edit') } format.xml { render :xml => exception.record.errors, :status => :unprocessable_entity } end # Registro nao encontrado elsif (RAILS_ENV == 'production') and exception.is_a?(ActiveRecord::RecordNotFound) respond_to do |format| format.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => 404 } format.xml { head 404 } end # Outras excecoes else super end end def set_timezone #TzTime.zone = session[:user].tz TzTime.zone = TZInfo::Timezone.get("America/Fortaleza") yield TzTime.reset! end def startup if session[:user_id] @current_user = User.find(session[:user_id]) else login_by_token end @color = App.default_color @color = @current_user.pref_color if @current_user @color = params[:color].to_i if params[:color] end end