JSMA users

Overview

The JSMA users provides functionality for accessing users. User can log-in to the IFE in contrast to customers that cannot log-in to the IFE.

What can JSMA users do for me?

You could easily use the JSMA users to get information about the current user

Index

Usage

reading data

Here is an example on how to read data from a JSMA users:

...
users.findByName('alice'); // => user
...

Methods

The JSMA users provides the following methods:

user users.current()

Returns a JSMA user for the current logged in user, if available.

Example

...
var user = users.current();
if (user === null)
{
   return createStandardResult("user.notLoggedIn");
}
...

user users.findById(id)

Returns a JSMA user when a user is found for the given 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

...
var user = users.findById(27); // => user
...

Parameter id (required)

The user id for the lookup.

user users.findByName(name)

Returns a JSMA user when a user is found for the given name.

Example

...
var user = users.findByName('alice'); // => user
...

Parameter name (required)

The user name for the lookup.

users.impersonate(UserJsma user, Function fun)

Executes the given function "fun" under the given user "user".

Example

...
users.impersonate(editUser, function() {
	    // Execute code as the user. E.g. create a slice, add a file and commit the slice.

        var slice = slices.create({ name: message });
        slice.switch();
        
        files.create({ file: request.parameter('file'), type: 'admin_upload', package: someNamespace.id });

        slice.commit(message);
});
...

Parameter user (required)

The user under which the function should be executed

Parameter fun (required)

The function that should be executed.