mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-01 21:51:49 +01:00
I'm intending this to be the last big change before releasing 1.04. Can people with access to the trunk through subversion check out this changeset and report any bugs? git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@182 a4c988fc-2ded-0310-b66e-134b36920a42
61 lines
1.7 KiB
Ruby
61 lines
1.7 KiB
Ruby
# The filters added to this controller will be run for all controllers in the application.
|
|
# Likewise will all the methods added be available for all controllers.
|
|
|
|
require_dependency "login_system"
|
|
|
|
require 'date'
|
|
|
|
class ApplicationController < ActionController::Base
|
|
|
|
helper :application
|
|
include LoginSystem
|
|
|
|
before_filter :set_session_expiration
|
|
before_filter :get_current_user
|
|
|
|
# Count the number of uncompleted actions, excluding those
|
|
# in hidden contexts
|
|
#
|
|
def count_shown_items(hidden)
|
|
count = 0
|
|
sub = 0
|
|
hidden.each do |h|
|
|
sub = Todo.find_all("done=0 AND context_id=#{h.id}").length + sub
|
|
end
|
|
total = Todo.find_all("done=0").length - sub
|
|
end
|
|
|
|
# Reverses the urlize() method by substituting underscores for spaces
|
|
#
|
|
def deurlize(name)
|
|
name.to_s.gsub(/_/, " ")
|
|
end
|
|
|
|
def set_session_expiration
|
|
# http://wiki.rubyonrails.com/rails/show/HowtoChangeSessionOptions
|
|
unless @session == nil
|
|
return if @controller_name == 'feed' or @session['noexpiry'] == "on"
|
|
# If the method is called by the feed controller (which we don't have under session control)
|
|
# or if we checked the box to keep logged in on login
|
|
# don't set the session expiry time.
|
|
if @session
|
|
# Get expiry time (allow ten seconds window for the case where we have none)
|
|
expiry_time = @session['expiry_time'] || Time.now + 10
|
|
if expiry_time < Time.now
|
|
# Too late, matey... bang goes your session!
|
|
reset_session
|
|
else
|
|
# Okay, you get another hour
|
|
@session['expiry_time'] = Time.now + (60*60)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def get_current_user
|
|
@user = @session['user']
|
|
end
|
|
|
|
end
|