Allowing username duplicates

Tags: 442 views 6

How to configure the URLs to allow users to have the same username.

Useful tip

Allowing username duplicates is helpful if you have several brands set up in Atomia.

Before you begin

To enable this feature, see Configuring reseller root domains.

Configuring Identity

  1. Locate the STS\Web.config file, usually located in C:\Program Files (x86)\Atomia\Identity\STS.
  2. Set <add key="UniqueUserMultipleReseller" value="false" /> to true.
  3. Locate the <membership> section in the configuration and add the following element to each extra reseller root domain.
  4.   <add name="reseller2.com" connectionStringName="UserManagementConectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="reseller2.com" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="10" minRequiredPasswordLength="3" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    

Keep in mind

Remember to change reseller2.com to your reseller root domain. Both the name and applicationName attributes has to be changed.

  1. Locate the <roleManager> section in the configuration and add the following element.
  2.   <add connectionStringName="UserManagementConectionString" applicationName="reseller2.com" name="reseller2.com" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    
  3. Locate the UserAPI\web.config file, usually located in C:\Program Files (x86)\Atomia\Identity\UserAPI.
  4. Repeat the above steps for the STS configuration.

Configuring account API and Billing API

  1. Locate the AccountAPI\Web.config file usually located in C:\Program Files (x86)\Atomia\BillingAPIs\AccountApi.
  2. Locate the BillingApi\Web.config file usually located in C:\Program Files (x86)\Atomia\BillingAPIs\BillingApi.
  3. Set <add key="UniqueUserMultipleReseller" value="false" /> to true.
  4. Add a new key for each extra reseller root domain. Don’t add the key for the domain that you have been using for your main installation.
  5.   <add key="reseller2.com" value="true" />
    

Configuring the Automation Server

  1. Locate the web.config in C:\Program Files (x86)\Atomia\AutomationServer\Web.
  2. Set <add key="UniqueUserMultipleReseller" value="false" /> to true.

Configuring the Billing Customer Panel and Hosting Control Panel

  1. Locate the appConfig.config file in C:\Program Files (x86)\Atomia\BillingCustomerPanel\App_Data.
  2. Set <add key="UniqueUserMultipleReseller" value="false" /> to true.
  3. Locate the appConfig.config file in C:\Program Files (x86)\Atomia\HostingControlPanel\App_Data.
  4. Set <add key="UniqueUserMultipleReseller" value="false" /> to true.

Database changes

  1. Start SQL Server Management Studio and execute the following query.
  2.   insert into AtomiaUserManagement.dbo.aspnet_Applications
      (ApplicationName, LoweredApplicationName, ApplicationId)
      values ('reseller2.com', 'reseller2.com', NEWID())
    

Keep in mind

Remember to replace reseller2.com with the domain you are using for your reseller.

  1. To migrate existing users, modify the following SQL script to fit your needs.
  2.  -- Variables
      DECLARE @current_application_id UNIQUEIDENTIFIER
      DECLARE @new_application_id UNIQUEIDENTIFIER
      DECLARE @user_id UNIQUEIDENTIFIER
      DECLARE @current_reseller_root_domain NVARCHAR(255)
      DECLARE @new_reseller_root_domain NVARCHAR(255)
      DECLARE @name NVARCHAR(255)
      DECLARE @username NVARCHAR(255)
      DECLARE @accounts TABLE(name NVARCHAR(255))
      DECLARE @usernames TABLE (username NVARCHAR(255))
    
      -- The reseller root domain that the users have right now, before migration. If you are migrating from the default reseller/root domain this should be NULL
      SET @current_reseller_root_domain = NULL
    
      -- The reseller root domain that the users should have after migration
      SET @new_reseller_root_domain = 'reseller2.com'
    
      -- List of accounts that should be migrated
      INSERT INTO @accounts VALUES('100130')
      INSERT INTO @accounts VALUES('100131')
    
      --
      -- Nothing below this line should have to be changed
      --
    
      -- Let's create new application if it doesn't exist
      IF @new_reseller_root_domain IS NOT NULL AND NOT EXISTS (SELECT 1 FROM AtomiaUserManagement.dbo.aspnet_Applications WHERE ApplicationName = @new_reseller_root_domain)
      BEGIN
          INSERT INTO AtomiaUserManagement.dbo.aspnet_Applications
          (ApplicationId, ApplicationName, Description, LoweredApplicationName)
          VALUES(NEWID(), @new_reseller_root_domain, @new_reseller_root_domain, @new_reseller_root_domain)
      END
    
      -- Get current application id
      IF @current_reseller_root_domain IS NULL
      BEGIN
          SELECT @current_application_id = ApplicationId
          FROM AtomiaUserManagement.dbo.aspnet_Applications
          WHERE ApplicationName = 'AtomiaIdentityStS'
      END
      ELSE
      BEGIN
          SELECT @current_application_id = ApplicationId
          FROM AtomiaUserManagement.dbo.aspnet_Applications
          WHERE ApplicationName = @current_reseller_root_domain
      END
    
      -- Get new application id
      IF @new_reseller_root_domain IS NULL
      BEGIN
          SELECT @new_application_id = ApplicationId
          FROM AtomiaUserManagement.dbo.aspnet_Applications
          WHERE ApplicationName = 'AtomiaIdentityStS'
      END
      ELSE
      BEGIN
          SELECT @new_application_id = ApplicationId
          FROM AtomiaUserManagement.dbo.aspnet_Applications
          WHERE ApplicationName = @new_reseller_root_domain
      END
    
      -- Make sure the application has all the needed roles
      IF NOT EXISTS (SELECT 1 FROM AtomiaUserManagement.dbo.aspnet_Roles WHERE ApplicationId = @new_application_id AND RoleName = 'AccountOwner')
      BEGIN
          INSERT INTO AtomiaUserManagement.dbo.aspnet_Roles (ApplicationId, RoleId, RoleName, LoweredRoleName)
          VALUES (@new_application_id, NEWID(), 'AccountOwner', 'accountowner')
      END
    
      IF NOT EXISTS (SELECT 1 FROM AtomiaUserManagement.dbo.aspnet_Roles WHERE ApplicationId = @new_application_id AND RoleName = 'AccountUser')
      BEGIN
          INSERT INTO AtomiaUserManagement.dbo.aspnet_Roles (ApplicationId, RoleId, RoleName, LoweredRoleName)
          VALUES (@new_application_id, NEWID(), 'AccountUser', 'accountuser')
      END
    
      IF NOT EXISTS (SELECT 1 FROM AtomiaUserManagement.dbo.aspnet_Roles WHERE ApplicationId = @new_application_id AND RoleName = 'Administrators')
      BEGIN
          INSERT INTO AtomiaUserManagement.dbo.aspnet_Roles (ApplicationId, RoleId, RoleName, LoweredRoleName)
          VALUES (@new_application_id, NEWID(), 'Administrators', 'administrators')
      END
    
      IF NOT EXISTS (SELECT 1 FROM AtomiaUserManagement.dbo.aspnet_Roles WHERE ApplicationId = @new_application_id AND RoleName = 'Reseller')
      BEGIN
          INSERT INTO AtomiaUserManagement.dbo.aspnet_Roles (ApplicationId, RoleId, RoleName, LoweredRoleName)
          VALUES (@new_application_id, NEWID(), 'Reseller', 'reseller')
      END
    
      -- Get all usernames for the accounts
      DECLARE cur CURSOR FOR
      SELECT name
      FROM @accounts
    
      OPEN cur
      FETCH NEXT FROM cur INTO @name
    
      WHILE (@@FETCH_STATUS = 0)
      BEGIN
          -- Store users for the account name in the usernames table
          INSERT INTO @usernames
          SELECT l.username
          FROM AtomiaAccount.dbo.account a
          INNER JOIN AtomiaAccount.dbo.login l ON l.fk_account_id = a.id
          WHERE a.name = @name
    
          FETCH NEXT FROM cur INTO @name
      END
    
      CLOSE cur
      DEALLOCATE cur
    
      -- Iterate over the usernames
      DECLARE cur CURSOR FOR
      SELECT username
      FROM @usernames
    
      OPEN cur
      FETCH NEXT FROM cur INTO @username
    
      WHILE (@@FETCH_STATUS = 0)
      BEGIN
          -- Set reseller root domain in the login table
          print 'Set reseller root domain in the login table'
          IF @current_reseller_root_domain IS NULL
          BEGIN
              UPDATE AtomiaAccount.dbo.login
              SET reseller_root_domain = @new_reseller_root_domain
              WHERE username = @username AND (reseller_root_domain IS NULL OR reseller_root_domain = '')
          END
          ELSE
          BEGIN
              UPDATE AtomiaAccount.dbo.login
              SET reseller_root_domain = @new_reseller_root_domain
              WHERE username = @username AND reseller_root_domain = @current_reseller_root_domain
          END
    
          -- Set identity properties
          print 'Set identity properties'
          IF @current_reseller_root_domain IS NULL
          BEGIN
              UPDATE AtomiaIdentity.dbo.identity_properties
              SET value = @new_reseller_root_domain
              WHERE username = @username AND (reseller_root_domain IS NULL OR reseller_root_domain = '') AND property = 'resellerRootDomain'
    
              UPDATE AtomiaIdentity.dbo.identity_properties
              SET reseller_root_domain = @new_reseller_root_domain
              WHERE username = @username AND (reseller_root_domain IS NULL OR reseller_root_domain = '')
          END
          ELSE
          BEGIN
              UPDATE AtomiaIdentity.dbo.identity_properties
              SET value = @new_reseller_root_domain
              WHERE username = @username AND reseller_root_domain = @current_reseller_root_domain AND property = 'resellerRootDomain'
    
              UPDATE AtomiaIdentity.dbo.identity_properties
              SET reseller_root_domain = @new_reseller_root_domain
              WHERE username = @username AND reseller_root_domain = @current_reseller_root_domain
          END
    
          -- Get user id for the username
          print 'Get user id for the username'
          SELECT @user_id = UserId
          FROM AtomiaUserManagement.dbo.aspnet_Users
          WHERE UserName = @username AND ApplicationId = @current_application_id
    
          -- Change application id for the user
          print 'Change application id for the user'
          UPDATE AtomiaUserManagement.dbo.aspnet_Users
          SET ApplicationId = @new_application_id
          WHERE UserId = @user_id
    
          UPDATE AtomiaUserManagement.dbo.aspnet_Membership
          SET ApplicationId = @new_application_id
          WHERE UserId = @user_id
    
          -- Change roles for the user
          print 'Change roles for the user'
          UPDATE uir
          SET uir.RoleId = nr.RoleId
          FROM AtomiaUserManagement.dbo.aspnet_UsersInRoles uir
          INNER JOIN AtomiaUserManagement.dbo.aspnet_Roles cr ON cr.RoleId = uir.RoleId
          INNER JOIN AtomiaUserManagement.dbo.aspnet_Roles nr ON nr.RoleName = cr.RoleName AND nr.ApplicationId = @new_application_id
          WHERE uir.UserId = @user_id
    
          FETCH NEXT FROM cur INTO @username
      END
    
      CLOSE cur
      DEALLOCATE cur
    

Was this helpful?