Пример #1
0
 /// <summary>
 /// Gets the specified policy as a string
 /// </summary>
 /// <param name="policy">The policy you want as a string</param>
 /// <returns>The policy value</returns>
 public static string GetPolicyAsString(IdentityPolicies policy)
 {
     if (policy == IdentityPolicies.Adult)
     {
         return "comment";
         //return "comment";
     }
     else if (policy == IdentityPolicies.Kids)
     {
         return "u16comment";
         // return "http://identity/policies/dna/kids";
     }
     else if (policy == IdentityPolicies.Over13)
     {
         return "comment";
         // return "http://identity/policies/dna/over13";
     }
     else if (policy == IdentityPolicies.Schools)
     {
         return "u16comment";
         // return "http://identity/policies/dna/schools";
     }
     else if (policy == IdentityPolicies.Blast)
     {
         return "comment";
         // return "http://identity/policies/dna/blast";
     }
     return "";
 }
Пример #2
0
 /// <summary>
 /// Helper method for creating a new normal Identity user on the fly
 /// </summary>
 /// <param name="userName">The name you want the new user to have</param>
 /// <param name="password">The password for the account</param>
 /// <param name="dateOfBirth">The date of birth for the account. Format - "1989-12-31"</param>
 /// <param name="email">The email for the account</param>
 /// <param name="displayName">The display name for the account</param>
 /// <param name="siteid">The site that you want to add the user as a notable</param>
 /// <param name="policy">The policy the user is to be validated against</param>
 /// <param name="cookie">Output value for the users cookie</param>
 /// <param name="secureCookie">Output value for the users secure cookie</param>
 /// <param name="identityUserID">Output value for the new users Identity UserID</param>
 /// <param name="dnaUserID">Output value for the new users DNA UserID</param>
 /// <returns>True if they were created ok, false if not</returns>
 public static bool CreateNewIdentityNotableUser(string userName, string password, string dateOfBirth, string email, string displayName, int siteid, IdentityPolicies policy, out Cookie cookie, out Cookie secureCookie, out string identityUserID, out int dnaUserID)
 {
     dnaUserID = 0;
     if (CreateNewIdentityNormalUser(userName, password, dateOfBirth, email, displayName, true, policy, true, out cookie, out secureCookie, out identityUserID, out dnaUserID))
     {
         if (dnaUserID > 0)
         {
             return AddUserToGroupInDatabase(dnaUserID, "Notables", siteid);
         }
     }
     return false;
 }
Пример #3
0
 /// <summary>
 /// Helper method for creating a new normal Identity user on the fly
 /// </summary>
 /// <param name="userName">The name you want the new user to have</param>
 /// <param name="password">The password for the account</param>
 /// <param name="dateOfBirth">The date of birth for the account. Format - "1989-12-31"</param>
 /// <param name="email">The email for the account</param>
 /// <param name="displayName">The display name for the account</param>
 /// <param name="acceptedIdentityTCs">A flag to whether or not the user has agreed the identity terms and conditions</param>
 /// <param name="policy">The policy the user is to be validated against</param>
 /// <param name="acceptedPolicyTCs">A flag stating whether or not the user has accepted the policy</param>
 /// <param name="cookie">Output value for the users cookie</param>
 /// <param name="secureCookie">Output value for the users secure cookie</param>
 /// <param name="identityUserID">Output value for the new users Identity UserID</param>
 /// <param name="dnaUserID">Output value for the new users DNA UserID</param>
 /// <returns>True if they were created ok, false if not</returns>
 public static bool CreateNewIdentityNormalUser(string userName, string password, string dateOfBirth, string email, string displayName, bool acceptedIdentiutyTCs, IdentityPolicies policy, bool acceptedPolicyTCs, out Cookie cookie, out Cookie secureCookie, out string userIdentityID, out int dnaUserID)
 {
     dnaUserID = 0;
     if (CreateIdentityUser(userName, password, dateOfBirth, email, displayName, true, policy, true, 0, out cookie, out secureCookie, out userIdentityID))
     {
         dnaUserID = CreateUserInDatabase(userName, email, displayName, userIdentityID);
     }
     return dnaUserID > 0;
 }
Пример #4
0
 /// <summary>
 /// Helper method for creating a new normal Identity user on the fly
 /// </summary>
 /// <param name="userName">The name you want the new user to have</param>
 /// <param name="password">The password for the account</param>
 /// <param name="dateOfBirth">The date of birth for the account. Format - "1989-12-31"</param>
 /// <param name="email">The email for the account</param>
 /// <param name="displayName">The display name for the account</param>
 /// <param name="policy">The policy the user is to be validated against</param>
 /// <param name="cookie">Output value for the users cookie</param>
 /// <param name="secureCookie">Output value for the users secure cookie</param>
 /// <param name="identityUserID">Output value for the new users Identity UserID</param>
 /// <param name="dnaUserID">Output value for the new users DNA UserID</param>
 /// <returns>True if they were created ok, false if not</returns>
 public static bool CreateNewIdentitySuperUser(string userName, string password, string dateOfBirth, string email, string displayName, IdentityPolicies policy, out Cookie cookie, out Cookie secureCookie, out string userIdentityID, out int dnaUserID)
 {
     dnaUserID = 0;
     if (CreateNewIdentityNormalUser(userName, password, dateOfBirth, email, displayName, true, policy, true, out cookie, out secureCookie, out userIdentityID, out dnaUserID))
     {
         SetUserAsSuperUserInDataBase(dnaUserID);
     }
     return dnaUserID > 0;
 }
Пример #5
0
        /// <summary>
        /// Creates/Registers a new Identity user
        /// </summary>
        /// <param name="userName">The name of the new user</param>
        /// <param name="password">The password the user account will use</param>
        /// <param name="dateOfBirth">The date of birth for the new user</param>
        /// <param name="email">The email address for the new user</param>
        /// <param name="displayName">Optional display name for the user. Leave blank if not needed</param>
        /// <param name="acceptedIdentityTCs">A flag to state whether or not the user has excepted the Identity T&Cs</param>
        /// <param name="policy">The policy that the user is being created for</param>
        /// <param name="acceptedPolicyTCs">A flag to state whether or no the user has accepted the policy T&Cs</param>
        /// <param name="legacySSOID"></param>
        /// <param name="cookie">Output value for the users cookie</param>
        /// <param name="secureCookie">Output value for the users secure cookie</param>
        /// <param name="userIdentityID"></param>
        /// <returns>True if created, false if not</returns>
        static public bool CreateIdentityUser(string userName,
                                                string password,
                                                string dateOfBirth,
                                                string email,
                                                string displayName,
                                                bool acceptedIdentityTCs,
                                                IdentityPolicies policy,
                                                bool acceptedPolicyTCs,
                                                int legacySSOID,
                                                out Cookie cookie,
                                                out Cookie secureCookie,
                                                out string userIdentityID)
        {
            ServicePointManager.ServerCertificateValidationCallback += AcceptAllCertificatePolicy;

            userIdentityID = "";
            cookie = null;
            secureCookie = null;

            // Create a new user to do the tests with
            Dictionary<string, string> postParams = new Dictionary<string, string>();
            postParams.Add(_wrUserName, userName);
            postParams.Add(_wrPassword, password);
            postParams.Add(_wrDateOfBirth, dateOfBirth);
            postParams.Add(_wrAgreementAcceptedFlag, acceptedIdentityTCs ? "1" : "0");
            postParams.Add(_wremail, email);
            postParams.Add(_wremailvalidated, acceptedPolicyTCs ? "1" : "0");
            if (policy != IdentityPolicies.Adult && acceptedIdentityTCs)
            {
                postParams.Add(_wrGuardianAcceptedFlag, "1");
                postParams.Add(_wrGuardianEmail, "parent_" + email);
                postParams.Add(_wrGuardianEmailConfirmed, "1");
            }

            if (displayName.Length > 0)
            {
                postParams.Add(_wrdisplayName, displayName);
            }
            if (legacySSOID > 0)
            {
                postParams.Add(_wrLegacySSOID, legacySSOID.ToString());
            }

            // Register the new user
            HttpWebResponse response = CallIdentityRestAPI("/users", postParams, null, RequestVerb.POST);
            if (response != null && response.StatusCode == HttpStatusCode.Created)
            {
                cookie = response.Cookies["IDENTITY"];
                secureCookie = response.Cookies["IDENTITY-HTTPS"];

                string[] cookieParams = cookie.Value.Split('|');
                userIdentityID = cookieParams[0];
                response.Close();
            }
            else
            {
                response.Close();
                _error += ".\nFailed to create user.";
                return false;
            }

            // Now update a few of the core attributes
            List<Cookie> cookies = new List<Cookie>();
            cookies.Add(cookie);
            cookies.Add(secureCookie);

            // Now update the personal attribute for the policy T&Cs
            if (acceptedPolicyTCs)
            {
                postParams.Clear();
                if (policy == IdentityPolicies.Adult)
                {
                    postParams.Add(_wrHouseRulesAdults, "1");
                }
                else if (policy == IdentityPolicies.Over13)
                {
                    postParams.Add(_wrHouseRulesOver13, "1");
                }
                else if (policy == IdentityPolicies.Schools)
                {
                    postParams.Add(_wrHouseRulesSchools, "1");
                }
                else
                {
                    postParams.Add(_wrHouseRulesKids, "1");
                }

                response = CallIdentityRestAPI(string.Format("/users/{0}/applications/dna/attributes", userName), postParams, cookies, RequestVerb.POST);
                if (response == null || response.StatusCode != HttpStatusCode.Created)
                {
                    _error += ".\nFailed to set users policy details.";
                    response.Close();
                    return false;
                }
                response.Close();
            }

            Console.WriteLine("Created new Identity User : "******", " + password + ", " + dateOfBirth + ", " + email + ", " + displayName);

            return true;
        }