Exemplo n.º 1
0
        // GET: /Manage/ManageExternalLogins
        public async Task <ActionResult> ManageExternalLogins(ManageControllerIndexViewMessageType?messageType)
        {
            var userId = this.userIdentityProvider.GetUserId(this.User.Identity);

            var user = await this.userIdentityApplicationService.FindByIdAsync(userId);

            if (user == null)
            {
                var errorViewModel = new ErrorViewModel(this.userIdentityProvider);

                return(this.View("Error", errorViewModel));
            }

            var userLogins = await this.userIdentityApplicationService.GetLoginsAsync(userId);

            var externalAuthenticationTypes = this.userIdentityApplicationService.GetExternalAuthenticationTypes().ToList();
            var externalUserLogins          = externalAuthenticationTypes
                                              .Where(authenticationType => userLogins.All(userLogin => authenticationType.AuthenticationType != userLogin.LoginProvider)).ToList();
            var mumberOfExternalAuthenticationTypes = externalAuthenticationTypes.Count();

            var manageExternalLoginsViewModel = new ManageExternalLoginsViewModel(this.userIdentityProvider)
            {
                UserLinkedLogins                    = userLogins,
                ExternalAuthenticationTypes         = externalUserLogins,
                NumberOfExternalAuthenticationTypes = mumberOfExternalAuthenticationTypes,
                StatusMessage = this.GetManageLoginsViewStatusMessage(messageType),
                ShowRemoveExternalAccountButton = user.PasswordHash != null || userLogins.Count > 1
            };

            return(this.View(manageExternalLoginsViewModel));
        }
        public async Task <IActionResult> ManageExternalLogins()
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (user == null)
            {
                return(View("Error"));
            }

            var userLogins = await _userManager.GetLoginsAsync(user);

            var otherLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync())
                              .Where(@as => userLogins.All(ul => @as.Name != ul.LoginProvider))
                              .ToList();

            var viewModel = new ManageExternalLoginsViewModel
                            (
                userLogins.ToList(),
                otherLogins.ToList(),
                user.PasswordHash != null || userLogins.Count > 1
                            );

            return(View(viewModel));
        }