Skip to content

Commit

Permalink
Validated emails are not blank and are properly formatted (regex)
Browse files Browse the repository at this point in the history
  • Loading branch information
7riumph committed Feb 13, 2025
1 parent e650607 commit 90be431
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions app/controllers/volunteers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 90be431

Please sign in to comment.