User Manager

Introduction

This involves interaction with the authenticated user in some way.

User Manager

The UserManager object enables you get information about the current authenticated user as well as interacting with the User Schema. Methods directly available on this object include -

Get User

This method is used to retrieve a particular user where the username is known. Definition of this method is given as -

/**
* Get user by username and domain.
* @param {String} username Username
* @param {ObjectId} domain Domain
* @param {Function} fn Callback
* @return {Object} User.
*/
function(username, domain, fn) {};

Example using this within a processor -

this.entityRepo
.infrastructure()
.userManager.getUser(MY_USERNAME, DOMAIN_ID, (error, user) => {});

Update User

This method is used to update a user's information. Definition of this method is given as -

/**
* Updates an existing user
* @param {Object} user Existing user
* @param {any} withPassword determines whether to update the user password also.
* @param {Function} fn Callback
*
*/
Infrastructure.prototype.updateUser = function (user, withPassword, fn) {};

Example using this within a processor -

this.entityRepo
.infrastructure()
.userManager.updateUser(USER_OBJECT, false, (error, updatedUser) => {});

In Role

This method is used to check if a user is in a particular role. Definition of this method is given as -

/**
* Check if user belongs to roleName
* @param {String} roleName Name of the Role
* @param {Object} user User Object
* @param {Function} fn Callback function returns Error, Boolean
*/
Infrastructure.prototype.inRole = function (roleName, user, fn) {};

Example using this method is given as -

this.entityRepo
.infrastructure()
.userManager.inRole(ROLE_NAME, USER_TO_CHECK, (error, isInRole) => {}); //isInRole is a Boolean to check if successful or not.

Check Password

This method is used to confirm a user's password. Definition of this method is given as -

/**
* Check passwords match
* @param {String} domain User's domain
* @param {String} username Username
* @param {String} password Password to check in clear text
* @param {Function} fn Callback
*
*/
Infrastructure.prototype.checkPassword = function (
domain,
username,
password,
fn
) {};

Example using this method in a processor is given as -

this.entityRepo.infrastructure().userManager.checkPassword(DOMAIN_ID, USERNAME, PASSWORD_TO_CHECK, (error, isCorrectPassword)) {};

Change Password

This method is used to change a user's password. Definition of the method is given as -

/**
* Change the users password.
* @param {String} username Username
* @param {String} domain Domain of the user
* @param {String} password Current password
* @param {String} newPassword New password
* @param {Function} fn Callback
*
*/
Infrastructure.prototype.changePassword = function (
username,
domain,
password,
newPassword,
fn
) {};

Example using this method in a processor is given as -

this.entityRepo
.infrastructure()
.userManager.changePassword(
USERNAME,
DOMAIN_ID,
CURRENT_PASSWORD,
NEW_PASSWORD,
(error, result) => {}
);

Get Users By Param

This method is used to get users that fit a particular criteria. Definition for the method is given as -

/**
* Get users by param
* @param {Object} query Object
* @param {Function} fn Callback
*/
Infrastructure.prototype.getUsersByParam = function (query, fn) {};

Example using this method in a processor is given as -

let QUERY = {};
this.entityRepo
.infrastructure()
.userManager.getUsersByParam(QUERY, (error, users) => {});

Generate Scoped Token

This is used to generate a token that can only perform functionalities within a particular scope. Definition for this method is given as -

/**
* Generate Scoped Token
* @param {String} scope //scope for the token
* @param {Object} data //Data to generate the token for
* @param {Number} exp //TTL expiry in milliseconds
* /
Infrastructure.prototype.generateScopedToken = function (scope, data, exp) {};

Example using this method in a processor -

let DATA = {};
this.entityRepo
.infrastructure()
.userManager.generateScopedToken(SCOPE, DATA, TTL);

Verify Scoped Token

This method is used to verify a scoped token that has already been generated. It verifies if it is being used within the correct scope and by the right user. Definition for this method is given as -

/**
* Verify Scoped Token
* @param {String} scope
* @param {String} token
* /
Infrastructure.prototype.verifyScopedToken = function (scope, token) {};

Example using this method in a processor -

this.entityRepo.infrastrucure().userManager.verifyScopedToken(SCOPE, TOKEN);

Get Role

This method is used to get a role by its ID. Definition for this method is given as -

/**
* Retrieves a role by Id
* @param {String|ObjectId} id Role Id
* @param {Function} fn Callback
*
*/
Infrastructure.prototype.getRole = function (id, fn) {};

Example using this method in a processor -

this.entityRepo
.infrastructure()
.userManager.getRole(ROLE_ID, (error, role) => {});

Get User By Id

This method is used to get a particular user by it's ID. Definition for this method is given as -

/**
* Retrieves a user by id
* @param {String|ObjectId} id - User id
* @param {Function} fn Callback
*
*/
Infrastructure.prototype.getUserById = function (id, fn) {};

Example using this method in processors -

this.entityRepo
.infrastructure()
.userManager.getUserById(USER_ID, (error, user) => {});

Get Roles

This method is used to get roles that match a particular filter query. Definition of this method is given as -

/**
* Retrieves roles that match the query
* @param {Object} query Filter
* @param {Object} options Optional
* @param {Function} fn Callback
*
*/
Infrastructure.prototype.getRoles = function (query, options, fn) {};

Example using this method in a processor -

let QUERY = {};
this.entityRepo
.infrastructure()
.userManager.getRoles(QUERY, OPTIONS, (error, roles) => {});

// TODO Write documentation for Access Control Lists.