JSMA customers
Overview
The JSMA customers provides access to the customers (JSMA customer) in the instance.
What can JSMA customers do for me?
You can use the JSMA customers to access and manipulate customers in the database
Index
Usage
writing data
Here is an example on how to write data to a JSMA customers:
... customers.each(function(customer) { customer.setConfirmed(true); }); ...
reading data
Here is an example on how to read data from a JSMA customers:
... customers.findByLoginName('Alice1980') // => customer ...
Methods
The JSMA customers provides the following methods:
customer customers.current
Returns the current logged in customer for the request as a JSMA customer if available.
Example
... customers.current // => customer ...
void customers.each(fun)
Executes the given function on every customer in the database.
Example
... customers.each(function(customer) { customer.setConfirmed(true); }); ...
Parameter fun:function (required)
A function to be called on each JSMA customer.
customer[] customers.find(query, [options={}])
The function signature customers.find(query, [limit]) is deprecated and will produce a warning in log files.
Searches and retrieves a list of JSMA customer from the Sphinx index.
Example
... customers.find('alice') // => [customer0, customer1, ...] ...
Parameter query:string (required)
Parameter options:object (optional)
If no value for limit is provided, the default value of 10 will be used.
customer customers.findById(id)
Retrieves a single JSMA customer from the database by id.
Avoid usage of findById
Ids change whenever a package is reimported. So please avoid using ids whenever possible. Also delivering contents to users by id might make it possible for users to flip through the files (and by that see contents of others possibly) by changing the ids in requests.
Example
... customers.findById(1) // => customer ...
Parameter id:int (required)
customer customers.findByLoginName(login)
Retrieves a single JSMA customer from the database by loginName.
Example
... customers.findByLoginName('Alice1980') // => customer ...
Parameter login:string (required)
bool customers.loggedIn
Returns true or false whether there is a currently logged in customer in the context of execution.
Example
... customers.loggedIn // => false ...
customer customers.login(name, password)
Logs in a customer by name and password.
Returns the JSMA customer if successful.
Example
... customers.login('alice', 'alices password'); // => customer ...
Parameter name:string (required)
Parameter password:string (required)
customers.logout()
Logs out the current customer.
Example
... customers.logout() ...
customer customers.register(login, password, display_name, portal, [email])
Registers a new customer and returns it as a JSMA customer.
Example
... customers.register('login', 'password', 'display_name', portal, 'info@example.org') // => customer ...
Parameter login:string (required)
Parameter password:string (required)
Parameter display_name:string (required)
Parameter portal:portal (required)
Either a JSMA portal or the id of a portal.
Parameter email:string (optional)
customers.request
The current JSMA request.
Example
... customers.request // => request ...
customers.session
The current JSMA session.
Example
... customers.session // => session ...