Ejemplo n.º 1
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="customer">Customer</param>
 /// <param name="parameters">Parameters</param>
 public CustomerAutoRegisteredByExternalMethodEvent(Customer customer, ExternalAuthenticationParameters parameters)
 {
     this.Customer = customer;
     this.AuthenticationParameters = parameters;
 }
        /// <summary>
        /// Authenticate current user and associate new external account with user
        /// </summary>
        /// <param name="currentLoggedInUser">Current logged-in user</param>
        /// <param name="parameters">Authentication parameters received from external authentication method</param>
        /// <param name="returnUrl">URL to which the user will return after authentication</param>
        /// <returns>Result of an authentication</returns>
        protected virtual IActionResult AuthenticateNewUser(Customer currentLoggedInUser, ExternalAuthenticationParameters parameters, string returnUrl)
        {
            //associate external account with logged-in user
            if (currentLoggedInUser != null)
            {
                AssociateExternalAccountWithUser(currentLoggedInUser, parameters);
                return(SuccessfulAuthentication(returnUrl));
            }

            //or try to register new user
            if (_customerSettings.UserRegistrationType != UserRegistrationType.Disabled)
            {
                return(RegisterNewUser(parameters, returnUrl));
            }

            //registration is disabled
            return(ErrorAuthentication(new[] { "Registration is disabled" }, returnUrl));
        }