Module: Sinatra::Authentication::Helpers

Defined in:
lib/sinatra/authentication/helpers.rb

Instance Method Summary collapse

Instance Method Details

#__USER__Object



34
35
36
# File 'lib/sinatra/authentication/helpers.rb', line 34

def __USER__
    settings.
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 cookies, required_roles = []
    __USER__.user_auth(cookies, required_roles)
end

#should_return_to?(path, ignored = settings.ignored_by_return_to) ⇒ Boolean

Returns:

  • (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