private void validateAdr(GeographicAddressData d, GeographicAddressView v)
 {
     Assert.AreEqual(v.AddressLine, d.Address);
     Assert.AreEqual(v.City, d.CityOrAreaCode);
     Assert.AreEqual(v.RegionOrState, d.RegionOrStateOrCountryCode);
     Assert.AreEqual(v.ZipOrPostalCode, d.ZipOrPostCodeOrExtension);
     Assert.AreEqual(v.Country, d.CountryID);
     validateCommon(d, v);
 }
示例#2
0
 private void validateEntity(GeographicAddressView expected, GeographicAddressData actual)
 {
     Assert.IsNotNull(expected);
     Assert.IsNotNull(actual);
     Assert.AreEqual(expected.ID, actual.ID);
     Assert.AreEqual(expected.AddressLine, actual.Address);
     Assert.AreEqual(expected.City, actual.CityOrAreaCode);
     Assert.AreEqual(expected.Country, actual.CountryID);
     Assert.AreEqual(expected.RegionOrState, actual.RegionOrStateOrCountryCode);
     Assert.AreEqual(expected.ZipOrPostalCode, actual.ZipOrPostCodeOrExtension);
     validateDates(expected.ValidFrom, actual.ValidFrom);
     validateDates(expected.ValidTo, actual.ValidTo);
 }
示例#3
0
        public static GeographicAddress Create(GeographicAddressView v)
        {
            var d = new GeographicAddressData {
                ID                         = v.ID,
                Address                    = v.AddressLine,
                CityOrAreaCode             = v.City,
                ZipOrPostCodeOrExtension   = v.ZipOrPostalCode,
                RegionOrStateOrCountryCode = v.RegionOrState,
                CountryID                  = v.Country,
                ValidTo                    = v.ValidTo ?? DateTime.MaxValue,
                ValidFrom                  = v.ValidFrom ?? DateTime.MinValue
            };

            return(new GeographicAddress(d));
        }
示例#4
0
        public static GeographicAddress CreateAddress(string id, string addressLine,
                                                      string city, string regionOrState, string zipOrPostalCode, string countryId,
                                                      DateTime?validFrom = null, DateTime?validTo = null)
        {
            var r = new GeographicAddressData {
                ID      = id,
                Address = addressLine,
                ZipOrPostCodeOrExtension   = zipOrPostalCode,
                RegionOrStateOrCountryCode = regionOrState,
                CityOrAreaCode             = city,
                CountryID = countryId,
                ValidFrom = validFrom ?? DateTime.MinValue,
                ValidTo   = validTo ?? DateTime.MaxValue
            };

            return(new GeographicAddress(r));
        }
        Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var addressId = Guid.NewGuid().ToString();
                var address   = new GeographicAddressData {
                    Address   = model.AddressLine, CityOrAreaCode = model.City,
                    CountryID = getCountryCodesDictionary()[model.Country], ID = addressId,
                    ZipOrPostCodeOrExtension   = model.ZipCode,
                    RegionOrStateOrCountryCode = model.County
                };
                var user = new ApplicationUser {
                    UserName  = model.Email, Email = model.Email,
                    FirstName = model.FirstName, LastName = model.LastName, Address = address, AddressID = addressId, DateOfBirth = model.DateOfBirth
                };
                await addresses.AddObject(AddressFactory.Create(address));

                var result = await userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    logger.LogInformation("User created a new account with password.");
                    var code = await userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                    await emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

                    await signInManager.SignInAsync(user, isPersistent : false);

                    logger.LogInformation("User created a new account with password.");
                    return(redirectToLocal(returnUrl));
                }

                addErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#6
0
 private static GeographicAddress create(GeographicAddressData data)
 {
     return(new GeographicAddress(data));
 }
        public static void Initialize(ApplicationDbContext context)
        {
            context.Database.EnsureCreated();

            var userAddressId = Guid.NewGuid().ToString();
            var userAddress   = new GeographicAddressData {
                ID      = userAddressId,
                Address = "Test Lane 5",
                ZipOrPostCodeOrExtension   = "12345",
                CityOrAreaCode             = "Test City",
                RegionOrStateOrCountryCode = "Siilimäe",
                CountryID = "EST",
            };
            var user = new ApplicationUser
            {
                FirstName            = "Test",
                LastName             = "User",
                Email                = "*****@*****.**",
                NormalizedEmail      = "*****@*****.**",
                UserName             = "******",
                NormalizedUserName   = "******",
                PhoneNumber          = "+111111111111",
                Address              = userAddress,
                AddressID            = userAddressId,
                DateOfBirth          = DateTime.ParseExact("27/10/2018", "dd/MM/yyyy", CultureInfo.InvariantCulture),
                EmailConfirmed       = true,
                PhoneNumberConfirmed = true,
                SecurityStamp        = Guid.NewGuid().ToString("D"),
                Id = "testUserid"
            };
            var user2AddressId = Guid.NewGuid().ToString();
            var user2Address   = new GeographicAddressData
            {
                ID      = user2AddressId,
                Address = "Test Lane 4",
                ZipOrPostCodeOrExtension   = "12344",
                CityOrAreaCode             = "Test City",
                RegionOrStateOrCountryCode = "Mustamäe",
                CountryID = "EST",
            };
            var user2 = new ApplicationUser
            {
                FirstName            = "Sonic",
                LastName             = "Siil",
                Email                = "*****@*****.**",
                NormalizedEmail      = "*****@*****.**",
                UserName             = "******",
                NormalizedUserName   = "******",
                PhoneNumber          = "+111111111111",
                Address              = user2Address,
                AddressID            = user2AddressId,
                DateOfBirth          = DateTime.ParseExact("29/10/2018", "dd/MM/yyyy", CultureInfo.InvariantCulture),
                EmailConfirmed       = true,
                PhoneNumberConfirmed = true,
                SecurityStamp        = Guid.NewGuid().ToString("D"),
                Id = "sonicSiilId"
            };

            var systemAddressId = Guid.NewGuid().ToString();
            var systemAddress   = new GeographicAddressData
            {
                ID      = systemAddressId,
                Address = "null",
                ZipOrPostCodeOrExtension   = "12345",
                CityOrAreaCode             = "null",
                RegionOrStateOrCountryCode = "Siliine",
                CountryID = "EST",
            };
            var system = new ApplicationUser
            {
                FirstName            = "System",
                LastName             = "User",
                Email                = "*****@*****.**",
                NormalizedEmail      = "*****@*****.**",
                UserName             = "******",
                NormalizedUserName   = "******",
                PhoneNumber          = "+111111111111",
                Address              = systemAddress,
                AddressID            = systemAddressId,
                DateOfBirth          = DateTime.ParseExact("07/11/2018", "dd/MM/yyyy", CultureInfo.InvariantCulture),
                EmailConfirmed       = true,
                PhoneNumberConfirmed = true,
                SecurityStamp        = Guid.NewGuid().ToString("D"),
                Id = "system"
            };

            if (!context.Users.Any(u => u.UserName == user2.UserName) || !context.Users.Any(u => u.UserName == user.UserName) || !context.Users.Any(u => u.UserName == system.UserName))
            {
                var userStore = new UserStore <ApplicationUser>(context);
                hashPasswordAndCreateUser(userStore, user, "secret");
                hashPasswordAndCreateUser(userStore, user2, "secret");
                hashPasswordAndCreateUser(userStore, system, "secret");
            }
            context.SaveChangesAsync();
        }