Class: Rottweiler::Auth::Settings
- Inherits:
-
Object
- Object
- Rottweiler::Auth::Settings
- Defined in:
- lib/rottweiler/auth/settings.rb
Overview
Implements the logic for requests authentication in Rails controllers.
Instance Method Summary collapse
- #auth_failed_cbk ⇒ Object
- #auth_failed_cbk=(callback) ⇒ Object
- #auth_success_cbk ⇒ Object
- #auth_success_cbk=(callback) ⇒ Object
- #authenticate(request) ⇒ Object
-
#initialize(superklass) ⇒ Settings
constructor
A new instance of Settings.
- #reset! ⇒ Object
- #reset_skip! ⇒ Object
- #skip_authentication!(only: nil, except: nil) ⇒ Object
- #skip_authentication?(action_name) ⇒ Boolean
Constructor Details
#initialize(superklass) ⇒ Settings
Returns a new instance of Settings.
9 10 11 12 |
# File 'lib/rottweiler/auth/settings.rb', line 9 def initialize(superklass) @super_params = superklass.rottweiler if superklass.respond_to?(:rottweiler) reset! end |
Instance Method Details
#auth_failed_cbk ⇒ Object
53 54 55 |
# File 'lib/rottweiler/auth/settings.rb', line 53 def auth_failed_cbk @auth_failed_cbk || @super_params&.auth_failed_cbk end |
#auth_failed_cbk=(callback) ⇒ Object
47 48 49 50 51 |
# File 'lib/rottweiler/auth/settings.rb', line 47 def auth_failed_cbk=(callback) validate_callback!(callback) @auth_failed_cbk = callback end |
#auth_success_cbk ⇒ Object
63 64 65 |
# File 'lib/rottweiler/auth/settings.rb', line 63 def auth_success_cbk @auth_success_cbk || @super_params&.auth_success_cbk end |
#auth_success_cbk=(callback) ⇒ Object
57 58 59 60 61 |
# File 'lib/rottweiler/auth/settings.rb', line 57 def auth_success_cbk=(callback) validate_callback!(callback) @auth_success_cbk = callback end |
#authenticate(request) ⇒ Object
67 68 69 |
# File 'lib/rottweiler/auth/settings.rb', line 67 def authenticate(request) Result.new(request) end |
#reset! ⇒ Object
14 15 16 17 18 |
# File 'lib/rottweiler/auth/settings.rb', line 14 def reset! @auth_failed_cbk = nil @auth_success_cbk = nil reset_skip! end |
#reset_skip! ⇒ Object
20 21 22 |
# File 'lib/rottweiler/auth/settings.rb', line 20 def reset_skip! @skip = { only: [], except: [], all: false } end |
#skip_authentication!(only: nil, except: nil) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/rottweiler/auth/settings.rb', line 24 def skip_authentication!(only: nil, except: nil) raise Rottweiler::InvalidParamsError, 'You can only use `only` or `except`, not both' if only && except reset_skip! @skip[:only] = sanitize_action_names(only) @skip[:except] = sanitize_action_names(except) @skip[:all] = true if only.nil? end |
#skip_authentication?(action_name) ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rottweiler/auth/settings.rb', line 34 def skip_authentication?(action_name) action_name = action_name.to_sym # Use the most local value if it's set, otherwise use the value from the superclass return true if @skip[:only].include?(action_name) return true if @skip[:all] && !@skip[:except].include?(action_name) # If there's no superclass, return false, otherwise return the value from the superclass return @super_params.skip_authentication?(action_name) unless @super_params.nil? false end |