2011-08-09 10:23:09 +00:00
|
|
|
class ApplicationController < ActionController::Base
|
2011-08-11 02:02:04 +00:00
|
|
|
before_filter :set_user, :count_visits
|
2011-08-09 10:23:09 +00:00
|
|
|
protect_from_forgery
|
2011-08-10 02:03:10 +00:00
|
|
|
|
2011-08-11 02:02:04 +00:00
|
|
|
private
|
|
|
|
def count_visits
|
|
|
|
value = (cookies[:visits] || '0').to_i
|
|
|
|
cookies[:visits] = (value + 1).to_s
|
|
|
|
@visits = cookies[:visits]
|
|
|
|
end
|
|
|
|
|
2011-08-10 02:03:10 +00:00
|
|
|
protected
|
2011-08-11 02:02:04 +00:00
|
|
|
def set_user
|
|
|
|
@user = User.find(session[:id]) if @user.nil? && session[:id]
|
|
|
|
end
|
2011-08-10 02:03:10 +00:00
|
|
|
|
2011-08-11 02:02:04 +00:00
|
|
|
def login_required
|
|
|
|
return true if @user
|
|
|
|
access_denied
|
|
|
|
return false
|
|
|
|
end
|
2011-08-10 02:03:10 +00:00
|
|
|
|
2011-08-11 02:02:04 +00:00
|
|
|
def access_denied
|
2011-08-11 02:09:24 +00:00
|
|
|
session[:return_to] = request.fullpath
|
2011-08-11 02:02:04 +00:00
|
|
|
flash[:error] = 'Oops. You need to login before you can view that page.'
|
|
|
|
redirect_to :controller => 'user', :action => 'login'
|
|
|
|
end
|
2011-08-09 10:23:09 +00:00
|
|
|
end
|