public ActionResult MethodUpdate(AuthenticationMethodModel model, GridCommand command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageExternalAuthenticationMethods)) { return(AccessDeniedView()); } var eam = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName(model.SystemName); if (eam.IsMethodActive(_externalAuthenticationSettings)) { if (!model.IsActive) { //mark as disabled _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Remove(eam.PluginDescriptor.SystemName); _settingService.SaveSetting(_externalAuthenticationSettings); } } else { if (model.IsActive) { //mark as active _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Add(eam.PluginDescriptor.SystemName); _settingService.SaveSetting(_externalAuthenticationSettings); } } return(Methods(command)); }
public ActionResult ActivateProvider(string systemName, bool activate) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageExternalAuthenticationMethods)) { return(AccessDeniedView()); } var method = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName(systemName); bool dirty = method.IsMethodActive(_externalAuthenticationSettings) != activate; if (dirty) { if (!activate) { _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Remove(method.Metadata.SystemName); } else { _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Add(method.Metadata.SystemName); } _settingService.SaveSetting(_externalAuthenticationSettings); _pluginMediator.ActivateDependentWidgets(method.Metadata, activate); } return(RedirectToAction("Providers")); }
private ActionResult LoginInternal(string returnUrl, bool verifyResponse) { var processor = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName("ExternalAuth.Weixin"); if (processor == null || !processor.IsMethodActive(_externalAuthenticationSettings) || !processor.PluginDescriptor.Installed || !_pluginFinder.AuthenticateStore(processor.PluginDescriptor, _storeContext.CurrentStore.Id)) { throw new NopException("Weixin module cannot be loaded"); } var viewModel = new LoginModel(); TryUpdateModel(viewModel); var result = _oAuthProviderWeixinAuthorizer.Authorize(returnUrl, verifyResponse); switch (result.AuthenticationStatus) { case OpenAuthenticationStatus.Error: { if (!result.Success) { foreach (var error in result.Errors) { ExternalAuthorizerHelper.AddErrorsToDisplay(error); } } return(new RedirectResult(Url.LogOn(returnUrl))); } case OpenAuthenticationStatus.AssociateOnLogon: { return(new RedirectResult(Url.LogOn(returnUrl))); } case OpenAuthenticationStatus.AutoRegisteredEmailValidation: { //result return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.EmailValidation })); } case OpenAuthenticationStatus.AutoRegisteredAdminApproval: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.AdminApproval })); } case OpenAuthenticationStatus.AutoRegisteredStandard: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Standard })); } default: break; } if (result.Result != null) { return(result.Result); } return(HttpContext.Request.IsAuthenticated ? new RedirectResult(!string.IsNullOrEmpty(returnUrl) ? returnUrl : "~/") : new RedirectResult(Url.LogOn(returnUrl))); }
private ActionResult LoginInternal(string returnUrl, bool verifyResponse) { var processor = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName(FacebookExternalAuthMethod.SystemName, _services.StoreContext.CurrentStore.Id); if (processor == null || !processor.IsMethodActive(_externalAuthenticationSettings)) { throw new SmartException("Facebook module cannot be loaded"); } var viewModel = new LoginModel(); TryUpdateModel(viewModel); var result = _oAuthProviderFacebookAuthorizer.Authorize(returnUrl, verifyResponse); switch (result.AuthenticationStatus) { case OpenAuthenticationStatus.Error: { if (!result.Success) { result.Errors.Each(x => NotifyError(x)); } return(new RedirectResult(Url.LogOn(returnUrl))); } case OpenAuthenticationStatus.AssociateOnLogon: { return(new RedirectResult(Url.LogOn(returnUrl))); } case OpenAuthenticationStatus.AutoRegisteredEmailValidation: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.EmailValidation, returnUrl })); } case OpenAuthenticationStatus.AutoRegisteredAdminApproval: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.AdminApproval, returnUrl })); } case OpenAuthenticationStatus.AutoRegisteredStandard: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Standard, returnUrl })); } default: break; } if (result.Result != null) { return(result.Result); } return(HttpContext.Request.IsAuthenticated ? RedirectToReferrer(returnUrl, "~/") : new RedirectResult(Url.LogOn(returnUrl))); }
public ActionResult LoginInternal(string returnUrl, bool verifyResponse) { var processor = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName("ExternalAuth.WeiXin"); //if (processor == null || //!processor.IsMethodActive(_externalAuthenticationSettings) || //!processor.PluginDescriptor.Installed) //throw new Exception("微信登录插件没有加载"); var result = _oAuthProviderWeiXinAuthorizer.Authorize(returnUrl, verifyResponse); switch (result.AuthenticationStatus) { case OpenAuthenticationStatus.Error: { if (!result.Success) { foreach (var error in result.Errors) { ExternalAuthorizerHelper.AddErrorsToDisplay(error); } } return(new RedirectResult(Url.LogOn(returnUrl))); } case OpenAuthenticationStatus.AssociateOnLogon: { return(new RedirectResult(Url.LogOn(returnUrl))); } case OpenAuthenticationStatus.AutoRegisteredEmailValidation: { //result return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.EmailValidation })); } case OpenAuthenticationStatus.AutoRegisteredAdminApproval: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.AdminApproval })); } case OpenAuthenticationStatus.AutoRegisteredStandard: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Standard })); } default: break; } if (result.Result != null) { return(result.Result); } return(HttpContext.Request.IsAuthenticated? new RedirectResult(!string.IsNullOrEmpty(returnUrl) ? returnUrl : "~/") : new RedirectResult(Url.LogOn(returnUrl))); }
public ActionResult MethodUpdate([Bind(Exclude = "ConfigurationRouteValues")] AuthenticationMethodModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageExternalAuthenticationMethods)) { return(AccessDeniedView()); } var eam = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName(model.SystemName); if (eam.IsMethodActive(_externalAuthenticationSettings)) { if (!model.IsActive) { //mark as disabled _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Remove( eam.PluginDescriptor.SystemName); _settingService.SaveSetting(_externalAuthenticationSettings); } } else { if (model.IsActive) { //mark as active _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Add( eam.PluginDescriptor.SystemName); _settingService.SaveSetting(_externalAuthenticationSettings); } } var pluginDescriptor = eam.PluginDescriptor; pluginDescriptor.DisplayOrder = model.DisplayOrder; PluginFileParser.SavePluginDescriptionFile(pluginDescriptor); //reset plugin cache _pluginFinder.ReloadPlugins(); return(new NullJsonResult()); }
private ActionResult LoginInternal(string returnUrl, bool verifyResponse) { var processor = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName(TwitterExternalAuthMethod.SystemName, Services.StoreContext.CurrentStore.Id); if (processor == null || !processor.IsMethodActive(_externalAuthenticationSettings)) { NotifyError(T("Plugins.CannotLoadModule", T("Plugins.FriendlyName.SmartStore.TwitterAuth"))); return(new RedirectResult(Url.LogOn(returnUrl))); } var authorizer = Services.ResolveNamed <IExternalProviderAuthorizer>("twitter"); var result = authorizer.Authorize(returnUrl, verifyResponse); switch (result.AuthenticationStatus) { case OpenAuthenticationStatus.Error: result.Errors.Each(x => NotifyError(x)); return(new RedirectResult(Url.LogOn(returnUrl))); case OpenAuthenticationStatus.AssociateOnLogon: return(new RedirectResult(Url.LogOn(returnUrl))); case OpenAuthenticationStatus.AutoRegisteredEmailValidation: return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.EmailValidation, returnUrl })); case OpenAuthenticationStatus.AutoRegisteredAdminApproval: return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.AdminApproval, returnUrl })); case OpenAuthenticationStatus.AutoRegisteredStandard: return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Standard, returnUrl })); default: if (result.Result != null) { return(result.Result); } if (HttpContext.Request.IsAuthenticated) { return(RedirectToReferrer(returnUrl, "~/")); } return(new RedirectResult(Url.LogOn(returnUrl))); } }
public ActionResult Login(string returnUrl) { var processor = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName("QQ外部认证"); if (processor == null || !processor.IsMethodActive(_externalAuthenticationSettings) || !processor.PluginDescriptor.Installed || !_pluginFinder.AuthenticateStore(processor.PluginDescriptor, _storeContext.CurrentStore.Id)) { throw new NopException("QQ模块没有被装载"); } var viewModel = new LoginModel(); TryUpdateModel(viewModel); var authenticationUrl = RequestAuthentication(); return(new RedirectResult(authenticationUrl)); }
public ActionResult ConfigureMethod(string systemName) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageExternalAuthenticationMethods)) { return(AccessDeniedView()); } var eam = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName(systemName); if (eam == null) { return(RedirectToAction("Methods")); } var model = eam.ToModel(); string actionName, controllerName; RouteValueDictionary routeValues; eam.GetConfigurationRoute(out actionName, out controllerName, out routeValues); model.ConfigurationActionName = actionName; model.ConfigurationControllerName = controllerName; model.ConfigurationRouteValues = routeValues; return(View(model)); }
public virtual CustomerInfoModel PrepareCustomerInfoModel(CustomerInfoModel model, Customer customer, bool excludeProperties, string overrideCustomCustomerAttributesXml = "") { if (model == null) { throw new ArgumentNullException("model"); } if (customer == null) { throw new ArgumentNullException("customer"); } model.AllowCustomersToSetTimeZone = _dateTimeSettings.AllowCustomersToSetTimeZone; foreach (var tzi in _dateTimeHelper.GetSystemTimeZones()) { model.AvailableTimeZones.Add(new SelectListItem { Text = tzi.DisplayName, Value = tzi.Id, Selected = (excludeProperties ? tzi.Id == model.TimeZoneId : tzi.Id == _dateTimeHelper.CurrentTimeZone.Id) }); } if (!excludeProperties) { model.VatNumber = customer.GetAttribute <string>(SystemCustomerAttributeNames.VatNumber); model.FirstName = customer.GetAttribute <string>(SystemCustomerAttributeNames.FirstName); model.LastName = customer.GetAttribute <string>(SystemCustomerAttributeNames.LastName); model.Gender = customer.GetAttribute <string>(SystemCustomerAttributeNames.Gender); var dateOfBirth = customer.GetAttribute <DateTime?>(SystemCustomerAttributeNames.DateOfBirth); if (dateOfBirth.HasValue) { model.DateOfBirthDay = dateOfBirth.Value.Day; model.DateOfBirthMonth = dateOfBirth.Value.Month; model.DateOfBirthYear = dateOfBirth.Value.Year; } model.Company = customer.GetAttribute <string>(SystemCustomerAttributeNames.Company); model.StreetAddress = customer.GetAttribute <string>(SystemCustomerAttributeNames.StreetAddress); model.StreetAddress2 = customer.GetAttribute <string>(SystemCustomerAttributeNames.StreetAddress2); model.ZipPostalCode = customer.GetAttribute <string>(SystemCustomerAttributeNames.ZipPostalCode); model.City = customer.GetAttribute <string>(SystemCustomerAttributeNames.City); model.CountryId = customer.GetAttribute <int>(SystemCustomerAttributeNames.CountryId); model.StateProvinceId = customer.GetAttribute <int>(SystemCustomerAttributeNames.StateProvinceId); model.Phone = customer.GetAttribute <string>(SystemCustomerAttributeNames.Phone); model.Fax = customer.GetAttribute <string>(SystemCustomerAttributeNames.Fax); //newsletter var newsletter = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(customer.Email, _storeContext.CurrentStore.Id); model.Newsletter = newsletter != null && newsletter.Active; model.Signature = customer.GetAttribute <string>(SystemCustomerAttributeNames.Signature); model.Email = customer.Email; model.Username = customer.Username; } else { if (_customerSettings.UsernamesEnabled && !_customerSettings.AllowUsersToChangeUsernames) { model.Username = customer.Username; } } if (_customerSettings.UserRegistrationType == UserRegistrationType.EmailValidation) { model.EmailToRevalidate = customer.EmailToRevalidate; } //countries and states if (_customerSettings.CountryEnabled) { model.AvailableCountries.Add(new SelectListItem { Text = _localizationService.GetResource("Address.SelectCountry"), Value = "0" }); foreach (var c in _countryService.GetAllCountries(_workContext.WorkingLanguage.Id)) { model.AvailableCountries.Add(new SelectListItem { Text = c.GetLocalized(x => x.Name), Value = c.Id.ToString(), Selected = c.Id == model.CountryId }); } if (_customerSettings.StateProvinceEnabled) { //states var states = _stateProvinceService.GetStateProvincesByCountryId(model.CountryId, _workContext.WorkingLanguage.Id).ToList(); if (states.Any()) { model.AvailableStates.Add(new SelectListItem { Text = _localizationService.GetResource("Address.SelectState"), Value = "0" }); foreach (var s in states) { model.AvailableStates.Add(new SelectListItem { Text = s.GetLocalized(x => x.Name), Value = s.Id.ToString(), Selected = (s.Id == model.StateProvinceId) }); } } else { bool anyCountrySelected = model.AvailableCountries.Any(x => x.Selected); model.AvailableStates.Add(new SelectListItem { Text = _localizationService.GetResource(anyCountrySelected ? "Address.OtherNonUS" : "Address.SelectState"), Value = "0" }); } } } model.DisplayVatNumber = _taxSettings.EuVatEnabled; model.VatNumberStatusNote = ((VatNumberStatus)customer.GetAttribute <int>(SystemCustomerAttributeNames.VatNumberStatusId)) .GetLocalizedEnum(_localizationService, _workContext); model.GenderEnabled = _customerSettings.GenderEnabled; model.DateOfBirthEnabled = _customerSettings.DateOfBirthEnabled; model.DateOfBirthRequired = _customerSettings.DateOfBirthRequired; model.CompanyEnabled = _customerSettings.CompanyEnabled; model.CompanyRequired = _customerSettings.CompanyRequired; model.StreetAddressEnabled = _customerSettings.StreetAddressEnabled; model.StreetAddressRequired = _customerSettings.StreetAddressRequired; model.StreetAddress2Enabled = _customerSettings.StreetAddress2Enabled; model.StreetAddress2Required = _customerSettings.StreetAddress2Required; model.ZipPostalCodeEnabled = _customerSettings.ZipPostalCodeEnabled; model.ZipPostalCodeRequired = _customerSettings.ZipPostalCodeRequired; model.CityEnabled = _customerSettings.CityEnabled; model.CityRequired = _customerSettings.CityRequired; model.CountryEnabled = _customerSettings.CountryEnabled; model.CountryRequired = _customerSettings.CountryRequired; model.StateProvinceEnabled = _customerSettings.StateProvinceEnabled; model.StateProvinceRequired = _customerSettings.StateProvinceRequired; model.PhoneEnabled = _customerSettings.PhoneEnabled; model.PhoneRequired = _customerSettings.PhoneRequired; model.FaxEnabled = _customerSettings.FaxEnabled; model.FaxRequired = _customerSettings.FaxRequired; model.NewsletterEnabled = _customerSettings.NewsletterEnabled; model.UsernamesEnabled = _customerSettings.UsernamesEnabled; model.AllowUsersToChangeUsernames = _customerSettings.AllowUsersToChangeUsernames; model.CheckUsernameAvailabilityEnabled = _customerSettings.CheckUsernameAvailabilityEnabled; model.SignatureEnabled = _forumSettings.ForumsEnabled && _forumSettings.SignaturesEnabled; //external authentication model.NumberOfExternalAuthenticationProviders = _openAuthenticationService .LoadActiveExternalAuthenticationMethods(_workContext.CurrentCustomer, _storeContext.CurrentStore.Id).Count; foreach (var ear in _openAuthenticationService.GetExternalIdentifiersFor(customer)) { var authMethod = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName(ear.ProviderSystemName); if (authMethod == null || !authMethod.IsMethodActive(_externalAuthenticationSettings)) { continue; } model.AssociatedExternalAuthRecords.Add(new CustomerInfoModel.AssociatedExternalAuthModel { Id = ear.Id, Email = ear.Email, ExternalIdentifier = ear.ExternalIdentifier, AuthMethodName = authMethod.GetLocalizedFriendlyName(_localizationService, _workContext.WorkingLanguage.Id) }); } //custom customer attributes var customAttributes = PrepareCustomCustomerAttributes(customer, overrideCustomCustomerAttributesXml); customAttributes.ForEach(model.CustomerAttributes.Add); return(model); }
public ActionResult Login(string returnUrl) { var processor = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName("ExternalAuth.OpenId"); if (processor == null || !processor.IsMethodActive(_externalAuthenticationSettings) || !processor.PluginDescriptor.Installed) { throw new NopException("OpenID module cannot be loaded"); } if (!_openIdProviderAuthorizer.IsOpenIdCallback) { var viewModel = new LoginModel(); TryUpdateModel(viewModel); _openIdProviderAuthorizer.EnternalIdentifier = viewModel.ExternalIdentifier; } var result = _openIdProviderAuthorizer.Authorize(returnUrl); switch (result.AuthenticationStatus) { case OpenAuthenticationStatus.Error: { if (!result.Success) { foreach (var error in result.Errors) { ExternalAuthorizerHelper.AddErrorsToDisplay(error); } } return(new RedirectResult(Url.LogOn(returnUrl))); } case OpenAuthenticationStatus.AssociateOnLogon: { return(new RedirectResult(Url.LogOn(returnUrl))); } case OpenAuthenticationStatus.AutoRegisteredEmailValidation: { //result return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.EmailValidation })); } case OpenAuthenticationStatus.AutoRegisteredAdminApproval: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.AdminApproval })); } case OpenAuthenticationStatus.AutoRegisteredStandard: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Standard })); } default: break; } if (result.Result != null) { return(result.Result); } return(HttpContext.Request.IsAuthenticated ? new RedirectResult(!string.IsNullOrEmpty(returnUrl) ? returnUrl : "~/") : new RedirectResult(Url.LogOn(returnUrl))); }
/// <summary> /// Prepare the customer info model /// </summary> /// <param name="model">Customer info model</param> /// <param name="customer">Customer</param> /// <param name="excludeProperties">Whether to exclude populating of model properties from the entity</param> /// <param name="overrideCustomCustomerAttributesXml">Overridden customer attributes in XML format; pass null to use CustomCustomerAttributes of customer</param> /// <returns>Customer info model</returns> public virtual UserInfoModel PrepareCustomerInfoModel(UserInfoModel model, User customer, bool excludeProperties, string overrideCustomCustomerAttributesXml = "") { if (model == null) { throw new ArgumentNullException("model"); } if (customer == null) { throw new ArgumentNullException("customer"); } model.AllowCustomersToSetTimeZone = _dateTimeSettings.AllowCustomersToSetTimeZone; foreach (var tzi in _dateTimeHelper.GetSystemTimeZones()) { model.AvailableTimeZones.Add(new SelectListItem { Text = tzi.DisplayName, Value = tzi.Id, Selected = (excludeProperties ? tzi.Id == model.TimeZoneId : tzi.Id == _dateTimeHelper.CurrentTimeZone.Id) }); } if (!excludeProperties) { model.VatNumber = customer.GetAttribute <string>(SystemUserAttributeNames.VatNumber); model.FirstName = customer.GetAttribute <string>(SystemUserAttributeNames.FirstName); model.LastName = customer.GetAttribute <string>(SystemUserAttributeNames.LastName); model.Gender = customer.GetAttribute <string>(SystemUserAttributeNames.Gender); var dateOfBirth = customer.GetAttribute <DateTime?>(SystemUserAttributeNames.DateOfBirth); if (dateOfBirth.HasValue) { model.DateOfBirthDay = dateOfBirth.Value.Day; model.DateOfBirthMonth = dateOfBirth.Value.Month; model.DateOfBirthYear = dateOfBirth.Value.Year; } model.Company = customer.GetAttribute <string>(SystemUserAttributeNames.Company); model.StreetAddress = customer.GetAttribute <string>(SystemUserAttributeNames.StreetAddress); model.StreetAddress2 = customer.GetAttribute <string>(SystemUserAttributeNames.StreetAddress2); model.ZipPostalCode = customer.GetAttribute <string>(SystemUserAttributeNames.ZipPostalCode); model.City = customer.GetAttribute <string>(SystemUserAttributeNames.City); model.CountryId = customer.GetAttribute <int>(SystemUserAttributeNames.CountryId); model.StateProvinceId = customer.GetAttribute <int>(SystemUserAttributeNames.StateProvinceId); model.Phone = customer.GetAttribute <string>(SystemUserAttributeNames.Phone); model.Fax = customer.GetAttribute <string>(SystemUserAttributeNames.Fax); //newsletter model.Signature = customer.GetAttribute <string>(SystemUserAttributeNames.Signature); model.Email = customer.Email; model.Username = customer.Username; } else { if (_customerSettings.UsernamesEnabled && !_customerSettings.AllowUsersToChangeUsernames) { model.Username = customer.Username; } } if (_customerSettings.UserRegistrationType == UserRegistrationType.EmailValidation) { model.EmailToRevalidate = customer.EmailToRevalidate; } model.GenderEnabled = _customerSettings.GenderEnabled; model.DateOfBirthEnabled = _customerSettings.DateOfBirthEnabled; model.DateOfBirthRequired = _customerSettings.DateOfBirthRequired; model.CompanyEnabled = _customerSettings.CompanyEnabled; model.CompanyRequired = _customerSettings.CompanyRequired; model.StreetAddressEnabled = _customerSettings.StreetAddressEnabled; model.StreetAddressRequired = _customerSettings.StreetAddressRequired; model.StreetAddress2Enabled = _customerSettings.StreetAddress2Enabled; model.StreetAddress2Required = _customerSettings.StreetAddress2Required; model.ZipPostalCodeEnabled = _customerSettings.ZipPostalCodeEnabled; model.ZipPostalCodeRequired = _customerSettings.ZipPostalCodeRequired; model.CityEnabled = _customerSettings.CityEnabled; model.CityRequired = _customerSettings.CityRequired; model.CountryEnabled = _customerSettings.CountryEnabled; model.CountryRequired = _customerSettings.CountryRequired; model.StateProvinceEnabled = _customerSettings.StateProvinceEnabled; model.StateProvinceRequired = _customerSettings.StateProvinceRequired; model.PhoneEnabled = _customerSettings.PhoneEnabled; model.PhoneRequired = _customerSettings.PhoneRequired; model.FaxEnabled = _customerSettings.FaxEnabled; model.FaxRequired = _customerSettings.FaxRequired; model.NewsletterEnabled = _customerSettings.NewsletterEnabled; model.UsernamesEnabled = _customerSettings.UsernamesEnabled; model.AllowUsersToChangeUsernames = _customerSettings.AllowUsersToChangeUsernames; model.CheckUsernameAvailabilityEnabled = _customerSettings.CheckUsernameAvailabilityEnabled; //external authentication model.NumberOfExternalAuthenticationProviders = _openAuthenticationService .LoadActiveExternalAuthenticationMethods(_workContext.CurrentUser, 0).Count; foreach (var ear in _openAuthenticationService.GetExternalIdentifiersFor(customer)) { var authMethod = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName(ear.ProviderSystemName); if (authMethod == null || !authMethod.IsMethodActive(_externalAuthenticationSettings)) { continue; } model.AssociatedExternalAuthRecords.Add(new UserInfoModel.AssociatedExternalAuthModel { Id = ear.Id, Email = ear.Email, ExternalIdentifier = ear.ExternalIdentifier, AuthMethodName = authMethod.GetLocalizedFriendlyName(_localizationService, _workContext.WorkingLanguage.Id) }); } //custom customer attributes var customAttributes = PrepareCustomCustomerAttributes(customer, overrideCustomCustomerAttributesXml); customAttributes.ForEach(model.CustomerAttributes.Add); return(model); }
public ActionResult Login(string returnUrl) { var processor = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName(Provider.SystemName, _services.StoreContext.CurrentStore.Id); if (processor == null || !processor.IsMethodActive(_externalAuthenticationSettings)) { throw new SmartException("Twitter module cannot be loaded"); } var viewModel = new LoginModel(); TryUpdateModel(viewModel); var result = _oAuthProviderTwitterAuthorizer.Authorize(returnUrl); switch (result.AuthenticationStatus) { case OpenAuthenticationStatus.Error: { if (!result.Success) { foreach (var error in result.Errors) { NotifyError(error); } } return(new RedirectResult(Url.LogOn(returnUrl))); } case OpenAuthenticationStatus.AssociateOnLogon: { return(new RedirectResult(Url.LogOn(returnUrl))); } case OpenAuthenticationStatus.AutoRegisteredEmailValidation: { //result return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.EmailValidation })); } case OpenAuthenticationStatus.AutoRegisteredAdminApproval: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.AdminApproval })); } case OpenAuthenticationStatus.AutoRegisteredStandard: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Standard })); } default: break; } if (result.Result != null) { return(result.Result); } return(HttpContext.Request.IsAuthenticated ? new RedirectResult(!string.IsNullOrEmpty(returnUrl) ? returnUrl : "~/") : new RedirectResult(Url.LogOn(returnUrl))); }
/// <summary> /// Load external authentication method by system name /// </summary> /// <param name="systemName">System name</param> /// <returns>Found external authentication method</returns> public IExternalAuthenticationMethod LoadExternalAuthenticationMethodBySystemName(string systemName) { return(_openAuthenticationService.LoadExternalAuthenticationMethodBySystemName(systemName)); }