Beispiel #1
0
 public async Task AddOrMergeContact(string email, string firstName, string lastName)
 {
     var contact = new ApiContact()
     {
         Email     = email,
         FirstName = firstName,
         LastName  = lastName
     };
     await _ontraContacts.CreateOrMergeAsync(contact.GetChanges());
 }
Beispiel #2
0
        // *** IUserStore ***

        /// <summary>
        /// Creates the specified user in the user store.
        /// </summary>
        /// <param name="user">The user to create.</param>
        /// <param name="cancellationToken">The CancellationToken used to propagate notifications that the operation should be canceled.</param>
        /// <returns>An IdentityResult containing the creation result.</returns>
        /// <exception cref="System.Net.Http.HttpRequestException">An HTTP error occured while communicating with Ontraport.</exception>
        /// <exception cref="System.OperationCanceledException">The task timed out or was cancelled.</exception>
        public async Task <IdentityResult> CreateAsync(TUser user, CancellationToken cancellationToken)
        {
            user.CheckNotNull(nameof(user));
            user.NormalizedUserName.CheckNotNullOrEmpty(nameof(user.NormalizedUserName));
            user.PasswordHash.CheckNotNullOrEmpty(nameof(user.PasswordHash));
            // user.UserRole.CheckNotNullOrEmpty(nameof(user.UserRole));

            // Check if user account already exists.
            var contact = await _ontraportContacts.SelectAsync(user.NormalizedUserName, cancellationToken).ConfigureAwait(false);

            if (!string.IsNullOrEmpty(contact?.IdentityPasswordHash))
            {
                return(IdentityResult.Failed(new IdentityError()
                {
                    Description = "There is already an account with that email address."
                }));
            }

            // Add password hash.
            contact = new TContact()
            {
                Email = user.NormalizedUserName.ToLowerInvariant(), // store email as lowercase
                IdentityPasswordHash         = user.PasswordHash,
                IdentityAccessFailedCount    = user.AccessFailedCount,
                IdentityLockoutEnd           = user.LockoutEnd,
                IdentityLockoutEnabled       = user.LockoutEnabled,
                IdentityTwoFactorEnabled     = user.TwoFactorEnabled,
                IdentityEmailConfirmed       = user.EmailConfirmed,
                IdentityPhoneNumberConfirmed = user.PhoneNumberConfirmed,
                IdentitySecurityStamp        = user.SecurityStamp
            };
            if (user.PhoneNumber.HasValue())
            {
                contact.IdentityPhoneNumber = user.PhoneNumber;
            }

            var newContact = await _ontraportContacts.CreateOrMergeAsync(contact.GetChanges(), cancellationToken).ConfigureAwait(false);

            if (newContact?.Id != null)
            {
                // Get the ID of the updated contact.
                user.Id = newContact.Id.Value;
            }
            return(IdentityResult.Success);
        }
Beispiel #3
0
        public Task <IdentityResult> CreateAsync(ApplicationUser user, CancellationToken cancellationToken)
        {
            IdentityResult identityResult = new IdentityResult();
            var            userOntraPort  = new ApiCustomContact()
            {
                Email = user.Email,
                //FirstName = user.PasswordHash,
                ////LastName = user.LastName,
                Password = user.PasswordHash,
                UserRole = user.UserRole
            };

            try
            {
                var result = _ontraportContacts.CreateOrMergeAsync(userOntraPort.GetChanges()).Result;
                return(Task.FromResult <IdentityResult>(identityResult));
            }

            catch (Exception ex)
            {
            }
            return(Task.FromResult <IdentityResult>(null));
        }