Module: Sinatra::SimpleAuthentication::Controllers::Helpers
- Defined in:
- lib/sinatra/simple_authentication/controllers/helpers.rb
Instance Method Summary collapse
- #current_user ⇒ Object
-
#get_view_as_string(filename) ⇒ Object
BECAUSE sinatra 9.1.1 can’t load views from different paths properly.
- #logged_in? ⇒ Boolean
- #login_required ⇒ Object
Instance Method Details
#current_user ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/sinatra/simple_authentication/controllers/helpers.rb', line 17 def current_user if !!session[:user] Session.model_class.find_user(:id => session[:user]) else return false end end |
#get_view_as_string(filename) ⇒ Object
BECAUSE sinatra 9.1.1 can’t load views from different paths properly
30 31 32 33 34 35 36 37 38 |
# File 'lib/sinatra/simple_authentication/controllers/helpers.rb', line 30 def get_view_as_string(filename) view = File.join(settings.sinatra_authentication_view_path, filename) data = "" f = File.open(view, "r") f.each_line do |line| data += line end return data end |
#logged_in? ⇒ Boolean
25 26 27 |
# File 'lib/sinatra/simple_authentication/controllers/helpers.rb', line 25 def logged_in? !!session[:user] end |
#login_required ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/sinatra/simple_authentication/controllers/helpers.rb', line 7 def login_required if !!current_user return true else session[:return_to] = request.fullpath redirect '/login' return false end end |