Class: Aker::Form::Middleware::LoginRenderer

Inherits:
Object
  • Object
show all
Includes:
LoginFormAssetProvider, Rack::ConfigurationHelper
Defined in:
lib/aker/form/middleware/login_renderer.rb

Overview

Rack middleware used by Aker::Form::Mode to render an HTML login form.

This middleware implements half of the form login process. The other half is implemented by LoginResponder.

Author:

  • David Yip

Instance Method Summary collapse

Methods included from Rack::ConfigurationHelper

#login_path, #logout_path

Methods included from Rack::EnvironmentHelper

#authority, #configuration, #interactive?

Methods included from LoginFormAssetProvider

#asset_root, #login_css, #login_html

Constructor Details

#initialize(app) ⇒ LoginRenderer

Instantiates the middleware.

Parameters:

  • app (Rack app)

    The Rack application on which this middleware should be layered.

  • login_path (String)

    the login path



22
23
24
# File 'lib/aker/form/middleware/login_renderer.rb', line 22

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

Rack entry point.

‘call` returns one of three responses, depending on the path and method.

  • If the method is GET and the path is ‘login_path`, `call` returns an HTML form for submitting a username and password.

  • If the method is GET and the path is ‘login_path + “/login.css”`, `call` returns the CSS for the aforementioned form.

  • Otherwise, ‘call` passes the request down through the Rack stack.

Returns:

  • a finished Rack response



39
40
41
42
43
44
45
# File 'lib/aker/form/middleware/login_renderer.rb', line 39

def call(env)
  case [env['REQUEST_METHOD'], env['PATH_INFO']]
    when ['GET', (env)];                (env)
    when ['GET', (env) + '/login.css']; 
    else                                          @app.call(env)
  end
end