/// <summary> /// Creates and then sets the current user to a new identity user account. /// </summary> /// <param name="userName">The username for the new account</param> /// <param name="password">The password for the new account</param> /// <param name="displayname">The display name for the new account</param> /// <param name="email">The email address for the account</param> /// <param name="dateOfBirth">The date of birth for the user. Format "1989-12-31"</param> /// <param name="policy">The policy you want to create the account under</param> /// <param name="siteid">The site that you want to create them in</param> /// <param name="userType">The type of user you want to create</param> /// <returns>True if the user was created correctly, false if not</returns> public bool SetCurrentUserAsNewIdentityUser(string userName, string password, string displayname, string email, string dateOfBirth, TestUserCreator.IdentityPolicies policy, int siteid, TestUserCreator.UserType userType) { // Set the identity glag to true. Obvious if we're wanting to create identity users _useIdentity = true; Cookie cookie; Cookie secureCookie; if (userType == TestUserCreator.UserType.Normal) { if (!TestUserCreator.CreateNewIdentityNormalUser(userName, password, dateOfBirth, email, displayname, true, policy, true, out cookie, out secureCookie, out _identityuserid, out _userid)) { return false; } } else if (userType == TestUserCreator.UserType.Editor) { if (!TestUserCreator.CreateNewIdentityEditorUser(userName, password, dateOfBirth, email, displayname, siteid, policy, out cookie, out secureCookie, out _identityuserid, out _userid)) { return false; } } else if (userType == TestUserCreator.UserType.SuperUser) { if (!TestUserCreator.CreateNewIdentitySuperUser(userName, password, dateOfBirth, email, displayname, policy, out cookie, out secureCookie, out _identityuserid, out _userid)) { return false; } } else if (userType == TestUserCreator.UserType.Moderator) { if (!TestUserCreator.CreateNewIdentityModeratorUser(userName, password, dateOfBirth, email, displayname, siteid, policy, out cookie, out secureCookie, out _identityuserid, out _userid)) { return false; } } else if (userType == TestUserCreator.UserType.Notable) { if (!TestUserCreator.CreateNewIdentityNotableUser(userName, password, dateOfBirth, email, displayname, siteid, policy, out cookie, out secureCookie, out _identityuserid, out _userid)) { return false; } } /* * else if (userType == TestUserCreator.UserType.Scout) { if (!TestUserCreator.CreateNewIdentityScoutUser(userName, password, dateOfBirth, email, displayname, siteid, policy, out cookie, out secureCookie, out _identityuserid, out _userid)) { return false; } } */ else if (userType == TestUserCreator.UserType.IdentityOnly) { if (!TestUserCreator.CreateIdentityUser(userName, password, dateOfBirth, email, displayname, true, policy, true, 0, out cookie, out secureCookie, out _identityuserid)) { return false; } _useDebugIdentityUser = false; } else { return false; } _cookie = HttpUtility.UrlEncode(cookie.Value); _secureCookie = HttpUtility.UrlEncode(secureCookie.Value); _userName = userName; _password = password; _useIdentity = true; return true; }
/// <summary> /// Creates and then sets the current user to a new identity user account. /// </summary> /// <param name="userName">The username for the new account</param> /// <param name="password">The password for the new account</param> /// <param name="displayname">The display name for the new account</param> /// <param name="email">The email address for the account</param> /// <param name="dateOfBirth">The date of birth for the user. Format "1989-12-31"</param> /// <param name="policy">The policy you want to create the account under</param> /// <param name="sitename">The site that you want to create them in</param> /// <param name="userType">The type of user you want to create</param> /// <returns>True if the user was created correctly, false if not</returns> public bool SetCurrentUserAsNewIdentityUser(string userName, string password, string displayname, string email, string dateOfBirth, TestUserCreator.IdentityPolicies policy, string sitename, TestUserCreator.UserType userType) { int siteid = 0; IInputContext context = DnaMockery.CreateDatabaseInputContext(); using (IDnaDataReader reader = context.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("SELECT SiteID FROM dbo.Sites WHERE UrlName='" + sitename + "'"); if (!reader.HasRows || !reader.Read()) { return false; } siteid = reader.GetInt32NullAsZero("siteid"); } return siteid > 0 && SetCurrentUserAsNewIdentityUser(userName, password, displayname, email, dateOfBirth, policy, siteid, userType); }