Class: MagicLinks::Middleware::MagicTokenRedirect::Handler
- Inherits:
-
Object
- Object
- MagicLinks::Middleware::MagicTokenRedirect::Handler
- Defined in:
- lib/magic_links/middleware/magic_token_redirect.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #handle ⇒ Object
-
#initialize(env) ⇒ Handler
constructor
A new instance of Handler.
- #magic_token ⇒ Object
- #path ⇒ Object
- #redirect_request? ⇒ Boolean
- #root ⇒ Object
- #scope ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(env) ⇒ Handler
Returns a new instance of Handler.
17 18 19 |
# File 'lib/magic_links/middleware/magic_token_redirect.rb', line 17 def initialize(env) @request = ActionDispatch::Request.new(env) end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
33 34 35 |
# File 'lib/magic_links/middleware/magic_token_redirect.rb', line 33 def request @request end |
Instance Method Details
#handle ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/magic_links/middleware/magic_token_redirect.rb', line 21 def handle return unless redirect_request? return root unless magic_token.present? .encrypted[magic_token_key] = {value: magic_token.token, expires: } if scope respond_with_redirect magic_token.target_path end |
#magic_token ⇒ Object
43 44 45 46 47 |
# File 'lib/magic_links/middleware/magic_token_redirect.rb', line 43 def magic_token return unless token @magic_token ||= MagicToken.find_by(token: token) end |
#path ⇒ Object
35 36 37 |
# File 'lib/magic_links/middleware/magic_token_redirect.rb', line 35 def path request.path end |
#redirect_request? ⇒ Boolean
39 40 41 |
# File 'lib/magic_links/middleware/magic_token_redirect.rb', line 39 def redirect_request? Templates.match?(path) end |
#root ⇒ Object
29 30 31 |
# File 'lib/magic_links/middleware/magic_token_redirect.rb', line 29 def root respond_with_redirect '/', 'to the home page (token not found)' end |
#scope ⇒ Object
53 54 55 |
# File 'lib/magic_links/middleware/magic_token_redirect.rb', line 53 def scope magic_token&.scope end |