42 lines
1.4 KiB
Ruby
42 lines
1.4 KiB
Ruby
class ApplicationController < ActionController::Base
|
|
# Prevent CSRF attacks by raising an exception.
|
|
# For APIs, you may want to use :null_session instead.
|
|
protect_from_forgery with: :exception
|
|
|
|
# Do not mention passwords in the log file
|
|
# filter_parameter_logging :password
|
|
|
|
before_action :get_current_users_screenshots, :moderate_packages
|
|
# TODO: Deprecation. What is the replacement for Rails.env.development? ?
|
|
|
|
# Query for packages that were uploaded by the current user.
|
|
# If the user is anonymous then find the uploads by the cookie token.
|
|
# If the user is logged in then find the uploads by matching the user id.
|
|
def get_current_users_screenshots
|
|
if user_signed_in?
|
|
@current_users_screenshots = current_user.screenshots
|
|
end
|
|
end
|
|
|
|
# If the current user is an administrator then show a second bar below
|
|
# the navigation bar that contains a paginator of packages that contain
|
|
# screenshots that require moderation.
|
|
def moderate_packages
|
|
if user_signed_in? and current_user.is_admin? and Package.need_moderation.any?
|
|
@moderate_packages = Package.need_moderation
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
# Define where the user is redirected to after a successful login.
|
|
def after_sign_in_path_for(resource)
|
|
my_profile_path
|
|
#my_welcome_path
|
|
end
|
|
|
|
# Overwriting the sign_out redirect path method
|
|
def after_sign_out_path_for(resource_or_scope)
|
|
root_path
|
|
end
|
|
end
|