Module: Sinatra::Warden::Helpers
- Defined in:
- lib/sinatra_warden/sinatra.rb
Instance Method Summary collapse
-
#authenticate(*args) ⇒ Object
(also: #login)
Authenticate a user against defined strategies.
-
#authenticated?(scope = nil) ⇒ Boolean
(also: #logged_in?)
Check the current session is authenticated to a given scope.
-
#authorize!(failure_path = nil) ⇒ Object
Require authorization for an action.
-
#logout(scopes = nil) ⇒ Object
Terminate the current session.
-
#session_info(scope = nil) ⇒ Object
Return session info.
-
#user(scope = nil) ⇒ Object
(also: #current_user)
Access the user from the current session.
-
#user=(new_user, opts = {}) ⇒ Object
(also: #current_user=)
Store the logged in user in the session.
-
#warden ⇒ Object
The main accessor to the warden middleware.
Instance Method Details
#authenticate(*args) ⇒ Object Also known as: login
Authenticate a user against defined strategies
25 26 27 |
# File 'lib/sinatra_warden/sinatra.rb', line 25 def authenticate(*args) warden.authenticate!(*args) end |
#authenticated?(scope = nil) ⇒ Boolean Also known as: logged_in?
Check the current session is authenticated to a given scope
19 20 21 |
# File 'lib/sinatra_warden/sinatra.rb', line 19 def authenticated?(scope=nil) scope ? warden.authenticated?(:scope => scope) : warden.authenticated? end |
#authorize!(failure_path = nil) ⇒ Object
Require authorization for an action
59 60 61 62 63 64 |
# File 'lib/sinatra_warden/sinatra.rb', line 59 def (failure_path=nil) unless authenticated? session[:return_to] = request.path if settings.auth_use_referrer redirect(failure_path ? failure_path : settings.auth_failure_path) end end |
#logout(scopes = nil) ⇒ Object
Terminate the current session
33 34 35 |
# File 'lib/sinatra_warden/sinatra.rb', line 33 def logout(scopes=nil) scopes ? warden.logout(scopes) : warden.logout(warden.config.default_scope) end |
#session_info(scope = nil) ⇒ Object
Return session info
14 15 16 |
# File 'lib/sinatra_warden/sinatra.rb', line 14 def session_info(scope=nil) scope ? warden.session(scope) : scope end |
#user(scope = nil) ⇒ Object Also known as: current_user
Access the user from the current session
40 41 42 |
# File 'lib/sinatra_warden/sinatra.rb', line 40 def user(scope=nil) scope ? warden.user(scope) : warden.user end |
#user=(new_user, opts = {}) ⇒ Object Also known as: current_user=
Store the logged in user in the session
51 52 53 |
# File 'lib/sinatra_warden/sinatra.rb', line 51 def user=(new_user, opts={}) warden.set_user(new_user, opts) end |
#warden ⇒ Object
The main accessor to the warden middleware
7 8 9 |
# File 'lib/sinatra_warden/sinatra.rb', line 7 def warden request.env['warden'] end |