FlitterProvider

flitter-auth/flitter/FlitterProvider~ FlitterProvider

Local database authentication provider for Flitter.


Constructor

new FlitterProvider()

Extends

Members

(private) _di_allow_defer :boolean

If true, the injector will defer the class if the class requests any services that the container is missing. These services are filled in later and added to the prototype and any instances. True by default.

Type:
  • boolean

(private) _di_deferred_instances :Array.<module:flitter-di/src/Injectable~Injectable>

Collection of instances of this class that need to have the deferred service instances injected into them when the deferred services are finally provided.

(private) _di_deferred_services :Array.<string>

List of services that were deferred and not provided at the time of injection.

Type:
  • Array.<string>

app :module:libflitter/app/FlitterApp~FlitterApp

The Flitter app.

config :Object

The provider's config.

Type:
  • Object

User :module:flitter-auth/model/User~User

The User model's class.

Type:
  • module:flitter-auth/model/User~User

Methods

(async) check_user_auth(user, password) → {Promise.<boolean>}

Check the validity of the provided credentials.

Parameters:
Name Type Description
user string
password string
Returns:
  • true if the credentials succeed, false otherwise
Type
Promise.<boolean>

(async) cleanup(app) → {Promise.<void>}

Clean up resources used by this provider.

Parameters:
Name Type Description
app module:libflitter/app/FlitterApp~FlitterApp

the current app

Returns:
Type
Promise.<void>

(async) get_login_args(form_data) → {Promise.<Array.<string>>}

From the form data, get the formatted arguments to be passed into the login function. Should create the username and password params.

Parameters:
Name Type Description
form_data Object
Returns:
Type
Promise.<Array.<string>>

(async) get_registration_args(form_data) → {Promise.<Array.<*>>}

From the form data, get the formatted arguments to be passed into the registration function. Should create the username and {password} objects.

Parameters:
Name Type Description
form_data object

the form data from the request

Returns:
Type
Promise.<Array.<*>>

handle_login_get(req, res, next) → {Promise.<*>}

Handle a request to get the login view. By default, shows the view specified by this.registration_view(), passing it title, heading_text, provider_name

Parameters:
Name Type Description
req express/Request
res express/Response
next function
Returns:
Type
Promise.<*>

handle_register_get(req, res, next) → {Promise.<*>}

Handle a request to get the registration view. By default, shows the view specified by this.registration_view(), passing it title, heading_text, provider_name

Parameters:
Name Type Description
req express/Request
res express/Response
next function
Returns:
Type
Promise.<*>

(async) login(username, password, argsopt) → {Promise.<(boolean|module:flitter-auth/model/User~User)>}

Attempt to authenticate a user with the provided credentials. If it succeeds, return their User object.

Parameters:
Name Type Attributes Description
username string
password string
args <optional>

not required

Returns:
  • false if the auth is unsuccessful, a User instance if it is
Type
Promise.<(boolean|module:flitter-auth/model/User~User)>

login_view() → {string}

Get the Flitter canonical name of the login view.

Returns:
Type
string

(async) logout(request) → {Promise.<object>}

Log out the current user, if there is one, and clean the auth session.

Parameters:
Name Type Description
request express/Request
Returns:
  • the clean session
Type
Promise.<object>

logout_view() → {string}

Get the Flitter canonical name of the logout view.

Returns:
Type
string

(async) register(username, attrs, data) → {Promise.<module:flitter-auth/model/User~User>}

Register a new user.

Parameters:
Name Type Description
username string

name of the new user

attrs object

collection of key-value pairs to set in the model

data object

additional data to save in the model's JSON

Returns:
Type
Promise.<module:flitter-auth/model/User~User>

registration_view() → {string}

Get the Flitter canonical name of the registration view.

Returns:
Type
string

(async) session(request, user) → {Promise.<void>}

Bootstrap the session. Sets auth.user and auth.user_id.

Parameters:
Name Type Description
request express/Request
user module:flitter-auth/model/User~User

the authenticated user

Returns:
Type
Promise.<void>

(async) validate_login(form_data) → {Promise.<Array.<string>>}

Ensure that login form_data is valid. Checks for username.

Parameters:
Name Type Description
form_data object
Returns:
  • array of string errors. If empty array, no errors.
Type
Promise.<Array.<string>>

(async) validate_registration(form_data) → {Promise.<Array.<string>>}

Validate the form input to register a new user.

Parameters:
Name Type Description
form_data object

form data to validate

Returns:
  • collection of error messages. If array is empty, input is valid.
Type
Promise.<Array.<string>>