Account : Account information

更新时间:
2024-05-15
下载文档

Account : Account information

This module is EdgerOS account information acquisition module. Apps can use this module to acquire user information of specified account.

User can use the following code to import the account module.

var account = require('account');

Support

The following shows account module APIs available for each permissions.

 User ModePrivilege Mode
account.info
account.update
account.gpdate
account.mname
account.list
account.groups
account.remarks
account.set 
account.delete 

Account Object

account.info(acoid, callback)

  • acoid {String} Account id.
  • callback {Function} Callback function.
    • error {Error} Error message.
    • info {Object} Account information.

Get account information by acoid. If the error parameter of the callback function is undefined, the account information is valid, The account information object contains the following members:

  • acoid {String} Account id.
  • group {String} Account group name.
  • alias {String} Account alias name.
  • extra {Object} Account extra information.
groupDescription
'admin'Current device administrator group.
'user'Current device user group.
'guest'Guest group.

Example

account.info('xxx', function(error, info) {
  if (error) {
    console.error('This specified account does not exist on the current device!');
  } else if (info) {
    switch (info.group) {
    case 'admin':
      console.log(info.alias, 'is administrator!');
      break;
    case 'user':
      console.log(info.alias, 'is user!');
      break;
    case 'guest':
      console.log(info.alias, 'is guest!');
      break;
    }
  }
});

account.update(callback)

  • callback {Function} Callback function.
    • event {String} Account event.
    • acoid {String} Account id.

Registered account status change callback function. The following events may occur:

eventDescription
'add'Add a new account to the current device.
'delete'Remove an account from the current device.
'update'The specified account information changed.

Example

account.update(function(event, acoid) {
  // Perform different actions according to different events.
});

account.gpdate(callback)

  • callback {Function} Callback function.
    • event {String} Group event.
    • group {String} Group name.
    • previous {String} Group previous name. Only valid on 'update' event.

Registered group status change callback function. The following events may occur:

eventDescription
'add'Add a new group to the current device.
'delete'Remove an group from the current device.
'update'The specified group changed name.

Example

account.gpdate(function(event, group, previous) {
  // Perform different actions according to different events.
});

account.mname([mname[, callback]])

  • mname {String} New machine name.
  • callback {Function} Callback function.
    • error {Error} Error message.
    • mname {String} Current machine name.

Get or set current machine name.

Example

account.mname(undefined, function(error, mname) {
  if (!error) {
    console.log('Current machine name is:', mname);
  }
});

account.list(callback[, simple])

  • callback {Function} Callback function.
    • error {Error} Error message.
    • list {Array} Account list.
  • simple {Boolean} Whether only need acoid information. default: false.

Get the account list of the current machine.

Example

account.list(function(error, list) {
  if (error) {
    console.error('Can not list account!');
  } else {
    list.forEach(function(u) {
      // u.acoid, u.alias, u.group, u.extra
    });
  }
});

account.list(function(error, list) {
  if (error) {
    console.error('Can not list account!');
  } else {
    list.forEach(function(acoid) {
      // acoid
    });
  }
}, true);

Get account profile: In EdgerOS 2.0.0 and later versions, the account.list API will return account information contains extra attribute. For privilege app, extra contains full information, for non privilege app, extra only contains profile attribute. The developer can use the following code to display user profile in web page:

var profile = ......; // get profile from REST api
var { protocol, hostname } = window.location;
var addr = `${protocol}//${hostname}${profile}`; // build profile URL

var img = new Image();
img.src = addr;

This profile is cached by the current EdgerOS machine, which can be obtained offline, and EdgerOS will update the profile every time when user browse the account details.

account.groups(callback)

  • callback {Function} Callback function.
    • error {Error} Error message.
    • list {Array} Group name list.

Get the group list of the current machine. App developers can use the account.list and account.groups functions to implement more refined permission management within the app.

Example

account.groups(function(error, list) {
  console.log('groups:', list);
});

account.remarks(acoid, callback)

  • acoid {String} Account id.
  • callback {Function} Callback function.
    • error {Error} Error message.
    • list {Array} Remarks list.

Get the specified user's remarks setting of other users in current machine. This function is available on EdgerOS 1.10.2 and above.

Each object in the returned array contains the following members:

  • acoid {String} Account id.
  • remark {String} Account remark.

account.set(acoid, alias, group[, extra[, callback]])

  • acoid {String} Account id.
  • group {String} Account group name.
  • alias {String} Account alias name.
  • extra {Object} Account extra information. default: {}.
  • callback {Function} Callback function.
    • error {Error} Error message.

Update or add an account information to the current device. group can only be 'admin' or 'user'.

Example

account.set(acoid, '张三', 'user');

account.delete(acoid[, callback])

  • acoid {String} Account id.
  • callback {Function} Callback function.
    • error {Error} Error message.

Delete an account in the current device.

Example

account.delete(acoid);
文档内容是否对您有所帮助?
有帮助
没帮助