public async Task<IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var user = new ApplicationUser() { UserName = model.Email, Email = model.Email, Name = model.Name, Address1 = model.Address1, Address2 = model.Address2, City = model.City, Company = model.Company, Fax = model.Fax, Phone = model.Phone };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                //Email
                var message = new SendGridMessage();
                message.From = new MailAddress("*****@*****.**");

                message.AddTo(user.Email);
                message.Subject = "Thanks for registering with Envision4IT";
                message.Text = "Thanks for registering with Envision4IT";

                var credentials = new NetworkCredential("quoc.m.duong", "uaaQD4512");
                var transportWeb = new Web("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");
                await transportWeb.DeliverAsync(message);
            }
            else
            {
                return GetErrorResult(result);
            }

            return Ok();
        }
        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() { UserName = model.Email, Email = 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();
        }
Beispiel #3
0
        private static void seedusers(ApplicationDbContext db)
        {
            var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));

            if (!db.Users.Any(x => x.UserName == "*****@*****.**"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "*****@*****.**",
                    UserName = "******",
                    Name = "Customer #1",
                    Company = "XZY Company",
                    Address1 = "Address Line 1",
                    Address2 = "Address Line 2",
                    City = "San Francisco",
                    State = "CA",
                    Zip = 94104,
                    Phone = 1234567890,
                    Fax = 1234567890
                };
                manager.Create(user, "123123");
            }

            if (!db.Users.Any(x => x.UserName == "*****@*****.**"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "*****@*****.**",
                    UserName = "******",
                    Name = "Tech user",
                    Company = "XZY Company",
                    Address1 = "Address Line 1",
                    Address2 = "Address Line 2",
                    City = "San Francisco",
                    State = "CA",
                    Zip = 94104,
                    Phone = 1234567890,
                    Fax = 1234567890
                };
                manager.Create(user, "123123");
            }
            if (!db.Users.Any(x => x.UserName == "*****@*****.**"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "*****@*****.**",
                    UserName = "******",
                    Name = "Admin user",
                    Company = "XZY Company",
                    Address1 = "Address Line 1",
                    Address2 = "Address Line 2",
                    City = "San Francisco",
                    State = "CA",
                    Zip = 94104,
                    Phone = 1234567890,
                    Fax = 1234567890
                };
                manager.Create(user, "123123");
            }
            if (!db.Users.Any(x => x.UserName == "*****@*****.**"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "*****@*****.**",
                    UserName = "******",
                    Name = "Root user",
                    Company = "XZY Company",
                    Address1 = "Address Line 1",
                    Address2 = "Address Line 2",
                    City = "San Francisco",
                    State = "CA",
                    Zip = 94104,
                    Phone = 1234567890,
                    Fax = 1234567890
                };
                manager.Create(user, "123123");
            }

            if (!db.Users.Any(x => x.UserName == "*****@*****.**"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "*****@*****.**",
                    UserName = "******",
                    Name = "Customer #2",
                    Company = "XZY Company",
                    Address1 = "Address Line 1",
                    Address2 = "Address Line 2",
                    City = "San Francisco",
                    State = "CA",
                    Zip = 94104,
                    Phone = 1234567890,
                    Fax = 1234567890
                };
                manager.Create(user, "123123");
            }
            if (!db.Users.Any(x => x.UserName == "*****@*****.**"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "*****@*****.**",
                    UserName = "******",
                    Name = "Customer #3",
                    Company = "XZY Company",
                    Address1 = "Address Line 1",
                    Address2 = "Address Line 2",
                    City = "San Francisco",
                    State = "CA",
                    Zip = 94104,
                    Phone = 1234567890,
                    Fax = 1234567890
                };
                manager.Create(user, "123123");
            }
            db.SaveChanges();
        }