Module: Sinatra::Warden::Helpers

Defined in:
lib/sinatra_warden/sinatra.rb

Instance Method Summary collapse

Instance Method Details

#authenticated?(*args) ⇒ Boolean Also known as: logged_in?

Proxy to the authenticated? method on warden

Returns:

  • (Boolean)


11
12
13
# File 'lib/sinatra_warden/sinatra.rb', line 11

def authenticated?(*args)
  warden.authenticated?(*args)
end

#authorize!(failure_path = nil) ⇒ Object

Require authorization for an action

Parameters:

  • path (String)

    to redirect to if user is unauthenticated



33
34
35
# File 'lib/sinatra_warden/sinatra.rb', line 33

def authorize!(failure_path=nil)
  redirect(failure_path ? failure_path : options.auth_failure_path) unless authenticated?
end

#user(*args) ⇒ Object Also known as: current_user

Access the currently logged in user



17
18
19
# File 'lib/sinatra_warden/sinatra.rb', line 17

def user(*args)
  warden.user(*args)
end

#user=(new_user) ⇒ Object Also known as: current_user=

Set the currently logged in user

Usage: self.user = @user

Parameters:

  • the (User)

    user you want to log in



26
27
28
# File 'lib/sinatra_warden/sinatra.rb', line 26

def user=(new_user)
  warden.set_user(new_user)
end

#wardenObject

The main accessor for the warden proxy instance



6
7
8
# File 'lib/sinatra_warden/sinatra.rb', line 6

def warden
  request.env['warden']
end