FindByEmailAddress() public method

public FindByEmailAddress ( string emailAddress ) : User
emailAddress string
return User
        public async virtual Task <ActionResult> LinkExternalAccount(string returnUrl)
        {
            // Extract the external login info
            var result = await AuthService.AuthenticateExternalLogin(OwinContext);

            if (result.ExternalIdentity == null)
            {
                // User got here without an external login cookie (or an expired one)
                // Send them to the logon action
                return(ExternalLinkExpired());
            }

            if (result.Authentication != null)
            {
                AuthService.CreateSession(OwinContext, result.Authentication.User);
                return(SafeRedirect(returnUrl));
            }
            else
            {
                // Gather data for view model
                var authUI = result.Authenticator.GetUI();
                var email  = result.ExternalIdentity.GetClaimOrDefault(ClaimTypes.Email);
                var name   = result
                             .ExternalIdentity
                             .GetClaimOrDefault(ClaimTypes.Name);

                // Check for a user with this email address
                User existingUser = null;
                if (!string.IsNullOrEmpty(email))
                {
                    existingUser = UserService.FindByEmailAddress(email);
                }

                var external = new AssociateExternalAccountViewModel()
                {
                    ProviderAccountNoun = authUI.AccountNoun,
                    AccountName         = name,
                    FoundExistingUser   = existingUser != null
                };

                var model = new LogOnViewModel
                {
                    External = external,
                    SignIn   = new SignInViewModel
                    {
                        UserNameOrEmail = email
                    },
                    Register = new RegisterViewModel
                    {
                        EmailAddress = email
                    }
                };

                return(LogOnView(model));
            }
        }
コード例 #2
0
        public async virtual Task <ActionResult> LinkExternalAccount(string returnUrl)
        {
            // Extract the external login info
            var result = await AuthService.AuthenticateExternalLogin(OwinContext);

            if (result.ExternalIdentity == null)
            {
                // User got here without an external login cookie (or an expired one)
                // Send them to the logon action
                return(ExternalLinkExpired());
            }

            if (result.Authentication != null)
            {
                // If we are an administrator and Gallery.EnforcedAuthProviderForAdmin is set
                // to require a specific authentication provider, challenge that provider if needed.
                ActionResult challenge;
                if (ShouldChallengeEnforcedProvider(
                        NuGetContext.Config.Current.EnforcedAuthProviderForAdmin, result.Authentication, returnUrl, out challenge))
                {
                    return(challenge);
                }

                // Create session
                await AuthService.CreateSessionAsync(OwinContext, result.Authentication);

                return(SafeRedirect(returnUrl));
            }
            else
            {
                // Gather data for view model
                var authUI = result.Authenticator.GetUI();
                var email  = result.ExternalIdentity.GetClaimOrDefault(ClaimTypes.Email);
                var name   = result
                             .ExternalIdentity
                             .GetClaimOrDefault(ClaimTypes.Name);

                // Check for a user with this email address
                User existingUser = null;
                if (!string.IsNullOrEmpty(email))
                {
                    existingUser = UserService.FindByEmailAddress(email);
                }

                var external = new AssociateExternalAccountViewModel()
                {
                    ProviderAccountNoun = authUI.AccountNoun,
                    AccountName         = name,
                    FoundExistingUser   = existingUser != null
                };

                var model = new LogOnViewModel
                {
                    External = external,
                    SignIn   = new SignInViewModel
                    {
                        UserNameOrEmail = email
                    },
                    Register = new RegisterViewModel
                    {
                        EmailAddress = email
                    }
                };

                return(LogOnView(model));
            }
        }