Members
(constant) con
Creates connection object for db connectivity.
- Source:
Methods
buildPermissionToggles(userPerms) → {Array}
Takes an object of user permissions, and will build an array based on what permissions they have already or not for the toggles on the profile page
Parameters:
| Name | Type | Description |
|---|---|---|
userPerms |
Object |
- Source:
Returns:
- Type
- Array
buildProfileFormData(user, overrides) → {Object}
Takes in a user object and another optional object, should that optional object exist and have relevant values then it will choose those values over the ones initially provided.
By doing this, even if there is an error or change in the data submitted from the HTML form and there are values missing, it will still be able to populate the form.
Parameters:
| Name | Type | Description |
|---|---|---|
user |
Object | |
overrides |
Object |
- Source:
Returns:
- Type
- Object
decimalToBinary(N, length) → {Array}
Convert a decimal number to a binary array, optionally padded to a certain length
Generated by github copilot
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
N |
* | the denary value to be converted | |
length |
* | 0 |
- Source:
Returns:
array of binary digits as strings
- Type
- Array
decodePermissionBitmask(bitmask) → {Object}
Decode a permission bitmask integer into an object of permission names and boolean values
Parameters:
| Name | Type | Description |
|---|---|---|
bitmask |
Integer |
- Source:
Returns:
object of permission names and boolean values
- Type
- Object
encodePermissionBitmask(permissions) → {Integer}
Encode an array of permission names into a bitmask integer
Parameters:
| Name | Type | Description |
|---|---|---|
permissions |
Array |
- Source:
Returns:
value of permission bitmask
- Type
- Integer
getUserData(userID, cb)
Takes a userID and returns the user data from the database corresponding to that userID.
Returns first value as a boolean, false indicating failure, true indicating success.
The second value is either the the error data if it failed or the requested data if it succeeded.
Filters out so only selected data will be returned, password hash is not included.
Parameters:
| Name | Type | Description |
|---|---|---|
userID |
string | |
cb |
function |
- Source:
hasPermissions(requiredPerms, logicType) → {function}
Checks if the user has the nessecary permissions to access a route, it is customisable such that you can specify an array of permissions that they can, and you can then specify if they need all of those permissions "AND" operating mode or "OR" operating mode if they only need one of them.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
requiredPerms |
Array | ||
logicType |
String | AND |
- Source:
Returns:
- Type
- function
hasPermissions(requiredPerms, userPerms, logicType) → {Boolean}
Back end logic to check if a user's provided permissions meet the requirements specified. Contains the logic for both "AND" and "OR" operations as well as universal access for admins.
Will accept either an Integer bitmask or a decoded permissions object.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
requiredPerms |
Array | ||
userPerms |
Object | Can also be an integer value | |
logicType |
String | AND | "AND" or "OR" |
- Source:
Returns:
- Type
- Boolean
hashPassword(password) → {String}
Hashes a password using the scrypt algorithm with a random salt, returning the combined salt and hash for storage
Parameters:
| Name | Type | Description |
|---|---|---|
password |
String |
- Source:
Returns:
Salt and Hash
- Type
- String
isAuthorised(req, res, next)
Checks if the user is authenticated by passport.js, if they aren't it directs them to log in.
Parameters:
| Name | Type | Description |
|---|---|---|
req |
Object | |
res |
Object | |
next |
function |
- Source:
isFutureDateTime(input) → {boolean}
Checks if the provided date time string is in the future compared to today or not.
Parameters:
| Name | Type | Description |
|---|---|---|
input |
string |
- Source:
Returns:
- Type
- boolean
isValidDateTime(input) → {boolean}
Returns true or false boolean values depending on if it is valid or not
Parameters:
| Name | Type | Description |
|---|---|---|
input |
string |
- Source:
Returns:
- Type
- boolean
isValidEmail(email) → {boolean}
Simple regex to check if the email is in a valid format
Parameters:
| Name | Type | Description |
|---|---|---|
email |
string |
- Source:
Returns:
- Type
- boolean
isValidPassword(password) → {boolean}
Check if the password is at least 8 characters long and contains at least one uppercase letter, one lowercase letter, and one number
Parameters:
| Name | Type | Description |
|---|---|---|
password |
string |
- Source:
Returns:
- Type
- boolean
isValidUsername(username) → {boolean}
Check if the username is between 3 and 20 characters and contains only alphanumeric characters and underscores
Parameters:
| Name | Type | Description |
|---|---|---|
username |
string |
- Source:
Returns:
- Type
- boolean
sanitiseInput(input) → {string}
Remove any potentially harmful characters from the input
Parameters:
| Name | Type | Description |
|---|---|---|
input |
string |
- Source:
Returns:
- Type
- string
verifyPassword(password, storedPassword) → {Boolean}
Verifies a password by hashing it with the same salt and comparing it to the stored hash
Parameters:
| Name | Type | Description |
|---|---|---|
password |
String | |
storedPassword |
String |
- Source:
Returns:
- Type
- Boolean