Skip to content

Commit

Permalink
Mark confirmation link as used after mail has been delivered
Browse files Browse the repository at this point in the history
  • Loading branch information
karlerikounapuu committed Sep 2, 2020
1 parent 73c3cec commit af9f973
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/controllers/contact_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def redirect_to_main
end

def show
if @contact_request.confirm_email
if @contact_request.confirmable?
redirect_to edit_contact_request_url
else
redirect_to root_url, alert: t('contact_requests.already_used')
Expand All @@ -51,12 +51,14 @@ def edit; end
def update
email_body = params[:email_body]
recipients = params[:recipients]
@contact_request.confirm_email

if @contact_request.send_contact_email(body: email_body, recipients: recipients)
logger.warn(
"Email sent to #{@contact_request.whois_record.name} contacts " \
"from #{@contact_request.email} (IP: #{request.ip})"
)

render :request_completed
else
redirect_to(:root, alert: t('contact_requests.something_went_wrong'))
Expand Down
7 changes: 3 additions & 4 deletions app/models/contact_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def completed_or_expired?
status == STATUS_SENT || !still_valid? || !whois_record_exists?
end

def confirmable?
status == STATUS_NEW && still_valid? && whois_record_exists?
end
private

def extract_emails_for_recipients(recipients)
Expand All @@ -83,10 +86,6 @@ def sendable?
status == STATUS_CONFIRMED && still_valid? && whois_record_exists?
end

def confirmable?
status == STATUS_NEW && still_valid? && whois_record_exists?
end

def still_valid?
valid_to >= Time.zone.now
end
Expand Down

0 comments on commit af9f973

Please sign in to comment.