public IActionResult SignIn(SignInViewModel model, string returnUrl)
        {
            if (!_authenticationPluginManager
                .IsPluginActive("ExternalAuth.NovellActiveDirectory", _workContext.CurrentCustomer, _storeContext.CurrentStore.Id))
            {
                throw new NopException("Novell Active Directory authentication module cannot be loaded");
            }

            if (string.IsNullOrEmpty(_novellActiveDirectoryExternalAuthSettings.LdapPath))
            {
                throw new NopException("Novell Active Directory authentication module not configured");
            }

            IActionResult result;

            if (string.IsNullOrEmpty(model.AdUserName))
            {
                ExternalAuthorizerHelper.AddErrorsToDisplay(_localizationService.GetResource("Plugins.ExternalAuth.NovellActiveDirectory.WindowsUserNotAvailable"));
                result = new RedirectToActionResult("Login", "Customer", (!string.IsNullOrEmpty(returnUrl)) ? new
                {
                    ReturnUrl = returnUrl
                } : null);
            }
            else
            {
                LdapUser ldapUser;
                try
                {
                    ldapUser = _ldapService.GetUserByUserName(model.AdUserName);
                    if (null == ldapUser)
                    {
                        ExternalAuthorizerHelper.AddErrorsToDisplay(_localizationService.GetResource("Plugins.ExternalAuth.NovellActiveDirectory.UserNotFound"));
                        return(new RedirectToActionResult("Login", "Customer", (!string.IsNullOrEmpty(returnUrl)) ? new
                        {
                            ReturnUrl = returnUrl
                        } : null));
                    }
                }
                catch (Exception e)
                {
                    ExternalAuthorizerHelper.AddErrorsToDisplay(_localizationService.GetResource("Plugins.ExternalAuth.NovellActiveDirectory.LdapError : " + e));
                    return(new RedirectToActionResult("Login", "Customer", (!string.IsNullOrEmpty(returnUrl)) ? new
                    {
                        ReturnUrl = returnUrl
                    } : null));
                }

                try
                {
                    bool flag6 = _ldapService.Authenticate(ldapUser.DistinguishedName, model.AdPassword);
                    if (flag6)
                    {
                        ExternalAuthenticationParameters authenticationParameters = new ExternalAuthenticationParameters
                        {
                            ProviderSystemName = "ExternalAuth.NovellActiveDirectory",
                            AccessToken        = Guid.NewGuid().ToString(),
                            Email = ldapUser.Email,
                            ExternalIdentifier        = ldapUser.Email,
                            ExternalDisplayIdentifier = ldapUser.Email
                        };
                        return(_externalAuthenticationService.Authenticate(authenticationParameters, returnUrl));
                    }
                }
                catch (Exception e)
                {
                    ExternalAuthorizerHelper.AddErrorsToDisplay(_localizationService.GetResource("Plugins.ExternalAuth.NovellActiveDirectory.LdapError : " + "auth " + e));
                    return(new RedirectToActionResult("Login", "Customer", (!string.IsNullOrEmpty(returnUrl)) ? new
                    {
                        ReturnUrl = returnUrl
                    } : null));
                }
            }

            ExternalAuthorizerHelper.AddErrorsToDisplay(
                _localizationService.GetResource("Plugins.ExternalAuth.NovellActiveDirectory.LdapError"));
            result = new RedirectToActionResult("Login", "Customer",
                                                (!string.IsNullOrEmpty(returnUrl)) ? new { ReturnUrl = returnUrl } : null);
            return(result);
        }
 public CustomerAutoRegisteredByExternalMethodEvent(Customer customer, ExternalAuthenticationParameters parameters)
 {
     Customer = customer;
     AuthenticationParameters = parameters;
 }