Exemplo n.º 1
0
        //
        // GET: /Manage/ManageLogins
        public async Task <ActionResult> ManageLogins(ManageMessageId?message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed."
                : message == ManageMessageId.Error ? "An error has occurred."
                : "";
            ApplicationUser user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            if (user == null)
            {
                return(View("Error"));
            }
            System.Collections.Generic.IList <UserLoginInfo> userLogins = await UserManager.GetLoginsAsync(User.Identity.GetUserId());

            System.Collections.Generic.List <AuthenticationDescription> otherLogins = AuthenticationManager.GetExternalAuthenticationTypes().Where(auth => userLogins.All(ul => auth.AuthenticationType != ul.LoginProvider)).ToList();
            ViewBag.ShowRemoveButton = user.PasswordHash != null || userLogins.Count > 1;
            return(View(new ManageLoginsViewModel
            {
                CurrentLogins = userLogins,
                OtherLogins = otherLogins
            }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ManageLogins(ManageMessageId?message = null)
        {
            ViewData["StatusMessage"] =
                message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed."
                : message == ManageMessageId.AddLoginSuccess ? "The external login was added."
                : message == ManageMessageId.Error ? "An error has occurred."
                : "";
            ApplicationUser user = await GetCurrentUserAsync();

            if (user == null)
            {
                return(View("Error"));
            }
            System.Collections.Generic.IList <UserLoginInfo> userLogins = await _userManager.GetLoginsAsync(user);

            System.Collections.Generic.IEnumerable <Microsoft.AspNetCore.Authentication.AuthenticationScheme> schemes = await _signInManager.GetExternalAuthenticationSchemesAsync();

            System.Collections.Generic.List <Microsoft.AspNetCore.Authentication.AuthenticationScheme> otherLogins = schemes.Where(auth => userLogins.All(ul => auth.Name != ul.LoginProvider)).ToList();
            ViewData["ShowRemoveButton"] = user.PasswordHash != null || userLogins.Count > 1;
            return(View(new ManageLoginsViewModel
            {
                CurrentLogins = userLogins,
                OtherLogins = otherLogins
            }));
        }