Class: Aker::Form::Mode
- Inherits:
-
Modes::Base
- Object
- Warden::Strategies::Base
- Modes::Base
- Aker::Form::Mode
- Includes:
- Modes::Support::AttemptedPath, Rack::Utils
- Defined in:
- lib/aker/form/mode.rb
Overview
An interactive mode that accepts a username and password POSTed from an HTML form.
It expects the username in a username parameter and the unobfuscated
password in a password parameter.
This mode also renders said HTML form if authentication fails. This is provided by Aker::Form::Middleware::LoginRenderer.
Class Method Summary (collapse)
-
+ (Object) append_middleware(builder)
Appends the login responder to its position in the Rack middleware stack.
-
+ (Symbol) key
A key that refers to this mode; used for configuration convenience.
-
+ (String) login_path
The path at which the login form will be accessible.
-
+ (Object) prepend_middleware(builder)
Prepends the login form renderer to its position in the Rack middleware stack.
Instance Method Summary (collapse)
-
- (Array<String>) credentials
Extracts username and password from request parameters.
-
- (Symbol) kind
The type of credentials supplied by this mode.
-
- (String) login_url
The absolute URL for the login form.
-
- (Rack::Response) on_ui_failure
Builds a Rack response that redirects to the login form.
-
- (Boolean) valid?
Returns true if username and password are present, false otherwise.
Methods included from Modes::Support::AttemptedPath
Methods inherited from Modes::Base
#authenticate!, #authority, #configuration, #interactive?, #store?
Methods included from Rack::EnvironmentHelper
#authority, #configuration, #interactive?
Class Method Details
+ (Object) append_middleware(builder)
Appends the login responder to its position in the Rack middleware stack.
46 47 48 49 |
# File 'lib/aker/form/mode.rb', line 46 def self.append_middleware(builder) builder.use(Middleware::LoginResponder, login_path) builder.use(Middleware::LogoutResponder) end |
+ (Symbol) key
A key that refers to this mode; used for configuration convenience.
26 27 28 |
# File 'lib/aker/form/mode.rb', line 26 def self.key :form end |
+ (String) login_path
The path at which the login form will be accessible. Currently
hard-wired as /login.
This path is specified relative to the application's mount point. If you're looking for the absolute URL of the login form, you need to use login_url.
39 40 41 |
# File 'lib/aker/form/mode.rb', line 39 def self.login_path '/login' end |
+ (Object) prepend_middleware(builder)
Prepends the login form renderer to its position in the Rack middleware stack.
54 55 56 |
# File 'lib/aker/form/mode.rb', line 54 def self.prepend_middleware(builder) builder.use(Middleware::LoginRenderer, login_path) end |
Instance Method Details
- (Array<String>) credentials
Extracts username and password from request parameters.
71 72 73 |
# File 'lib/aker/form/mode.rb', line 71 def credentials [request['username'], request['password']].compact end |
- (Symbol) kind
The type of credentials supplied by this mode.
62 63 64 |
# File 'lib/aker/form/mode.rb', line 62 def kind :user end |
- (String) login_url
The absolute URL for the login form.
85 86 87 88 89 |
# File 'lib/aker/form/mode.rb', line 85 def login_url uri = URI.parse(request.url) uri.path = env['SCRIPT_NAME'] + self.class.login_path uri.to_s end |
- (Rack::Response) on_ui_failure
Builds a Rack response that redirects to the login form.
95 96 97 98 99 |
# File 'lib/aker/form/mode.rb', line 95 def on_ui_failure ::Rack::Response.new do |resp| resp.redirect(login_url + '?url=' + escape(attempted_path)) end end |
- (Boolean) valid?
Returns true if username and password are present, false otherwise.
77 78 79 |
# File 'lib/aker/form/mode.rb', line 77 def valid? credentials.length == 2 end |