Ejemplo n.º 1
0
        public IHttpActionResult Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            // var userModel = UserModel.Create(model.Email, model.Email);
            var user = new ApplicationUser
            {
                Email = model.Email,
                UserName = model.Email
            };

            IdentityResult result = null;

            // TODO: Remove this.
            try
            {
                result = UserManager.Create(user, model.Password);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            return Ok();
        }
Ejemplo n.º 2
0
        public async Task<IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var info = await Authentication.GetExternalLoginInfoAsync();
            if (info == null)
            {
                return InternalServerError();
            }

            var user = new ApplicationUser
            {
                Email = model.Email,
                UserName = model.Email
            };

            IdentityResult result = await UserManager.CreateAsync(user);
            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            result = await UserManager.AddLoginAsync(user.Id, info.Login);
            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }
            return Ok();
        }
Ejemplo n.º 3
0
        private static IList<ApplicationUser> CreateUsers(DealsWhatDbContext context)
        {
            var users = new List<ApplicationUser>();

            for (int i = 0; i < 10; i++)
            {
                //var user = new ApplicationUser();
                //user.UserName = string.Format("User{0}", i);
                //user.Email = string.Format("user{0}@email.com", i);
                //user.Id = i.ToString();
                //user.EmailConfirmed = true;

                //var userName = string.Format("User{0}", i);
                //var user = UserModel.Create(userName, userName);
                //user.SetFirstName("first");
                //user.SetLastName("last");

                var user = new ApplicationUser
                {
                    Email = string.Format("User{0}", i),
                    UserName = string.Format("User{0}", i)
                };

                var address = new AddressModel();
                address.City = "Petaling Jaya";
                address.Country = "Malaysia";
                address.Line1 = "A021 Taman Sentosa";
                address.Line2 = "Jalan A11/2 Klang Lama";
                address.PostCode = "24141";
                address.State = "Selangor";
                user.SetBillingAddress(address);
                // var applicationUser = new ApplicationUser(user);

                //var user = new ApplicationUser
                //{
                //    UserId = i,
                //    Username = string.Format("User{0}", i),
                //    EmailAddress = string.Format("user{0}@email.com", i),
                //    AddressLine1 = "addressline1",
                //    State = "state",
                //    City = "city",
                //    Street = "street",
                //    FirstName = "firstname",
                //    LastName = "lastname",
                //    ZipCode = "zip"
                //};

                users.Add(user);
                context.Users.Add(user);
            }

            return users;
        }