public ActionResult ExternalMethods() { var model = new List <ExternalAuthenticationMethodModel>(); foreach (var eam in _openAuthenticationService.LoadActiveExternalAuthenticationMethods(_storeContext.CurrentStore.Id)) { var eamModel = new ExternalAuthenticationMethodModel(); string actionName; string controllerName; RouteValueDictionary routeValues; eam.Value.GetPublicInfoRoute(out actionName, out controllerName, out routeValues); eamModel.ActionName = actionName; eamModel.ControllerName = controllerName; eamModel.RouteValues = routeValues; model.Add(eamModel); } return(PartialView(model)); }
/// <summary> /// Prepare the external authentication method model /// </summary> /// <returns>List of the external authentication method model</returns> public virtual List <ExternalAuthenticationMethodModel> PrepareExternalMethodsModel() { var model = new List <ExternalAuthenticationMethodModel>(); foreach (var eam in _openAuthenticationService .LoadActiveExternalAuthenticationMethods(_workContext.CurrentCustomer, _storeContext.CurrentStore.Id)) { var eamModel = new ExternalAuthenticationMethodModel(); string actionName; string controllerName; RouteValueDictionary routeValues; eam.GetPublicInfoRoute(out actionName, out controllerName, out routeValues); eamModel.ActionName = actionName; eamModel.ControllerName = controllerName; eamModel.RouteValues = routeValues; model.Add(eamModel); } return(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); }
/// <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); }
/// <summary> /// Load active external authentication methods /// </summary> /// <param name="customer">Load records allowed only to a specified customer; pass null to ignore ACL permissions</param> /// <param name="storeId">Load records allowed only in a specified store; pass 0 to load all records</param> /// <returns>Payment methods</returns> public IList <IExternalAuthenticationMethod> LoadActiveExternalAuthenticationMethods(Customer customer = null, int storeId = 0) { return(_openAuthenticationService.LoadActiveExternalAuthenticationMethods(customer, storeId)); }