Ejemplo n.º 1
0
        public async Task Post(Invite invite)
        {
            using (var context = new ApplicationDbContext())
            {
                string userName = $"User-{Guid.NewGuid()}";
                var user = new ApplicationUser { UserName = userName, Email = invite.Email };

                var result = Request.GetOwinContext()
                    .GetUserManager<ApplicationUserManager>()
                    .CreateAsync(user, Guid.NewGuid().ToString()).Result;

                if (!result.Succeeded)
                {
                    throw new Exception("Error Inviting!");
                }

                var createdUser = context.Users
                    .Single(u => u.UserName == userName);

                invite.CreatedUser = createdUser;

                context.EventUsers.Add(new EventUser
                {
                    EventId = invite.EventId,
                    UserId = createdUser.Id,
                    Owner = false,
                    Attending = Attending.NotSelected,
                });

                context.Invites
                    .Add(invite);

                await EmailInvite(invite);

                context.SaveChanges();
            }
        }
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 { 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();
        }
Ejemplo n.º 3
0
        public async Task<IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                EmailNewUser(model.Email);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

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

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

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

            return Ok();
        }