Exemple #1
0
 /// <summary>
 /// Prepare the external authentication method model
 /// </summary>
 /// <returns>List of the external authentication method model</returns>
 public virtual List <ExternalAuthenticationMethodModel> PrepareExternalMethodsModel()
 {
     return(_externalAuthenticationService
            .LoadActiveExternalAuthenticationMethods(_workContext.CurrentUser)
            .Select(authenticationMethod => new ExternalAuthenticationMethodModel
     {
         ViewComponentName = authenticationMethod.GetPublicViewComponentName()
     }).ToList());
 }
        public IViewComponentResult Invoke()
        {
            var models = _externalAuthenticationService
                         .LoadActiveExternalAuthenticationMethods(_workContext.CurrentCustomer, _storeContext.CurrentStore.Id)
                         .Select(authenticationMethod =>
            {
                authenticationMethod.GetPublicViewComponent(out string viewComponentName);

                return(new ExternalAuthenticationMethodModel {
                    ViewComponentName = viewComponentName
                });
            }).ToList();

            return(View(models));
        }
        /// <summary>
        /// Prepare the external authentication method model
        /// </summary>
        /// <returns>List of the external authentication method model</returns>
        public virtual List <ExternalAuthenticationMethodModel> PrepareExternalMethodsModel()
        {
            var models = _externalAuthenticationService
                         .LoadActiveExternalAuthenticationMethods(_workContext.CurrentCustomer, 0)
                         .Select(authenticationMethod =>
            {
                authenticationMethod.GetPublicViewComponent(out string viewComponentName);

                return(new ExternalAuthenticationMethodModel
                {
                    ViewComponentName = viewComponentName
                });
            }).ToList();

            return(models);
        }
        private async Task PrepareExternalAuth(CustomerInfoModel model, GetInfo request)
        {
            model.NumberOfExternalAuthenticationProviders = _externalAuthenticationService
                                                            .LoadActiveExternalAuthenticationMethods(request.Customer, request.Store.Id).Count;
            foreach (var ear in await _externalAuthenticationService.GetExternalIdentifiersFor(request.Customer))
            {
                var authMethod = _externalAuthenticationService.LoadExternalAuthenticationMethodBySystemName(ear.ProviderSystemName);
                if (authMethod == null || !authMethod.IsMethodActive(_externalAuthenticationSettings))
                {
                    continue;
                }

                model.AssociatedExternalAuthRecords.Add(new CustomerInfoModel.AssociatedExternalAuthModel {
                    Id    = ear.Id,
                    Email = ear.Email,
                    ExternalIdentifier = ear.ExternalDisplayIdentifier,
                    AuthMethodName     = authMethod.GetLocalizedFriendlyName(_localizationService, request.Language.Id)
                });
            }
        }
Exemple #5
0
        public virtual async Task <CustomerInfoModel> PrepareInfoModel(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;
            if (model.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 = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.VatNumber);

                model.FirstName = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.FirstName);

                model.LastName = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.LastName);

                model.Gender = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.Gender);

                var dateOfBirth = await customer.GetAttribute <DateTime?>(_genericAttributeService, SystemCustomerAttributeNames.DateOfBirth);

                if (dateOfBirth.HasValue)
                {
                    model.DateOfBirthDay   = dateOfBirth.Value.Day;
                    model.DateOfBirthMonth = dateOfBirth.Value.Month;
                    model.DateOfBirthYear  = dateOfBirth.Value.Year;
                }
                model.Company = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.Company);

                model.StreetAddress = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.StreetAddress);

                model.StreetAddress2 = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.StreetAddress2);

                model.ZipPostalCode = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.ZipPostalCode);

                model.City = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.City);

                model.CountryId = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.CountryId);

                model.StateProvinceId = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.StateProvinceId);

                model.Phone = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.Phone);

                model.Fax = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.Fax);

                //newsletter
                var newsletter = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(customer.Email, _storeContext.CurrentStore.Id);

                if (newsletter == null)
                {
                    newsletter = await _newsLetterSubscriptionService.GetNewsLetterSubscriptionByCustomerId(customer.Id);
                }

                model.Newsletter = newsletter != null && newsletter.Active;

                var categories = (await _newsletterCategoryService.GetAllNewsletterCategory()).ToList();
                categories.ForEach(x => model.NewsletterCategories.Add(new NewsletterSimpleCategory()
                {
                    Id          = x.Id,
                    Description = x.GetLocalized(y => y.Description, _workContext.WorkingLanguage.Id),
                    Name        = x.GetLocalized(y => y.Name, _workContext.WorkingLanguage.Id),
                    Selected    = newsletter == null ? false : newsletter.Categories.Contains(x.Id),
                }));

                model.Signature = await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.Signature);

                model.Email    = customer.Email;
                model.Username = customer.Username;
            }
            else
            {
                if (_customerSettings.UsernamesEnabled && !_customerSettings.AllowUsersToChangeUsernames)
                {
                    model.Username = customer.Username;
                }
            }

            //countries and states
            if (_customerSettings.CountryEnabled)
            {
                model.AvailableCountries.Add(new SelectListItem {
                    Text = _localizationService.GetResource("Address.SelectCountry"), Value = ""
                });
                foreach (var c in await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id))
                {
                    model.AvailableCountries.Add(new SelectListItem
                    {
                        Text     = c.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id),
                        Value    = c.Id.ToString(),
                        Selected = c.Id == model.CountryId
                    });
                }

                if (_customerSettings.StateProvinceEnabled)
                {
                    //states
                    var states = await _stateProvinceService.GetStateProvincesByCountryId(model.CountryId, _workContext.WorkingLanguage.Id);

                    if (states.Any())
                    {
                        model.AvailableStates.Add(new SelectListItem {
                            Text = _localizationService.GetResource("Address.SelectState"), Value = ""
                        });

                        foreach (var s in states)
                        {
                            model.AvailableStates.Add(new SelectListItem {
                                Text = s.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id), 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 = ""
                        });
                    }
                }
            }
            model.DisplayVatNumber    = _taxSettings.EuVatEnabled;
            model.VatNumberStatusNote = ((VatNumberStatus)await customer.GetAttribute <int>(_genericAttributeService, 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 = _externalAuthenticationService
                                                            .LoadActiveExternalAuthenticationMethods(_workContext.CurrentCustomer, _storeContext.CurrentStore.Id).Count;
            foreach (var ear in await _externalAuthenticationService.GetExternalIdentifiersFor(customer))
            {
                var authMethod = _externalAuthenticationService.LoadExternalAuthenticationMethodBySystemName(ear.ProviderSystemName);
                if (authMethod == null || !authMethod.IsMethodActive(_externalAuthenticationSettings))
                {
                    continue;
                }

                model.AssociatedExternalAuthRecords.Add(new CustomerInfoModel.AssociatedExternalAuthModel
                {
                    Id    = ear.Id,
                    Email = ear.Email,
                    ExternalIdentifier = ear.ExternalDisplayIdentifier,
                    AuthMethodName     = authMethod.GetLocalizedFriendlyName(_localizationService, _workContext.WorkingLanguage.Id)
                });
            }

            //custom customer attributes
            var customAttributes = await PrepareCustomAttributes(customer, overrideCustomCustomerAttributesXml);

            foreach (var attribute in customAttributes)
            {
                model.CustomerAttributes.Add(attribute);
            }

            return(model);
        }
Exemple #6
0
        /// <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);
        }
Exemple #7
0
        /// <summary>
        /// Prepare the user info model
        /// </summary>
        /// <param name="model">User info model</param>
        /// <param name="user">User</param>
        /// <param name="excludeProperties">Whether to exclude populating of model properties from the entity</param>
        /// <param name="overrideCustomUserAttributesXml">Overridden user attributes in XML format; pass null to use CustomUserAttributes of user</param>
        /// <returns>User info model</returns>
        public virtual UserInfoModel PrepareUserInfoModel(UserInfoModel model, User user,
                                                          bool excludeProperties, string overrideCustomUserAttributesXml = "")
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            model.AllowUsersToSetTimeZone = _dateTimeSettings.AllowUsersToSetTimeZone;
            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>(user, NopUserDefaults.VatNumberAttribute);
                model.FirstName = _genericAttributeService.GetAttribute <string>(user, NopUserDefaults.FirstNameAttribute);
                model.LastName  = _genericAttributeService.GetAttribute <string>(user, NopUserDefaults.LastNameAttribute);
                model.Gender    = _genericAttributeService.GetAttribute <string>(user, NopUserDefaults.GenderAttribute);
                var dateOfBirth = _genericAttributeService.GetAttribute <DateTime?>(user, NopUserDefaults.DateOfBirthAttribute);
                if (dateOfBirth.HasValue)
                {
                    model.DateOfBirthDay   = dateOfBirth.Value.Day;
                    model.DateOfBirthMonth = dateOfBirth.Value.Month;
                    model.DateOfBirthYear  = dateOfBirth.Value.Year;
                }
                model.Company         = _genericAttributeService.GetAttribute <string>(user, NopUserDefaults.CompanyAttribute);
                model.StreetAddress   = _genericAttributeService.GetAttribute <string>(user, NopUserDefaults.StreetAddressAttribute);
                model.StreetAddress2  = _genericAttributeService.GetAttribute <string>(user, NopUserDefaults.StreetAddress2Attribute);
                model.ZipPostalCode   = _genericAttributeService.GetAttribute <string>(user, NopUserDefaults.ZipPostalCodeAttribute);
                model.City            = _genericAttributeService.GetAttribute <string>(user, NopUserDefaults.CityAttribute);
                model.County          = _genericAttributeService.GetAttribute <string>(user, NopUserDefaults.CountyAttribute);
                model.CountryId       = _genericAttributeService.GetAttribute <int>(user, NopUserDefaults.CountryIdAttribute);
                model.StateProvinceId = _genericAttributeService.GetAttribute <int>(user, NopUserDefaults.StateProvinceIdAttribute);
                model.Phone           = _genericAttributeService.GetAttribute <string>(user, NopUserDefaults.PhoneAttribute);
                model.Fax             = _genericAttributeService.GetAttribute <string>(user, NopUserDefaults.FaxAttribute);

                model.Signature = _genericAttributeService.GetAttribute <string>(user, NopUserDefaults.SignatureAttribute);

                model.Email    = user.Email;
                model.Username = user.Username;
            }
            else
            {
                if (_userSettings.UsernamesEnabled && !_userSettings.AllowUsersToChangeUsernames)
                {
                    model.Username = user.Username;
                }
            }

            if (_userSettings.UserRegistrationType == UserRegistrationType.EmailValidation)
            {
                model.EmailToRevalidate = user.EmailToRevalidate;
            }

            //countries and states
            if (_userSettings.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 (_userSettings.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.GenderEnabled                    = _userSettings.GenderEnabled;
            model.DateOfBirthEnabled               = _userSettings.DateOfBirthEnabled;
            model.DateOfBirthRequired              = _userSettings.DateOfBirthRequired;
            model.CompanyEnabled                   = _userSettings.CompanyEnabled;
            model.CompanyRequired                  = _userSettings.CompanyRequired;
            model.StreetAddressEnabled             = _userSettings.StreetAddressEnabled;
            model.StreetAddressRequired            = _userSettings.StreetAddressRequired;
            model.StreetAddress2Enabled            = _userSettings.StreetAddress2Enabled;
            model.StreetAddress2Required           = _userSettings.StreetAddress2Required;
            model.ZipPostalCodeEnabled             = _userSettings.ZipPostalCodeEnabled;
            model.ZipPostalCodeRequired            = _userSettings.ZipPostalCodeRequired;
            model.CityEnabled                      = _userSettings.CityEnabled;
            model.CityRequired                     = _userSettings.CityRequired;
            model.CountyEnabled                    = _userSettings.CountyEnabled;
            model.CountyRequired                   = _userSettings.CountyRequired;
            model.CountryEnabled                   = _userSettings.CountryEnabled;
            model.CountryRequired                  = _userSettings.CountryRequired;
            model.StateProvinceEnabled             = _userSettings.StateProvinceEnabled;
            model.StateProvinceRequired            = _userSettings.StateProvinceRequired;
            model.PhoneEnabled                     = _userSettings.PhoneEnabled;
            model.PhoneRequired                    = _userSettings.PhoneRequired;
            model.FaxEnabled                       = _userSettings.FaxEnabled;
            model.FaxRequired                      = _userSettings.FaxRequired;
            model.UsernamesEnabled                 = _userSettings.UsernamesEnabled;
            model.AllowUsersToChangeUsernames      = _userSettings.AllowUsersToChangeUsernames;
            model.CheckUsernameAvailabilityEnabled = _userSettings.CheckUsernameAvailabilityEnabled;


            //external authentication
            model.AllowUsersToRemoveAssociations          = _externalAuthenticationSettings.AllowUsersToRemoveAssociations;
            model.NumberOfExternalAuthenticationProviders = _externalAuthenticationService
                                                            .LoadActiveExternalAuthenticationMethods(_workContext.CurrentUser).Count;


            //custom user attributes
            var customAttributes = PrepareCustomUserAttributes(user, overrideCustomUserAttributesXml);

            foreach (var attribute in customAttributes)
            {
                model.UserAttributes.Add(attribute);
            }

            return(model);
        }