Class: Koi::Middleware::AdminAuthentication
- Inherits:
-
Object
- Object
- Koi::Middleware::AdminAuthentication
- Defined in:
- lib/koi/middleware/admin_authentication.rb
Instance Method Summary collapse
- #admin_call(env) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app) ⇒ AdminAuthentication
constructor
A new instance of AdminAuthentication.
Constructor Details
#initialize(app) ⇒ AdminAuthentication
Returns a new instance of AdminAuthentication.
6 7 8 |
# File 'lib/koi/middleware/admin_authentication.rb', line 6 def initialize(app) @app = app end |
Instance Method Details
#admin_call(env) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/koi/middleware/admin_authentication.rb', line 18 def admin_call(env) request = ActionDispatch::Request.new(env) session = ActionDispatch::Request::Session.find(request) if requires_authentication?(request) && !authenticated?(session) # Set the redirection path for returning the user to their requested path after login if request.get? request.flash[:redirect] = request.fullpath request.commit_flash end [303, { "Location" => "/admin/session/new" }, []] else @app.call(env) end end |
#call(env) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/koi/middleware/admin_authentication.rb', line 10 def call(env) if env["PATH_INFO"].starts_with?("/admin") admin_call(env) else @app.call(env) end end |