Class: Authie::RackController
- Inherits:
-
Object
- Object
- Authie::RackController
- Defined in:
- lib/authie/rack_controller.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #auth_session ⇒ Object
- #cookies ⇒ Object
- #current_user ⇒ Object
- #current_user=(user) ⇒ Object
-
#initialize(env) ⇒ RackController
constructor
A new instance of RackController.
-
#set_browser_id ⇒ Object
Set a random browser ID for this browser.
Constructor Details
#initialize(env) ⇒ RackController
Returns a new instance of RackController.
16 17 18 19 20 |
# File 'lib/authie/rack_controller.rb', line 16 def initialize(env) @env = env @request = ActionDispatch::Request.new(@env) set_browser_id end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
14 15 16 |
# File 'lib/authie/rack_controller.rb', line 14 def request @request end |
Instance Method Details
#auth_session ⇒ Object
44 45 46 |
# File 'lib/authie/rack_controller.rb', line 44 def auth_session @auth_session ||= Session.get_session(self) end |
#cookies ⇒ Object
22 23 24 |
# File 'lib/authie/rack_controller.rb', line 22 def @request. end |
#current_user ⇒ Object
40 41 42 |
# File 'lib/authie/rack_controller.rb', line 40 def current_user auth_session.user if auth_session.is_a?(Session) end |
#current_user=(user) ⇒ Object
36 37 38 |
# File 'lib/authie/rack_controller.rb', line 36 def current_user=(user) Session.start(self, user: user) end |
#set_browser_id ⇒ Object
Set a random browser ID for this browser.
27 28 29 30 31 32 33 34 |
# File 'lib/authie/rack_controller.rb', line 27 def set_browser_id until [:browser_id] proposed_browser_id = SecureRandom.uuid unless Session.where(browser_id: proposed_browser_id).exists? [:browser_id] = { value: proposed_browser_id, expires: 20.years.from_now } end end end |