Exemplo n.º 1
0
        public async Task <bool> ConfirmOptinToken(string userId, string token)
        {
            var userOptinTokenData = TokenStore.Find <OptinTokenData>("UserId", userId).FirstOrDefault();

            if (userOptinTokenData == null)
            {
                return(false);
            }

            var confirmResult = await _userManager.VerifyUserTokenAsync(userId, MarketingEmailOptinPurpose, token);

            if (!confirmResult)
            {
                return(false);
            }

            // Update consent data to CustomerContact
            var user    = _userManager.FindById(userId);
            var contact = _customerContext.GetContactByUsername(user.UserName);

            UpdateOptin(contact, true);

            // Delete token data from DDS
            TokenStore.Delete(userOptinTokenData.Id);
            return(true);
        }
Exemplo n.º 2
0
        public CustomerContact CreateCustomerContact(SiteUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            CustomerContact contact = _customerContext.GetContactByUsername(user.UserName);

            if (contact == null)
            {
                contact = CustomerContact.CreateInstance();
                contact.PrimaryKeyId = new PrimaryKeyId(new Guid(user.Id));
                contact.UserId       = "String:" + user.Email; // The UserId needs to be set in the format "String:{email}". Else a duplicate CustomerContact will be created later on.
            }

            // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
            // Send an email with this link
            // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
            // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
            // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
            if (!String.IsNullOrEmpty(user.FirstName) || !String.IsNullOrEmpty(user.LastName))
            {
                contact.FullName = $"{user.FirstName} {user.LastName}";
            }

            contact.FirstName          = user.FirstName;
            contact.LastName           = user.LastName;
            contact.Email              = user.Email;
            contact.RegistrationSource = user.RegistrationSource;

            if (user.Addresses != null)
            {
                foreach (var address in user.Addresses)
                {
                    contact.AddContactAddress(address);
                }
            }

            // The contact, or more likely its related addresses, must be saved to the database before we can set the preferred
            // shipping and billing addresses. Using an address id before its saved will throw an exception because its value
            // will still be null.
            contact.SaveChanges();

            SetPreferredAddresses(contact);

            return(contact);
        }