-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle newsletter subscriptions on the server side
- protect them using altcha captcha
- Loading branch information
Showing
8 changed files
with
38 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class NewsletterSubscriptionsController < ApplicationController | ||
|
||
def subscribe | ||
email, altcha = subscription_params | ||
if AltchaSolution.verify_and_save(altcha) | ||
SubscribeToNewsletterJob.perform_later(email, 'NewsletterSubscription') | ||
respond_to do |format| | ||
format.js { render :success} | ||
end | ||
else | ||
respond_to do |format| | ||
format.js { render :altcha_failure, status: :unprocessable_entity} | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def subscription_params | ||
params.require([:email, :altcha]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%= form_tag newsletter_subscribe_path, method: :post, remote: true, id: "newsletter-form" do |f| %> | ||
<%= email_field_tag :email, '', class: 'govuk-input sdn-footer__newsletter-input', placeholder: "Zadajte emailovú adresu", autocomplete: :email %> | ||
<%= submit_tag 'Prihlásiť', class: 'govuk-button sdn-footer__newsletter-button' %> | ||
<altcha-widget hidelogo hidefooter strings="<%= JSON.dump({ 'label': 'Nie som robot', 'verifying': 'Overujem...', 'verified': 'Overené'}) %>" challengeurl="<%= altcha_url() %>"></altcha-widget> | ||
<div class="newsletter-altcha-error"></div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
$('#newsletter-form').replaceWith('<%=j render partial: 'newsletter_subscriptions/form', object: @group %>'); | ||
$('.newsletter-altcha-error').html('Nie sme si isti, či nie ste robot... zaškrtli ste, že nie ste?'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
$('#newsletter-success').show(); | ||
if ($('#newsletter-warning').is(':visible')) { | ||
$('#newsletter-warning').hide(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters