Benutzer hinzufügen

const { EncryptWithPassword, EncryptWithPublicKey } = require('../node/lib/MtoEncryption');
const { MtoPbkdf2GenerateSalt } = require('../node/lib/MtoPbkdf2');
const MtoRsa = require('../node/lib/MtoRsa');

const createUser = async (api, username, password, parentId) => {
  const encodedPassword = unescape(encodeURIComponent(password))
  const pwHash = MtoPbkdf2GenerateSalt(encodedPassword, 16, 100000, 32)
  const rsa = new MtoRsa()
  rsa.generateKeyPair()
  const encryptedPrivateKeyWithPassword = EncryptWithPassword(encodedPassword, rsa.privateKeyToXml())

  // Membership of current API user
  const currentUserRsa = new MtoRsa()
  currentUserRsa.publicKeyFromXml(api.currentUser.PublicKey)
  const encryptedPrivateKeyWithPublicKey = EncryptWithPublicKey(currentUserRsa, rsa.privateKeyToXml())

  const user = {
    UserName: username
  }

  await api.organisationUnitManager.addOrganisationUnitUser(
    user,
    pwHash.key,
    pwHash.salt,
    rsa.publicKeyToXml(),
    encryptedPrivateKeyWithPassword,
    encryptedPrivateKeyWithPublicKey,
    parentId
  )
}

Tag hinzufügen

// Data may be any PsrData like PsrContainer, PsrRole, PsrOrganisationUnitUser …
const addTag = async (api, data, tagId) => {
  const dataTags = data.DataTags
  dataTags.push({
    DataId: data.Id,
    TagId: tagId
  })

  await api.tagManager.setDataTags(dataTags, data.Id)
}

Was this helpful?

Yes No
You indicated this topic was not helpful to you ...
Could you please leave a comment telling us why? Thank you!
Thanks for your feedback.