reject email addresses with spaces, catch mailer delivery errors

This commit is contained in:
joshua stein 2012-09-07 09:24:29 -05:00
parent 1987a24a2a
commit f0bc4e7c8d
2 changed files with 11 additions and 6 deletions

View file

@ -6,11 +6,16 @@ class InvitationsController < ApplicationController
i.user_id = @user.id
i.email = params[:email]
i.memo = params[:memo]
if i.save
i.send_email
flash[:success] = "Successfully e-mailed invitation to " <<
params[:email].to_s << "."
else
begin
if i.save
i.send_email
flash[:success] = "Successfully e-mailed invitation to " <<
params[:email].to_s << "."
else
raise
end
rescue
flash[:error] = "Could not send invitation, verify the e-mail " <<
"address is valid."
end

View file

@ -4,7 +4,7 @@ class Invitation < ActiveRecord::Base
attr_accessible nil
validate do
if !email.to_s.match(/\A[^@]+@[^@]+\.[^@]+\z/)
if !email.to_s.match(/\A[^@ ]+@[^ @]+\.[^ @]+\z/)
errors.add(:email, "is not valid")
end
end