Develop a NetLogic for managing user accounts

This NetLogic contains methods for adding and removing users.
Prerequisites
Set the default external code editor. See Set the default code editor.
  1. In
    Project view
    , right-click the
    NetLogic
    folder and select
    New
    Runtime NetLogic
    .
  2. Hover-over the NetLogic, select
    Edit
    Edit
    , and enter
    UserManagementScript
    .
  3. Double-click the NetLogic.
    The external code editor opens.
  4. Edit the NetLogic code:
    1. Add the
      AddUser
      method:
      [ExportMethod] public void AddUser(string name, string password, string localeId) { // Get the current project folder. var currentProject = Project.Current; var securityFolder = currentProject.GetObject("Security"); var usersFolder = securityFolder.GetObject("Users"); // Check the password length. if (password.Length < 1) return; // Creating a new User and set its locale and password. var newUser = InformationModel.MakeObject<User>(name); Session.ChangePassword(name, password, string.Empty); newUser.LocaleId = localeId; if (usersFolder == null) { Log.Error("Add User", "Missing Users folder"); return; } usersFolder.Children.Add(newUser.NodeId); }
      The
      AddUser
      method takes the following parameters:
      name
      The name of the new user account.
      password
      The password of the new user account.
      localeId
      The locale of the user account. For example,
      en-US
      or
      it-IT
    2. Add the
      RemoveUser
      method:
      [ExportMethod] public void RemoveUser(string name) { // Get the current project folder. var currentProject = Project.Current; var securityFolder = currentProject.GetObject("Security"); var usersFolder = securityFolder.GetObject("Users"); if (usersFolder == null) { Log.Error("Add User", "Missing Users folder"); return; } if (usersFolder.Children.Count <= 0) { Log.Error("Users folder is Empty"); return; } // Remove the User by the name. usersFolder.Children.Remove(name); }
      The
      RemoveUser
      method takes the following parameter:
      name
      The name of the user account to remove.
  5. Save the code.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.