//
        // GET: /Manage/LinkLoginCallback
        public async Task <ActionResult> LinkLoginCallback()
        {
            var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(XsrfKey, User.Identity.GetUserId());

            if (loginInfo == null)
            {
                return(RedirectToAction("ManageLogins", new { Message = ManageMessageId.Error }));
            }
            var result = await UserManageService.AddLoginAsync(User.Identity.GetUserId(), loginInfo.Login);

            return(result.Succeeded ? RedirectToAction("ManageLogins") : RedirectToAction("ManageLogins", new { Message = ManageMessageId.Error }));
        }
Beispiel #2
0
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }

            if (ModelState.IsValid)
            {
                // Получение сведений о пользователе от внешнего поставщика входа
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user   = Mapper.Map <UserServiceModel>(model);//new User { UserName = model.Email, Email = model.Email };
                var result = await UserManageService.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManageService.AddLoginAsync(user.Id, info.Login);//UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        await SignInManageService.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

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