Files
mapknitter/app/controllers/application_controller.rb
Sasha Boginsky a3bf9f6369 Upgrade to mySQL5.7, Ruby warning reductions, .md file updates (#355)
* delete old rails configurations

* update pr template

* update readme and docker image name

* add a mysql setup file

* update broken recaptcha link

* use File.exist? instead

* bump mysql2

* control mysql2 gem

* add custom rake test functions to provide option to suppress warnings

* small edit to mysql.md

* another one

* add rake task for total tests

* add a require for sass gem

* update deprecated URI.encode

* undo a comment on Rakefile I made

* ensure consistency for rake task names

* migrate rake tasks to new branch

* update readme

* update encoding method
2019-03-11 18:24:01 -04:00

56 lines
1.2 KiB
Ruby
Executable File

class ApplicationController < ActionController::Base
#include OpenIdAuthentication # shouldn't be necessary!!
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
helper :all # include all helpers, all the time
before_filter :current_user, :check_subdomain
helper_method :logged_in?
def current_user
user_id = session[:user_id]
if user_id
begin
@user = User.find(user_id)
rescue
@user = nil
end
else
@user = nil
end
end
def check_subdomain
if request.subdomain.present? && Rails.env != 'test'
redirect_to 'http://' + request.domain + request.port_string + request.fullpath
end
end
private
def require_login
unless logged_in?
path_info = request.env['PATH_INFO']
flash[:warning] = "You must be logged in to access this section"
redirect_to '/login?back_to=' + path_info.to_param # halts request cycle
end
end
def logged_in?
user_id = session[:user_id]
begin
if user_id and User.find(user_id)
return true
else
return false
end
rescue
return false
end
end
end