Namespace: User

User

Model for user accounts. Note that unlike the linked UserMeta model, this table is not versioned.

Source:

Methods

(protected, static) _containsOnlyLegalCharacters(name) → {Boolean}

Parameters:
Name Type Description
name String

username to validate

Source:
Throws:

if user name contains invalid characters

Type
NewUserError
Returns:

true if username contains illegal characters

Type
Boolean

(static) canonicalize(name) → {String}

Transform a user name to its canonical internal form (upper case), used for duplicate checking.

Parameters:
Name Type Description
name String

name to transform

Source:
Returns:

canoncial form

Type
String

(async, static) create(userObj) → {User}

Create a new user from an object containing the user data. Hashes the password, checks for uniqueness, validates. Saves.

Parameters:
Name Type Description
userObj Object

plain object containing data supported by this model

Source:
Throws:

if user exists, password is too short, or there are other validation problems.

Type
NewUserError
Returns:

the created user

Type
User

(async, static) createBio(user, bioObj) → {User}

Associate a new bio text with a given user and save both

Parameters:
Name Type Description
user User

user object to associate the bio with

bioObj Object

plain object with data conforming to UserMeta schema

Source:
Returns:

updated user

Type
User

(async, static) ensureUnique(name) → {Boolean}

Throw if we already have a user with this name.

Parameters:
Name Type Description
name String

username to check

Source:
Throws:

if exists

Type
NewUserError
Returns:

true if unique

Type
Boolean

(async, static) findByURLName(name, optionsopt) → {User}

Find a user by the urldecoded URL name (spaces replaced with underscores)

Parameters:
Name Type Attributes Description
name String

decoded URL name

options Object <optional>

query criteria

Properties
Name Type Default Description
withPassword Boolean false

if false, password will be filtered from result. Subsequent save() calls will throw an error

withData Boolean false

if true, the associated user-metadata object will be joined to the user

withTeams Boolean false

if true, the associated teams will be joined to the user

Source:
Throws:

if not found

Type
ThinkyError
Returns:

the matching user object

Type
User

(static) getWithTeams(id) → {Query}

Obtain user and all associated teams

Parameters:
Name Type Description
id String

user ID to look up

Source:
Returns:
Type
Query

(async, static) increaseInviteLinkCount(id) → {Number}

Increase the invite link count by 1 for a given user

Parameters:
Name Type Description
id String

unique ID of the user

Source:
Returns:

updated invite count

Type
Number

checkPassword(password) → {Promise}

Check this user's password hash against a provided plain text password.

Parameters:
Name Type Description
password String

plain text password

Source:
Returns:

promise that resolves true/false, or rejects if bcrypt library returns an error.

Type
Promise

getValidPreferences() → {Array.<String>}

Which preferences can be toggled via the API for/by this user? May be restricted in future based on access control limits.

Source:
Returns:

array of preference names

Type
Array.<String>

populateUserInfo(user)

Determine what the provided user (typically the currently logged in user) may do with the data associated with this User object, and populate its permission fields accordingly.

Parameters:
Name Type Description
user User

user whose permissions on this User object we want to determine

Source:

setName(displayName)

Updates display name, canonical name (used for duplicate checks) and derived representations such as URL name. Does not save.

Parameters:
Name Type Description
displayName String

the new display name for this user (must not contain illegal characters)

Source:

setPassword(password) → {Promise}

Update a password hash based on a plain text password. Does not save.

Parameters:
Name Type Description
password String

plain text password

Source:
Returns:

promise that resolves to password hashed via bcrpyt algorithm. Rejects with NewUserError if the password is too short, or if bcrypt library returns an error.

Type
Promise