2 # This file is part of SMR.
4 # SMR is free software: you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
9 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # SMR. If not, see <http://www.gnu.org/licenses/>.
16 class ApplicationController < ActionController::Base
17 before_filter :force_login
18 helper_method :current_user
22 # redirect to login unless we have a authenticated current_user
24 unless current_user or params[:controller].eql?'sessions'
25 redirect_to :controller=>'sessions', :action=>'new'
29 # find current_user by :auth_token cookie
31 @current_user ||= User.find_by_password_auth_token!(cookies[:auth_token]) if cookies[:auth_token]
34 # print whatever is given as parameter to the servers output
35 def debug(*parameters)
36 parameters.each { |p| print 'DEBUG> ', p.inspect }
43 # set session parameters that are of global use
44 # - these can be modified through POST from anywhere
48 # * smr_browse_date = {"day"=>"23","month"=>"5","year"=>"2010"}
50 def set_session_params
52 if params[:smr_browse_date] then
53 d=params[:smr_browse_date]
54 session[:smr_browse_date] = Time.new(d['year'],d['month'],d['day']).end_of_day.to_i
60 # return date the user is currently browsing, as Time
62 if session[:smr_browse_date].nil? then Time.new
63 else Time.at(session[:smr_browse_date]) end