mirror of
https://github.com/publiclab/mapknitter.git
synced 2025-12-11 18:59:59 +01:00
* Remove trailing white spaces and unnecessary blank lines * Remove basic rubocop offenses * add few maps tests * refactor maps controller * fix 'line too long' rubocop offense
45 lines
989 B
Ruby
Executable File
45 lines
989 B
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
|
|
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
|
|
|
|
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
|
|
user_id && User.find(user_id) ? true : false
|
|
rescue
|
|
return false
|
|
end
|
|
end
|
|
end
|