public void MapAnLoginToAParent()
        {
            //Arrange
            var parent = SharedArrange.SomeParent();
            var inviteId = Guid.NewGuid();
            parent.InvitationId = inviteId;

            context.Parents.Add(parent);
            context.SaveChanges();

            var command = new MapLoginToParent
            {
                InvitationId = inviteId,
                UserId = "abcde"
            };
            //Act
            command.Execute();
            //Assert
            Assert.IsTrue(RunDatabaseAsserts());

            //Teardown
        }
Ejemplo n.º 2
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model,
            string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Manage");
            }

            //If invide id is gone then something went wrong, logout.
            var inviteId = ControllerContext.HttpContext.Session["inviteId"];
            if (inviteId == null)
            {
                return LogOff();
            }

            if (ModelState.IsValid && inviteId != null)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };// adds record to AspNetUsers
    
                //-----
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {

                    result = await UserManager.AddLoginAsync(user.Id, info.Login);// adds record to [AspNetUserLogins]
                    if (result.Succeeded)
                    {
                        //Map parent to this user.
                        var command = new MapLoginToParent
                        {
                            InvitationId = Guid.Parse(inviteId.ToString()),
                            UserId = user.Id
                        };
                        command.Execute();

                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return RedirectToLocal(returnUrl);
                    }
                    AddErrors(result);
                }
                //----

            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }