Class: Carpool::Seatbelt
- Inherits:
-
Object
- Object
- Carpool::Seatbelt
- Includes:
- Mixins::Core
- Defined in:
- lib/carpool/seatbelt.rb
Instance Attribute Summary collapse
-
#current_passenger ⇒ Object
Returns the value of attribute current_passenger.
-
#current_user ⇒ Object
Returns the value of attribute current_user.
-
#env ⇒ Object
Returns the value of attribute env.
-
#redirect_to ⇒ Object
Returns the value of attribute redirect_to.
Instance Method Summary collapse
- #auth_request! ⇒ Object
- #auth_request? ⇒ Boolean
- #authenticate! ⇒ Object
- #authentication_exists? ⇒ Boolean
- #authorize!(user = nil) ⇒ Object
-
#initialize(env) ⇒ Seatbelt
constructor
A new instance of Seatbelt.
- #revoke! ⇒ Object
- #success! ⇒ Object
Methods included from Mixins::Core
Constructor Details
#initialize(env) ⇒ Seatbelt
Returns a new instance of Seatbelt.
8 9 10 |
# File 'lib/carpool/seatbelt.rb', line 8 def initialize(env) @env = env end |
Instance Attribute Details
#current_passenger ⇒ Object
Returns the value of attribute current_passenger.
6 7 8 |
# File 'lib/carpool/seatbelt.rb', line 6 def current_passenger @current_passenger end |
#current_user ⇒ Object
Returns the value of attribute current_user.
6 7 8 |
# File 'lib/carpool/seatbelt.rb', line 6 def current_user @current_user end |
#env ⇒ Object
Returns the value of attribute env.
6 7 8 |
# File 'lib/carpool/seatbelt.rb', line 6 def env @env end |
#redirect_to ⇒ Object
Returns the value of attribute redirect_to.
6 7 8 |
# File 'lib/carpool/seatbelt.rb', line 6 def redirect_to @redirect_to end |
Instance Method Details
#auth_request! ⇒ Object
35 36 37 38 39 |
# File 'lib/carpool/seatbelt.rb', line 35 def auth_request! return if auth_request? ['passenger_uri'] = @env['HTTP_REFERER'] ['requesting_authentication'] = true end |
#auth_request? ⇒ Boolean
41 42 43 |
# File 'lib/carpool/seatbelt.rb', line 41 def auth_request? ['requesting_authentication'] && ['requesting_authentication'] == true end |
#authenticate! ⇒ Object
16 17 18 |
# File 'lib/carpool/seatbelt.rb', line 16 def authenticate! throw(:carpool, Carpool::Responder.authenticate) unless authentication_exists? end |
#authentication_exists? ⇒ Boolean
12 13 14 |
# File 'lib/carpool/seatbelt.rb', line 12 def authentication_exists? !carpool_passenger_tokens.empty? end |
#authorize!(user = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/carpool/seatbelt.rb', line 20 def (user = nil) unless Carpool.acts_as?(:passenger) return false unless auth_request? update_authentication!(passenger_for_auth[:secret]) token = Carpool::Encryptor.generate_token(user.encrypted_credentials, passenger_for_auth[:secret]) payload = Carpool::Encryptor.generate_payload(current_passenger, token) throw(:carpool, Carpool::Responder.passenger_redirect(current_passenger, payload)) else seatbelt = Carpool::Encryptor.process_seatbelt(request.params['seatbelt']) throw(:carpool, Carpool::Responder.invalid) and return unless seatbelt[:user].is_a?(Hash) @current_user = seatbelt[:user] @redirect_to = seatbelt[:redirect_to] end end |
#revoke! ⇒ Object
49 50 51 |
# File 'lib/carpool/seatbelt.rb', line 49 def revoke! destroy_session! end |
#success! ⇒ Object
53 54 55 |
# File 'lib/carpool/seatbelt.rb', line 53 def success! throw(:carpool, [303, {"Location" => @redirect_to.to_s}, "Authorized!"]) end |