From 90be431f4662f2643fe00aba4f8168aa9ac934d8 Mon Sep 17 00:00:00 2001 From: 7riumph Date: Thu, 13 Feb 2025 14:38:05 -0700 Subject: [PATCH] Validated emails are not blank and are properly formatted (regex) --- app/controllers/volunteers_controller.rb | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/controllers/volunteers_controller.rb b/app/controllers/volunteers_controller.rb index 519407c3fc..eafc8e5a85 100644 --- a/app/controllers/volunteers_controller.rb +++ b/app/controllers/volunteers_controller.rb @@ -32,14 +32,16 @@ def create authorize @volunteer if @volunteer.save - @volunteer.invite!(current_user) - # call short io api here - raw_token = @volunteer.raw_invitation_token - invitation_url = Rails.application.routes.url_helpers.accept_user_invitation_url(invitation_token: raw_token, host: request.base_url) - hash_of_short_urls = @volunteer.phone_number.blank? ? {0 => nil, 1 => nil} : handle_short_url([invitation_url, request.base_url + "/users/edit"]) - body_msg = account_activation_msg("volunteer", hash_of_short_urls) - sms_status = deliver_sms_to @volunteer, body_msg - redirect_to edit_volunteer_path(@volunteer), notice: sms_acct_creation_notice("volunteer", sms_status) + if is_valid_email?(@volunteer.email) + @volunteer.invite!(current_user) + # call short io api here + raw_token = @volunteer.raw_invitation_token + invitation_url = Rails.application.routes.url_helpers.accept_user_invitation_url(invitation_token: raw_token, host: request.base_url) + hash_of_short_urls = @volunteer.phone_number.blank? ? {0 => nil, 1 => nil} : handle_short_url([invitation_url, request.base_url + "/users/edit"]) + body_msg = account_activation_msg("volunteer", hash_of_short_urls) + sms_status = deliver_sms_to @volunteer, body_msg + redirect_to edit_volunteer_path(@volunteer), notice: sms_acct_creation_notice("volunteer", sms_status) + end else render :new, status: :unprocessable_entity end @@ -176,4 +178,9 @@ def send_sms_to(phone_number, body) "SMS was not sent to Volunteer due to an error." end end + + def is_valid_email?(email) + return false if email.blank? + email.match?(URI::MailTo::EMAIL_REGEXP) + end end