/// <summary> /// Prepare paged external authentication method list model /// </summary> /// <param name="searchModel">External authentication method search model</param> /// <returns>External authentication method list model</returns> public virtual ExternalAuthenticationMethodListModel PrepareExternalAuthenticationMethodListModel( ExternalAuthenticationMethodSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get external authentication methods var externalAuthenticationMethods = _externalAuthenticationService.LoadAllExternalAuthenticationMethods(); //prepare grid model var model = new ExternalAuthenticationMethodListModel { Data = externalAuthenticationMethods.PaginationByRequestModel(searchModel).Select(method => { //fill in model values from the entity var externalAuthenticationMethodModel = method.ToPluginModel <ExternalAuthenticationMethodModel>(); //fill in additional values (not existing in the entity) externalAuthenticationMethodModel.IsActive = _externalAuthenticationService.IsExternalAuthenticationMethodActive(method); externalAuthenticationMethodModel.ConfigurationUrl = method.GetConfigurationPageUrl(); return(externalAuthenticationMethodModel); }), Total = externalAuthenticationMethods.Count }; return(model); }
/// <summary> /// Prepare plugins enabled warning model /// </summary> /// <param name="models">List of system warning models</param> protected virtual void PreparePluginsEnabledWarningModel(List <SystemWarningModel> models) { var plugins = _pluginService.GetPlugins <IPlugin>(); var notEnabled = new List <string>(); foreach (var plugin in plugins) { var isEnabled = true; switch (plugin) { case IPaymentMethod paymentMethod: isEnabled = _paymentService.IsPaymentMethodActive(paymentMethod); break; case IShippingRateComputationMethod shippingRateComputationMethod: isEnabled = _shippingService.IsShippingRateComputationMethodActive(shippingRateComputationMethod); break; case IPickupPointProvider pickupPointProvider: isEnabled = _shippingService.IsPickupPointProviderActive(pickupPointProvider); break; case ITaxProvider _: isEnabled = plugin.PluginDescriptor.SystemName .Equals(_taxSettings.ActiveTaxProviderSystemName, StringComparison.InvariantCultureIgnoreCase); break; case IExternalAuthenticationMethod externalAuthenticationMethod: isEnabled = _externalAuthenticationService.IsExternalAuthenticationMethodActive(externalAuthenticationMethod); break; case IWidgetPlugin widgetPlugin: isEnabled = _widgetService.IsWidgetActive(widgetPlugin); break; case IExchangeRateProvider exchangeRateProvider: isEnabled = exchangeRateProvider.PluginDescriptor.SystemName == _currencySettings.ActiveExchangeRateProviderSystemName; break; } if (isEnabled) { continue; } notEnabled.Add(plugin.PluginDescriptor.FriendlyName); } if (notEnabled.Any()) { models.Add(new SystemWarningModel { Level = SystemWarningLevel.Warning, Text = $"{_localizationService.GetResource("Admin.System.Warnings.PluginNotEnabled")}: {string.Join(", ", notEnabled)}" }); } }
/// <summary> /// Prepare plugin model properties of the installed plugin /// </summary> /// <param name="model">Plugin model</param> /// <param name="plugin">Plugin</param> protected virtual void PrepareInstalledPluginModel(PluginModel model, IPlugin plugin) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (plugin == null) { throw new ArgumentNullException(nameof(plugin)); } //prepare configuration URL model.ConfigurationUrl = plugin.GetConfigurationPageUrl(); //prepare enabled/disabled (only for some plugin types) model.CanChangeEnabled = true; switch (plugin) { case IExternalAuthenticationMethod externalAuthenticationMethod: model.IsEnabled = _externalAuthenticationService.IsExternalAuthenticationMethodActive(externalAuthenticationMethod); break; case IWidgetPlugin widgetPlugin: model.IsEnabled = _widgetService.IsWidgetActive(widgetPlugin); break; default: model.CanChangeEnabled = false; break; } }
/// <summary> /// Prepare plugin model properties of the installed plugin /// </summary> /// <param name="model">Plugin model</param> /// <param name="plugin">Plugin</param> protected virtual void PrepareInstalledPluginModel(PluginModel model, IPlugin plugin) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (plugin == null) { throw new ArgumentNullException(nameof(plugin)); } //prepare configuration URL model.ConfigurationUrl = plugin.GetConfigurationPageUrl(); //prepare enabled/disabled (only for some plugin types) model.CanChangeEnabled = true; switch (plugin) { case IPaymentMethod paymentMethod: model.IsEnabled = _paymentService.IsPaymentMethodActive(paymentMethod); break; case IShippingRateComputationMethod shippingRateComputationMethod: model.IsEnabled = _shippingService.IsShippingRateComputationMethodActive(shippingRateComputationMethod); break; case IPickupPointProvider pickupPointProvider: model.IsEnabled = _shippingService.IsPickupPointProviderActive(pickupPointProvider); break; case ITaxProvider _: model.IsEnabled = plugin.PluginDescriptor.SystemName .Equals(_taxSettings.ActiveTaxProviderSystemName, StringComparison.InvariantCultureIgnoreCase); break; case IExternalAuthenticationMethod externalAuthenticationMethod: model.IsEnabled = _externalAuthenticationService.IsExternalAuthenticationMethodActive(externalAuthenticationMethod); break; case IWidgetPlugin widgetPlugin: model.IsEnabled = _widgetService.IsWidgetActive(widgetPlugin); break; default: model.CanChangeEnabled = false; break; } }
/// <summary> /// Prepare plugins enabled warning model /// </summary> /// <param name="models">List of system warning models</param> protected virtual void PreparePluginsEnabledWarningModel(List <SystemWarningModel> models) { var pluginDescriptors = _pluginFinder.GetPluginDescriptors(); var notEnabled = new List <string>(); foreach (var plugin in pluginDescriptors.Select(pd => pd.Instance())) { var isEnabled = true; switch (plugin) { case IExternalAuthenticationMethod externalAuthenticationMethod: isEnabled = _externalAuthenticationService.IsExternalAuthenticationMethodActive(externalAuthenticationMethod); break; case IWidgetPlugin widgetPlugin: isEnabled = _widgetService.IsWidgetActive(widgetPlugin); break; case IExchangeRateProvider exchangeRateProvider: isEnabled = exchangeRateProvider.PluginDescriptor.SystemName == _currencySettings.ActiveExchangeRateProviderSystemName; break; } if (isEnabled) { continue; } notEnabled.Add(plugin.PluginDescriptor.FriendlyName); } if (notEnabled.Any()) { models.Add(new SystemWarningModel { Level = SystemWarningLevel.Warning, Text = $"{_localizationService.GetResource("Admin.System.Warnings.PluginNotEnabled")}: {string.Join(", ", notEnabled)}" }); } }
public virtual IActionResult MethodUpdate(ExternalAuthenticationMethodModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageExternalAuthenticationMethods)) { return(AccessDeniedView()); } var eam = _externalAuthenticationService.LoadExternalAuthenticationMethodBySystemName(model.SystemName); if (_externalAuthenticationService.IsExternalAuthenticationMethodActive(eam)) { 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; //update the description file PluginManager.SavePluginDescriptor(pluginDescriptor); //reset plugin cache _pluginFinder.ReloadPlugins(pluginDescriptor); return(new NullJsonResult()); }
public virtual IActionResult EditPopup(PluginModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins)) { return(AccessDeniedView()); } //try to get a plugin with the specified system name var pluginDescriptor = _pluginFinder.GetPluginDescriptorBySystemName(model.SystemName, LoadPluginsMode.All); if (pluginDescriptor == null) { return(RedirectToAction("List")); } if (ModelState.IsValid) { //we allow editing of 'friendly name', 'display order', store mappings pluginDescriptor.FriendlyName = model.FriendlyName; pluginDescriptor.DisplayOrder = model.DisplayOrder; pluginDescriptor.LimitedToStores.Clear(); if (model.SelectedStoreIds.Any()) { pluginDescriptor.LimitedToStores = model.SelectedStoreIds; } pluginDescriptor.LimitedToCustomerRoles.Clear(); if (model.SelectedCustomerRoleIds.Any()) { pluginDescriptor.LimitedToCustomerRoles = model.SelectedCustomerRoleIds; } //update the description file PluginManager.SavePluginDescriptor(pluginDescriptor); //reset plugin cache _pluginFinder.ReloadPlugins(pluginDescriptor); //locales foreach (var localized in model.Locales) { _localizationService.SaveLocalizedFriendlyName(pluginDescriptor.Instance(), localized.LanguageId, localized.FriendlyName); } //enabled/disabled if (pluginDescriptor.Installed) { var pluginInstance = pluginDescriptor.Instance(); switch (pluginInstance) { case IPaymentMethod paymentMethod: if (_paymentService.IsPaymentMethodActive(paymentMethod) && !model.IsEnabled) { //mark as disabled _paymentSettings.ActivePaymentMethodSystemNames.Remove(pluginDescriptor.SystemName); _settingService.SaveSetting(_paymentSettings); break; } if (!_paymentService.IsPaymentMethodActive(paymentMethod) && model.IsEnabled) { //mark as enabled _paymentSettings.ActivePaymentMethodSystemNames.Add(pluginDescriptor.SystemName); _settingService.SaveSetting(_paymentSettings); } break; case IShippingRateComputationMethod shippingRateComputationMethod: if (_shippingService.IsShippingRateComputationMethodActive(shippingRateComputationMethod) && !model.IsEnabled) { //mark as disabled _shippingSettings.ActiveShippingRateComputationMethodSystemNames.Remove(pluginDescriptor.SystemName); _settingService.SaveSetting(_shippingSettings); break; } if (!_shippingService.IsShippingRateComputationMethodActive(shippingRateComputationMethod) && model.IsEnabled) { //mark as enabled _shippingSettings.ActiveShippingRateComputationMethodSystemNames.Add(pluginDescriptor.SystemName); _settingService.SaveSetting(_shippingSettings); } break; case IPickupPointProvider pickupPointProvider: if (_shippingService.IsPickupPointProviderActive(pickupPointProvider) && !model.IsEnabled) { //mark as disabled _shippingSettings.ActivePickupPointProviderSystemNames.Remove(pluginDescriptor.SystemName); _settingService.SaveSetting(_shippingSettings); break; } if (!_shippingService.IsPickupPointProviderActive(pickupPointProvider) && model.IsEnabled) { //mark as enabled _shippingSettings.ActivePickupPointProviderSystemNames.Add(pluginDescriptor.SystemName); _settingService.SaveSetting(_shippingSettings); } break; case ITaxProvider _: if (!model.IsEnabled) { //mark as disabled _taxSettings.ActiveTaxProviderSystemName = string.Empty; _settingService.SaveSetting(_taxSettings); break; } //mark as enabled _taxSettings.ActiveTaxProviderSystemName = model.SystemName; _settingService.SaveSetting(_taxSettings); break; case IExternalAuthenticationMethod externalAuthenticationMethod: if (_externalAuthenticationService.IsExternalAuthenticationMethodActive(externalAuthenticationMethod) && !model.IsEnabled) { //mark as disabled _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Remove(pluginDescriptor.SystemName); _settingService.SaveSetting(_externalAuthenticationSettings); break; } if (!_externalAuthenticationService.IsExternalAuthenticationMethodActive(externalAuthenticationMethod) && model.IsEnabled) { //mark as enabled _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames.Add(pluginDescriptor.SystemName); _settingService.SaveSetting(_externalAuthenticationSettings); } break; case IWidgetPlugin widgetPlugin: if (_widgetService.IsWidgetActive(widgetPlugin) && !model.IsEnabled) { //mark as disabled _widgetSettings.ActiveWidgetSystemNames.Remove(pluginDescriptor.SystemName); _settingService.SaveSetting(_widgetSettings); break; } if (!_widgetService.IsWidgetActive(widgetPlugin) && model.IsEnabled) { //mark as enabled _widgetSettings.ActiveWidgetSystemNames.Add(pluginDescriptor.SystemName); _settingService.SaveSetting(_widgetSettings); } break; } //activity log _customerActivityService.InsertActivity("EditPlugin", string.Format(_localizationService.GetResource("ActivityLog.EditPlugin"), pluginDescriptor.FriendlyName)); } ViewBag.RefreshPage = true; return(View(model)); } //prepare model model = _pluginModelFactory.PreparePluginModel(model, pluginDescriptor, true); //if we got this far, something failed, redisplay form return(View(model)); }
/// <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 CustomerInfoModel PrepareCustomerInfoModel(CustomerInfoModel model, Customer customer, bool excludeProperties, string overrideCustomCustomerAttributesXml = "") { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (customer == null) { throw new ArgumentNullException(nameof(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 = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.VatNumberAttribute); model.FirstName = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.FirstNameAttribute); model.LastName = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.LastNameAttribute); model.Gender = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.GenderAttribute); var dateOfBirth = _genericAttributeService.GetAttribute <DateTime?>(customer, NopCustomerDefaults.DateOfBirthAttribute); if (dateOfBirth.HasValue) { model.DateOfBirthDay = dateOfBirth.Value.Day; model.DateOfBirthMonth = dateOfBirth.Value.Month; model.DateOfBirthYear = dateOfBirth.Value.Year; } model.Company = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.CompanyAttribute); model.StreetAddress = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.StreetAddressAttribute); model.StreetAddress2 = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.StreetAddress2Attribute); model.ZipPostalCode = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.ZipPostalCodeAttribute); model.City = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.CityAttribute); model.County = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.CountyAttribute); model.CountryId = _genericAttributeService.GetAttribute <int>(customer, NopCustomerDefaults.CountryIdAttribute); model.StateProvinceId = _genericAttributeService.GetAttribute <int>(customer, NopCustomerDefaults.StateProvinceIdAttribute); model.Phone = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.PhoneAttribute); model.Fax = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.FaxAttribute); //newsletter var newsletter = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(customer.Email, _storeContext.CurrentStore.Id); model.Newsletter = newsletter != null && newsletter.Active; model.Signature = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.SignatureAttribute); 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 = _localizationService.GetLocalized(c, 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 = _localizationService.GetLocalized(s, x => x.Name), Value = s.Id.ToString(), Selected = (s.Id == model.StateProvinceId) }); } } else { var 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 = _localizationService.GetLocalizedEnum((VatNumberStatus)_genericAttributeService .GetAttribute <int>(customer, NopCustomerDefaults.VatNumberStatusIdAttribute)); 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.CountyEnabled = _customerSettings.CountyEnabled; model.CountyRequired = _customerSettings.CountyRequired; 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.AllowCustomersToRemoveAssociations = _externalAuthenticationSettings.AllowCustomersToRemoveAssociations; model.NumberOfExternalAuthenticationProviders = _externalAuthenticationService .LoadActiveExternalAuthenticationMethods(_workContext.CurrentCustomer, _storeContext.CurrentStore.Id).Count; foreach (var record in customer.ExternalAuthenticationRecords) { var authMethod = _externalAuthenticationService.LoadExternalAuthenticationMethodBySystemName(record.ProviderSystemName); if (authMethod == null || !_externalAuthenticationService.IsExternalAuthenticationMethodActive(authMethod)) { continue; } model.AssociatedExternalAuthRecords.Add(new CustomerInfoModel.AssociatedExternalAuthModel { Id = record.Id, Email = record.Email, ExternalIdentifier = !string.IsNullOrEmpty(record.ExternalDisplayIdentifier) ? record.ExternalDisplayIdentifier : record.ExternalIdentifier, AuthMethodName = _localizationService.GetLocalizedFriendlyName(authMethod, _workContext.WorkingLanguage.Id) }); } //custom customer attributes var customAttributes = PrepareCustomCustomerAttributes(customer, overrideCustomCustomerAttributesXml); foreach (var attribute in customAttributes) { model.CustomerAttributes.Add(attribute); } //GDPR if (_gdprSettings.GdprEnabled) { var consents = _gdprService.GetAllConsents().Where(consent => consent.DisplayOnCustomerInfoPage).ToList(); foreach (var consent in consents) { var accepted = _gdprService.IsConsentAccepted(consent.Id, _workContext.CurrentCustomer.Id); model.GdprConsents.Add(PrepareGdprConsentModel(consent, accepted.HasValue && accepted.Value)); } } return(model); }