Beispiel #1
0
        public static Person Create(string name, string email, string password, string phone, string street,
                                    string postal, string city, string countryCode, DateTime dateOfBirth,
                                    PersonGender gender)
        {
            BasicCountry country = null;

            if (countryCode.Length > 0)
            {
                country = Country.FromCode(countryCode);
            }

            // Clean data

            while (name.Contains("  "))
            {
                name = name.Replace("  ", " ");
            }

            name   = name.Trim();
            email  = email.ToLower().Trim();
            phone  = LogicServices.CleanNumber(phone);
            postal = postal.Replace(" ", "").Trim();

            int personId = SwarmDb.GetDatabaseForWriting().CreatePerson(name, email, phone, street, postal, city,
                                                                        country == null ? 0 : country.Identity, dateOfBirth, gender);


            // Resolve the geography

            Person newPerson = FromIdentityAggressive(personId);

            // aggressive bypasses replication lag, avoids race condition
            newPerson.ResolveGeography();

            // Generate the salted password hash and set it

            if (password.Length > 0)
            {
                newPerson.PasswordHash = Authentication.GenerateNewPasswordHash(personId, password);
            }
            else
            {
                newPerson.PasswordHash = string.Empty; // if no password, prevent matching to anything
            }

            // Return the finished Person object

            return(newPerson);
        }