Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Latest commit

 

History

History
63 lines (47 loc) · 5.83 KB

File metadata and controls

63 lines (47 loc) · 5.83 KB

API and Usage Reference

Functions

createInstance([config])

Returns a new instance of Scurvy with config options applied if specified. Synchronous.

config object fields:

  • showTrace - Enables internal trace logging to console.log. A boolean value for debug and development purposes. Defaults to false.

- `authSchema` - Choose a standard method of login. When this String value is changed in an existing installation, the assumed table structure will change -- resulting in the need to alter or drop/recreate tables. It is suggested to pick the one that suits you best and stick with your choice. `authSchema` can be set to one of the following modes: - `'userid'` - Uses a userid field as the login name. Also includes an email address field. Default value. - `'email'` - Uses the user's email address as the login name.

loadModels(hook)

Loads all scurvy models into the provided hook object. Call this once after initializing a scurvy instance. The provided hook object must contain a field sequelize which is an instantiation of a new Sequelize(...) object. Synchronous.

setupAssociations(hook)

Sets up the primary-key/foreign-key relationships of the scurvy models. Call this once after calling the above loadModels() with the same hook. Synchronous.

setupSync(hook, callback, [syncParams])

Creates the User and Metastate tables if they don't already exist. Call this once after calling the above setupAssociations() with the same hook. The callback is called after completion with method signature callback(err, successful), where successful is true when the operation completed successfully. syncParams is an optional parameter passed in to the Sequelize table creation .sync() function. See http://sequelizejs.com/documentation#models-database-synchronization . Asynchronous.

generateNewHash(input, callback)

Creates a 60 character hash and 29 character salt from input. Calls callback when complete with method signature function (err, result). err is null when there is no error. result is an object with two fields salt and hash that are created by the hashing algorithm. Asynchronous.

comparePlaintextToHash(inputPassword, hash, callback)

Takes an inputPassword and hash that was created with generateNewHash() (where inputPassword was the input) and returns a callback with method signature function(err, matches) where err is null when there is no error, and matches is true if the parameters validate. Asynchronous.

setRounds(rounds)

Optional function. Internally, rounds defaults to 10. rounds must be an integer > 0. Synchronous.

generateMetastateHashkey(email, salt, callback)

Generates a metastate hash based off of the provided email and salt. The salt is intended to be the same which hashes the user's password. The resultant hashkey is passed to the callback with method signature callback(err, result) and can be used for an account confirmation URL (or other ways of identifying the account with a hash). If err is null, the result object will include a field: hashkey. Asynchronous.

doesMetastateHashkeyHaveUser(hashkey, callback)

Checks the database to see if a User with a status of inactive exists for a given hashkey. The callback is fired when the query is complete with method signature callback(err, result) where result is false if the match does not exist, otherwise it will be an object with fields containing the sequelize objects of the found user: { user: user, metastate: metastate }. Asynchronous.

validateMetastateHashkey(hashkey, email, callback)

Checks to see if a given hashkey was generated by a particular email. If the hashkey was generated by the email, the callback(err, validates) will have a null err and validates will be true. Else, validates will be false. Asynchronous.

createUser(params, callback)

Creates a user with given params. Required fields for params include: userid, email, passwrd, and status. If authSchema is set to email, do not pass the userid field as it is not used in this configuration. status must be either 'active', 'inactive', or 'deleted'. If left blank, status will default to inactive. Upon completion, callback will be called with method signature callback(err, result) where result will be an object containing sequelize object references to the newly created user and metastate if err is null. Asynchronous.

activateUser(input, callback)

Takes a sequelize object reference of a User instance that has a property input.metastate and sets the status property to active. The callback function is fired with method signature callback(err, successful), and successful is true when the user was successfully updated. Asynchronous.

verifyCredentials(input, callback)

Checks the database to see if the given input credentials are valid for an existing user, and returns the user. The input object requires different credential parameters depending on the configuration -- if authSchema is set to userid, pass in the object like: { userid 'theuserid', passwrd: 'thepassword' } and if authSchema is set to email, pass in the object like: { email 'theemail@domain.com', passwrd: 'thepassword' }. To retrieve custom user-associated objects from the database, an array of sequelize models can be passed into input.include. The returned user object from the callback will include these objects if they exist. The callback is called with method signature callback(err, user) where the user will be a valid retrieved User object if the input credentials are valid, else it will be false.