Module: controllers/authentication

Controller module providing logic for managing api authentication

Author:
Source:
Example
import { authentication as authenticationController } from '/src/controllers';

Methods

(async, static) confirmEmail(request, response, next)

Confirm email token

Parameters:
Name Type Description
request Object

HTTP request object

response Object

HTTP response callback object

next Object

Next route handler callback object

Source:
Throws:
    • Will throw an error if there is no URL query string.
    • Will throw an error if there is no token query string.
    • Will throw an error if token is not found in ConfirmEmailToken table.
    • Will throw an error if user can not be updated to confirm email true.
Returns:
  • Will returns HTTP response body.

(async, static) forgotPassword(request, response, next)

Will destroy reset tokens that are past now.

Parameters:
Name Type Description
request Object

HTTP request object.

response Object

HTTP response object callback.

next Object

Next route callback handler.

Source:
Returns:
    • Will return a http response body with a message confirming token emailed.
    • WIll return an error message if there is no request.body.
    • Will return an error message if no email provided.
    • Will return an error message if user cannot be found for the email address.
    • Will return an error message if previous reset tokens can not be updated as used for user requesting.
    • Will return an error message if a reset token cannot be generated.
    • Will return an error message if the reset token email cannot be sent.

(async, static) login(request, response, next)

API login controller for local username and password authentication

Parameters:
Name Type Description
request Object

HTTP request object

response Object

HTTP response callback object

next Object

Next route handler callback object

Source:
Returns:
  • Returns HTTP response body

(async, static) registerUser(request, response, next)

Register as a new user

Parameters:
Name Type Description
request Object

HTTP request object

response Object

HTTP response callback object

next Object

Next route handler callback object

Source:
Returns:
  • Returns HTTP response body

(async, static) resetPassword(request, response, next)

Reset password for email address if User.Id and token match the database and is not expired

Parameters:
Name Type Description
request Object

HTTP request object.

response Object

HTTP response object callback.

next Object

Next route callback handler.

Source:
Returns:
    • Will return a http response body.
    • Will return an error if no request query is sent.
    • Will return an error is there is no email or no token or no password.
    • Will return an error if a user cannot be found for the email address.
    • Will return an error if the email and token can not be validated.
    • Will return an error if password1 does not match password 2.