This repository has been archived on 2020-05-27. You can view files and clone it, but cannot push or open issues/pull-requests.
2008-10-01 02:19:35 -04:00
|
|
|
class Application < Merb::Controller
|
2008-10-11 04:22:58 -04:00
|
|
|
def index
|
|
|
|
redirect '/'
|
|
|
|
end
|
|
|
|
|
2008-10-01 02:19:35 -04:00
|
|
|
def current_user
|
2008-10-11 04:22:58 -04:00
|
|
|
if session[:user_id]
|
|
|
|
(@user ||= User.find(session[:user_id]))
|
|
|
|
else
|
|
|
|
(cookies[:session_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 reset_session
|
|
|
|
session[:user_id] = nil
|
|
|
|
end
|
2008-10-11 04:22:58 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
raise NotAllowed
|
|
|
|
else
|
|
|
|
current_user
|
|
|
|
end
|
|
|
|
raise NotFound if @user.nil?
|
|
|
|
end
|
2008-10-01 02:19:35 -04:00
|
|
|
end
|