Module: Sinatra::Authentication::Helpers
- Defined in:
- lib/sinatra/authentication/helpers.rb
Instance Method Summary collapse
- #__USER__ ⇒ Object
- #authenticate(opts) ⇒ Object
- #current_user(finder = lambda { |id| __USER__[id] }) ⇒ Object
-
#ensure_current_user(user) ⇒ Object
def logged_in? !!curent_user end.
- #logout! ⇒ Object
- #require_auth(cookies, required_roles = []) ⇒ Object
- #should_return_to?(path, ignored = settings.ignored_by_return_to) ⇒ Boolean
Instance Method Details
#__USER__ ⇒ Object
34 35 36 |
# File 'lib/sinatra/authentication/helpers.rb', line 34 def __USER__ settings.login_user_class end |
#authenticate(opts) ⇒ Object
28 29 30 31 32 |
# File 'lib/sinatra/authentication/helpers.rb', line 28 def authenticate(opts) if user = __USER__.authenticate(opts[:email], opts[:password]) user.id end end |
#current_user(finder = lambda { |id| __USER__[id] }) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/sinatra/authentication/helpers.rb', line 8 def current_user(finder = lambda { |id| __USER__[id] }) # Replace this with OttomanORM shit # NOTE: not keeping session data # @current_user ||= finder.call(session[:user]) if session[:user] nil end |
#ensure_current_user(user) ⇒ Object
def logged_in?
!!curent_user
end
19 20 21 |
# File 'lib/sinatra/authentication/helpers.rb', line 19 def ensure_current_user(user) halt 404 unless user == current_user end |
#logout! ⇒ Object
23 24 25 26 |
# File 'lib/sinatra/authentication/helpers.rb', line 23 def logout! # NOTE: not keeping session data # session.delete(:user) end |
#require_auth(cookies, required_roles = []) ⇒ Object
4 5 6 |
# File 'lib/sinatra/authentication/helpers.rb', line 4 def require_auth , required_roles = [] __USER__.user_auth(, required_roles) end |
#should_return_to?(path, ignored = settings.ignored_by_return_to) ⇒ Boolean
38 39 40 |
# File 'lib/sinatra/authentication/helpers.rb', line 38 def should_return_to?(path, ignored = settings.ignored_by_return_to) !(path =~ ignored) end |