示例#1
0
        public async Task Handle(RegisteredByExternalMethodEventHandler eventMessage, CancellationToken cancellationToken)
        {
            if (eventMessage?.Customer == null || eventMessage.AuthenticationParameters == null)
            {
                return;
            }

            //handle event only for this authentication method
            if (!eventMessage.AuthenticationParameters.ProviderSystemName.Equals(FacebookAuthenticationDefaults.ProviderSystemName))
            {
                return;
            }

            //store some of the customer fields
            var firstName = eventMessage.AuthenticationParameters.Claims?.FirstOrDefault(claim => claim.Type == ClaimTypes.GivenName)?.Value;

            if (!string.IsNullOrEmpty(firstName))
            {
                await _userFieldService.SaveField(eventMessage.Customer, SystemCustomerFieldNames.FirstName, firstName);
            }

            var lastName = eventMessage.AuthenticationParameters.Claims?.FirstOrDefault(claim => claim.Type == ClaimTypes.Surname)?.Value;

            if (!string.IsNullOrEmpty(lastName))
            {
                await _userFieldService.SaveField(eventMessage.Customer, SystemCustomerFieldNames.LastName, lastName);
            }

            //notifications for admin
            if (_customerSettings.NotifyNewCustomerRegistration)
            {
                await _messageProviderService.SendCustomerRegisteredMessage(eventMessage.Customer, _workContext.CurrentStore, _workContext.WorkingLanguage.Id);
            }

            //send welcome message
            if (eventMessage.RegistrationResult.Success)
            {
                await _messageProviderService.SendCustomerWelcomeMessage(eventMessage.Customer, _workContext.CurrentStore, _workContext.WorkingLanguage.Id);
            }
        }