public static async Task <bool> SignUpAsync(HttpContextBase context, string tenant, Registration model, RemoteUser user) { if (model.Password != model.ConfirmPassword) { throw new PasswordConfirmException(I18N.PasswordsDoNotMatch); } if (model.Email != model.ConfirmEmail) { throw new PasswordConfirmException(I18N.EmailsDoNotMatch); } model.Browser = user.Browser; model.IpAddress = user.IpAddress; var registration = model.Adapt <DTO.Registration>(); registration.Password = PasswordManager.GetHashedPassword(model.Email, model.Password); string registrationId = (await Registrations.RegisterAsync(tenant, registration).ConfigureAwait(false)).ToString(); if (string.IsNullOrWhiteSpace(registrationId)) { return(false); } var email = new SignUpEmail(context, registration, registrationId); await email.SendAsync(tenant).ConfigureAwait(false); return(true); }
public static async Task <bool> SignUp(Registration model, RemoteUser user) { if (model.Password != model.ConfirmPassword) { throw new PasswordConfirmException("Passwords do not match."); } if (model.Email != model.ConfirmEmail) { throw new PasswordConfirmException("Emails do not match."); } model.Browser = user.Browser; model.IpAddress = user.IpAddress; var registration = model.Adapt <DTO.Registration>(); registration.Password = PasswordManager.GetHashedPassword(model.Password); string registrationId = Registrations.Register(registration).ToString(); if (string.IsNullOrWhiteSpace(registrationId)) { return(false); } var email = new SignUpEmail(registration, registrationId); await email.SendAsync(); return(true); }
public async Task <IActionResult> OnPostAsync(int id) { ModelState.Clear(); // Clear the validation errors, will validate manually later. if (string.IsNullOrWhiteSpace(Registration.UserId)) { ModelState.AddModelError("UserId", "User field is required."); return(await OnGetAsync(id)); } // Check if user exists with email registered, and create new user if not. var user = await _userManager.FindByIdAsync(Registration.UserId); if (user == null) { // This shouldn't happen, because a registration can only // be created for existing users. ModelState.AddModelError(string.Empty, "Invalid user selected."); return(await OnGetAsync(id)); } Registration.ParticipantName = user.Name; Registration.Email = user.Email; Registration.Phone = user.PhoneNumber; EventInfo = await _eventsService.GetEventInfoByIdAsync(id, new EventInfoRetrievalOptions { LoadProducts = true }); if (EventInfo == null) { return(NotFound()); } Registration.EventInfoId = id; Registration.UserId = user.Id; // Any registrations for this user on this event? var registration = await _registrations.GetAsync(Registration.UserId, Registration.EventInfoId); if (registration != null) { ModelState.AddModelError(string.Empty, "Bruker var allerede registrert"); return(await OnGetAsync(id)); } // Validate the VM if (!TryValidateModel(Registration)) { ModelState.AddModelError(string.Empty, "Please check the form before submitting."); return(await OnGetAsync(id)); } // Create registration for our user var newRegistration = Registration.Adapt <Registration>(); await _registrations.CreateRegistration(newRegistration); await _db.SaveChangesAsync(); return(RedirectToPage("./Details", new { id = id })); }
public async Task <IActionResult> OnPostAsync(int id) { if (!ModelState.IsValid) { PaymentMethods = await _paymentMethodService.GetActivePaymentMethodsAsync(); return(Page()); } // Sanitization of input if (!string.IsNullOrWhiteSpace(Registration.ParticipantName)) { Registration.ParticipantName = Regex.Replace(Registration.ParticipantName, "<.*?>", String.Empty); } if (!string.IsNullOrWhiteSpace(Registration.Email)) { Registration.Email = Regex.Replace(Registration.Email, "<.*?>", String.Empty); } if (!string.IsNullOrWhiteSpace(Registration.PhoneCountryCode)) { Registration.PhoneCountryCode = Regex.Replace(Registration.PhoneCountryCode, "<.*?>", String.Empty); } if (!string.IsNullOrWhiteSpace(Registration.Phone)) { Registration.Phone = Regex.Replace(Registration.Phone, "<.*?>", String.Empty); } if (!string.IsNullOrWhiteSpace(Registration.ParticipantJobTitle)) { Registration.ParticipantJobTitle = Regex.Replace(Registration.ParticipantJobTitle, "<.*?>", String.Empty); } if (!string.IsNullOrWhiteSpace(Registration.ParticipantCity)) { Registration.ParticipantCity = Regex.Replace(Registration.ParticipantCity, "<.*?>", String.Empty); } if (!string.IsNullOrWhiteSpace(Registration.Notes)) { Registration.Notes = Regex.Replace(Registration.Notes, "<.*?>", String.Empty); } if (!string.IsNullOrWhiteSpace(Registration.CustomerVatNumber)) { Registration.CustomerVatNumber = Regex.Replace(Registration.CustomerVatNumber, "<.*?>", String.Empty); } if (!string.IsNullOrWhiteSpace(Registration.CustomerName)) { Registration.CustomerName = Regex.Replace(Registration.CustomerName, "<.*?>", String.Empty); } if (!string.IsNullOrWhiteSpace(Registration.CustomerEmail)) { Registration.CustomerEmail = Regex.Replace(Registration.CustomerEmail, "<.*?>", String.Empty); } if (!string.IsNullOrWhiteSpace(Registration.CustomerInvoiceReference)) { Registration.CustomerInvoiceReference = Regex.Replace(Registration.CustomerInvoiceReference, "<.*?>", String.Empty); } if (!string.IsNullOrWhiteSpace(Registration.CustomerZip)) { Registration.CustomerZip = Regex.Replace(Registration.CustomerZip, "<.*?>", String.Empty); } if (!string.IsNullOrWhiteSpace(Registration.CustomerCity)) { Registration.CustomerCity = Regex.Replace(Registration.CustomerCity, "<.*?>", String.Empty); } if (!string.IsNullOrWhiteSpace(Registration.CustomerCountry)) { Registration.CustomerCountry = Regex.Replace(Registration.CustomerCountry, "<.*?>", String.Empty); } EventInfo = await _eventsService.GetWithProductsAsync(id); if (EventInfo == null) { return(NotFound()); } Registration.EventInfoId = EventInfo.EventInfoId; // Check if user exists with email registered var user = await _userManager.FindByEmailAsync(Registration.Email); if (user != null) { Registration.UserId = user.Id; _logger.LogInformation("Found existing user."); // Any registrations for this user on this event? var existingRegistration = await _registrationService.GetAsync(user.Id, Registration.EventInfoId); if (existingRegistration != null) { // The user has already registered for the event. await _registrationEmailSender.SendRegistrationAsync(user.Email, "Du var allerede påmeldt!", "<p>Vi hadde allerede en registrering for deg.</p>", existingRegistration.RegistrationId); return(RedirectToPage("/Info/EmailSent")); } } else { // Create new user var newUser = new ApplicationUser { UserName = Registration.Email, Name = Registration.ParticipantName, Email = Registration.Email, PhoneNumber = (Registration.PhoneCountryCode + Registration.Phone) }; var result = await _userManager.CreateAsync(newUser); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); Registration.UserId = newUser.Id; user = newUser; } else { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } PaymentMethods = await _paymentMethodService.GetActivePaymentMethodsAsync(); return(Page()); } } // If we came here, we should enter our new participant into the database! _logger.LogInformation("Starting new registration:"); var newRegistration = Registration.Adapt <Registration>(); newRegistration.VerificationCode = PasswordHelper.GeneratePassword(6); await _registrationService.CreateRegistration(newRegistration, Registration.SelectedProducts); await _registrationEmailSender.SendRegistrationAsync(user.Email, "Velkommen på kurs!", "<p>Vi fikk registreringen din</p>", newRegistration.RegistrationId); return(RedirectToPage("/Info/EmailSent")); }