Docly

How to create a user ?

Estimated reading: 2 minutes 33 views

Create Visual-Guard user

VGMembershipCreateStatus createStatus; 

//Create VisualGuard user with all informations
VGMembershipUser jsmithUser = runtime.Membership.CreateUser(“jsmith”, “pwd”, “jsmith@xyz.com”, string.Empty, string.Empty, true, “user description”, “John”, “Smith”, out createStatus); 

//Easy creation of the user
VGMembershipUser tempUser = runtime.Membership.CreateUser(“mytestuser”, “pwd”);

Create Window account user

// Get all domains define your VGRepository
var domains = runtime.Domains.GetAllActiveDirectoryDomains(); 

// Set one domain
var selectedDomain = domains[0]; 
//provide the domain in which the window account need to be created 
//Create windows account 
VGMembershipUser windowUser = runtime.Membership.CreateActiveDirectoryUser(selectedDomain, @”novalys\firstuser”, “pwd”, null,out createStatus);

Create Database account user

VGMembershipCreateStatus createStatus; 
//Create Database account 
VGMembershipUser dbUser= runtime.Membership.AddDBUser(new VGDBUser(“sa”), out createStatus);

How to manage the creation status ?

if (createStatus == VGMembershipCreateStatus.Success)
{
  //user creation is successful
  //write your code 
}
else
{
  switch (createStatus)
  {
      case VGMembershipCreateStatus.DuplicateUserName:
          //User is not created as username already exists
          break;

      case VGMembershipCreateStatus.DuplicateEmail:
          //User is not created as user with same email address already exist
          break;

      case VGMembershipCreateStatus.TooManyUsers:
          //User is not created as user count has been reached to maximum as per license.
          break;

      case VGMembershipCreateStatus.InvalidComment:
          //User is not created as invalid comments
          break;

      case VGMembershipCreateStatus.InvalidEmail:
          //User is not created due to invalid emailaddress
          break;

      case VGMembershipCreateStatus.InvalidPassword:
          //User is not created due to invalid password
          break;

      case VGMembershipCreateStatus.InvalidQuestion:
          //User is not created due to invalid question                        
          break;

      case VGMembershipCreateStatus.InvalidAnswer:
          //User is not created as invalid answer
          break;


      case VGMembershipCreateStatus.InvalidUserName:
          //User is not created as username is invalid
          break;

      case VGMembershipCreateStatus.InvalidWindowsAccount:
          //User is not created due to invalid window account
          break;

      case VGMembershipCreateStatus.UserRejected:
          //User creation is rejected
          break;

      case VGMembershipCreateStatus.ProviderError:
          //User is not created as there is some issue in identity module
          break;

      default:
          break;

  }
}

Leave a Comment

Share this Doc
CONTENTS