This repository has been archived on 2020-05-27. You can view files and clone it, but cannot push or open issues/pull-requests.
binaryattraction/app/controllers/application.rb

57 lines
1.2 KiB
Ruby
Raw Normal View History

2008-10-01 02:19:35 -04:00
class Application < Merb::Controller
def index
redirect '/'
end
2008-10-01 02:19:35 -04:00
def current_user
if session[:user_id]
(@_user ||= User.find(session[:user_id]))
else
2008-10-17 18:02:22 -04:00
(cookies[:anonymous_id] ||= session.session_id)
end
end
def logged_in?
!session[:user_id].nil?
end
def administrator?
logged_in? and current_user and current_user.administrator?
2008-10-01 02:19:35 -04:00
end
def valid_anonymous_user?
!session[:validated_anonymous_user].nil?
end
def valid_anonymous_user!
session[:validated_anonymous_user] = true
end
2008-10-01 02:19:35 -04:00
def reset_session
session[:user_id] = nil
end
def get_photo_version(width, height)
key = "photo_#{@photo.id}_#{width}_#{height}"
img = Cache.get(key)
File.open("#{@photo.base_directory}/#{@photo.filename}", "r") do |f|
img = Magick::Image.from_blob(f.read).first.resize_to_fit(width, height)
Cache.put(key, img)
end if img.nil?
img
end
def fetch_allowed_user
@user = if administrator?
User.find_by_user_name params[:id]
elsif logged_in? and params[:id] != current_user.user_name
2008-10-11 18:36:28 -04:00
raise NotAcceptable
else
current_user
end
raise NotFound if @user.nil?
end
2008-10-01 02:19:35 -04:00
end