public async Task <ActionResult> OnPost() { if (ModelState.IsValid) { if (Input?.Password != _config.Value.AdminPassword) { ModelState.AddModelError("Input.Password", "Wrong password."); } else { var contact = await _ontraContacts.SelectAsync(Input.Email).ConfigureAwait(false); if (contact == null) { ModelState.AddModelError("Input.Email", "Contact not found in Ontraport."); } else { _ontraPostForms.ServerPost("p2c20557f60", new ApiCustomContact() { Email = Input.Email, GodConnectionNotes = Input.Notes }.GetChanges()); return(new LocalRedirectResult("/coaching-sent")); } } } return(Page()); }
public async Task <ActionResult> OnPost() { if (ModelState.IsValid) { if (Input?.Password != _config.Value.AdminPassword) { ModelState.AddModelError("Input.Password", "Wrong password."); } else { var contact = await _ontraContacts.SelectAsync(Input.Email).ConfigureAwait(false); if (contact?.Id == null) { ModelState.AddModelError("Input.Email", "Contact not found in Ontraport."); } else { await _ontraReadings.CreateAsync(new ApiReading() { ContactId = contact.Id, PictureFileName = contact.PictureFileName, EnergyReading = Input.EnergyReading.Replace("\n", "\n<br />", System.StringComparison.InvariantCulture), DistanceHealing = Input.DistanceHealing.Replace("\n", "\n<br />", System.StringComparison.InvariantCulture) }.GetChanges()).ConfigureAwait(false); await _ontraContacts.RemoveFromCampaignAsync(contact.Id.Value, 13).ConfigureAwait(false); // Product: Soul Alignment Reading return(new LocalRedirectResult("/coaching-sent")); } } } return(Page()); }
public async Task <ActionResult> OnPostAsync() { if (ModelState.IsValid) { if (Input?.Password != _config.Value.AdminPassword) { ModelState.AddModelError("Input.Password", "Wrong password."); } else { var uploadFileName = ""; if (Input.Recording != null) { var fileExt = Path.GetExtension(Input.Recording.FileName).ToUpperInvariant(); var validExt = new[] { ".MP3", ".M4A", ".ZIP" }; if (!validExt.Contains(fileExt)) { ModelState.AddModelError("Input.Recording", "File must be in MP3, M4A or ZIP format."); } else { var now = _dateService.Now; uploadFileName = $"{now:yyyy-MM-dd} {Input.Email}{fileExt}"; await _formHelper.UploadFileAsync(Input.Recording, _config.Value.UploadRecordingsPath, uploadFileName).ConfigureAwait(false); } } if (ModelState.IsValid) { var contact = await _ontraContacts.SelectAsync(Input.Email).ConfigureAwait(false); if (contact?.Id == null) { ModelState.AddModelError("Input.Email", "Contact not found in Ontraport."); } else if (contact.CoachingCallsLeft <= 0) { ModelState.AddModelError("Input.Email", "Contact has no coaching calls left."); } else { await _ontraRecordings.CreateAsync(new ApiRecording() { ContactId = contact.Id, FileName = uploadFileName }.GetChanges()).ConfigureAwait(false); contact.CoachingCallsLeft -= 1; contact.LastCoachingDate = _dateTimeService.UtcNowOffset; await _ontraContacts.UpdateAsync(contact.Id.Value, contact.GetChanges()).ConfigureAwait(false); return(new LocalRedirectResult("/coaching-sent")); } } } } return(Page()); }
// *** 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); }
public Task <ApplicationUser> FindByEmailAsync(string normalizedEmail, CancellationToken cancellationToken) { ApplicationUser applicationUser = new ApplicationUser(); ApiCustomContact customer = _ontraportContacts.SelectAsync(normalizedEmail).Result; if (customer != null) { if (customer.Data.Count() > 0) { if (customer.Email.ToUpper() == normalizedEmail) { applicationUser.UserName = customer.Email; applicationUser.Email = customer.Email; applicationUser.PasswordHash = customer.Password; applicationUser.UserRole = customer.UserRole; //applicationUser.FirstName = customer.FirstName; //applicationUser.LastName = customer.LastName; //applicationUser.Name = customer.FirstName + " " + customer.LastName; } } } return(Task.FromResult <ApplicationUser>(applicationUser)); }
public async Task <string> GetCustomerNameAndBirthday(string email) { var customer = await _ontraContacts.SelectAsync(email); return($"{customer.FirstNameField} {customer.LastNameField} - {customer.BirthdayField}"); }
/// <summary> /// Returns the Ontraport data for specified contact. /// </summary> /// <param name="contactId">The contact to retrieve information for.</param> /// <returns>The contact information.</returns> public async Task <ApiCustomContact> GetContactAsync(int contactId) => await _ontraContacts.SelectAsync(contactId).ConfigureAwait(false);