-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ECO-124 Captcha na registracie #97
Open
michal-rohacek
wants to merge
16
commits into
master
Choose a base branch
from
ECO-124/captcha
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+207
−95
Open
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0d18e35
Add and configure recaptcha gem
michal-rohacek 7726cc8
Add registration resource
michal-rohacek 6da4fa7
Expand registration form onto other controllers
michal-rohacek 5df2234
Refine code a bit
michal-rohacek fbe5ee9
Localize labels
michal-rohacek b9859c5
Refactor api_host a bit
michal-rohacek 7cbef38
Finalize registration forms and captcha mechanism
michal-rohacek ff7cc03
Add newlines
michal-rohacek dd18af4
Delete unnecessary lines
michal-rohacek 41c8766
Change how Registration (sub)classes are resolved
michal-rohacek 51bb993
Merge branch 'master' into ECO-124/captcha
michal-rohacek 4ffa498
Fix dotenv files to make tests pass
michal-rohacek 26d02dc
Add recaptcha keys for local testing purposes
michal-rohacek 10832c8
Refine controller a tiny bit
michal-rohacek 1e227f8
Refine and/or simplify few method calls
michal-rohacek d95d1de
Revert some changes
michal-rohacek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Finalize registration forms and captcha mechanism
- Loading branch information
commit 7cbef38be486353d1676f0a5218029bf9faeb5f3
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 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 |
---|---|---|
@@ -1,25 +1,21 @@ | ||
module RegistrationsHelper | ||
def registration_form_id(service = controller_name) | ||
"#{service}_registration_form" | ||
def recaptcha_action(service = controller_name) | ||
"#{service}_registration" | ||
end | ||
|
||
def recaptcha_action | ||
"#{controller_name}_registration" | ||
end | ||
def new_registration(args) | ||
raise unless args[:service] | ||
|
||
def controller_specific_register_path | ||
polymorphic_path([:services, controller_name, :index]) | ||
klass = (args[:service] == 'autoform') ? AutoformRegistration : Registration | ||
klass.new(args) | ||
end | ||
|
||
def render_registration_form(service: controller_name, registration: nil) | ||
registration ||= Registration.new(service: service) | ||
|
||
if registration.valid?(:render) | ||
render partial: 'registrations/form', object: registration | ||
def render_registration_form(service: controller_name, model: nil) | ||
unless model | ||
model = new_registration(service: service) | ||
return if model.invalid?(:render) | ||
end | ||
end | ||
|
||
def translate_field(field_name) | ||
translate "registrations.#{field_name}", default: '' | ||
render partial: 'registrations/form', object: model | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class AutoformRegistration < Registration | ||
EXTRA_FIELDS = { domain: 'entry.591019594' }.freeze | ||
|
||
attr_accessor :domain | ||
validates :domain, presence: true, on: :submit | ||
michal-rohacek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def user_input_fields | ||
super.append(:domain) | ||
end | ||
|
||
def mapping | ||
super.merge(EXTRA_FIELDS) | ||
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 |
---|---|---|
@@ -1,37 +1,35 @@ | ||
<div class="row" id="<%= registration_form_id %>"> | ||
<div class="col-md-12"> | ||
<%= form_with model: form do |f| %> | ||
<% if form.errors.any? %> | ||
<% form.errors.values.flatten.each do |message| %> | ||
<%= render 'services/share/flash_message', { type: :alert, message: message } %> | ||
<div id="<%= form.html_id %>"> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<%= form_with model: form, scope: :registration do |f| %> | ||
<% if form.errors.any? %> | ||
<% form.errors.full_messages.each do |message| %> | ||
<%= render 'services/share/flash_message', { type: :alert, message: message } %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
|
||
<% if form.checkbox_captcha %> | ||
<%= recaptcha_tags(site_key: ENV.fetch('RECAPTCHA_SITE_KEY_V2_CHECKBOX')) %> | ||
<% else %> | ||
<%= recaptcha_v3(action: recaptcha_action) %> | ||
<% end %> | ||
<%= recaptcha_v3(action: recaptcha_action(form.service)) %> | ||
|
||
<div class="form-group"> | ||
<% form.mappings.keys.each do |field| %> | ||
<div class="row"> | ||
<%= f.label field, translate_field(field), class: 'control-label' %> | ||
<div class="row"> | ||
<% form.user_input_fields.each do |field| %> | ||
<div class="col-md-3"> | ||
<%= f.text_field field, class: 'form-control input-lg' %> | ||
<div class="form-group"> | ||
<%= f.label field, t(field), class: 'control-label' %> | ||
<%= f.text_field field, class: 'form-control input-lg' %> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
|
||
<%= f.hidden_field :service, value: form.service %> | ||
<%= f.hidden_field :checkbox_captcha, value: form.checkbox_captcha %> | ||
<%= f.hidden_field :service %> | ||
|
||
<div class="col-md-4 col-md-pad"> | ||
<%= button_tag :submit, class: 'btn btn-default btn-lg btn-strong', id: 'submit-button' do %> | ||
<strong>Zaregistrovať</strong> | ||
<% end %> | ||
<div class="col-md-4 col-md-pad"> | ||
<%= label_tag :a, ' '.html_safe %><br> | ||
<%= button_tag :submit, class: 'btn btn-default btn-lg btn-strong', id: 'submit-button' do %> | ||
<strong>Zaregistrovať</strong> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
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 |
---|---|---|
@@ -1 +1 @@ | ||
$('#<%= registration_form_id(@registration.service) %>').html("<%= j render partial: 'registrations/form', object: @registration %>"); | ||
$('#<%= @registration.html_id %>').replaceWith("<%= j render 'services/share/flash_message', { type: :notice, message: 'Ďakujeme za Váš záujem. Budeme Vás kontaktovať cez zadaný email.' } %>"); |
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 @@ | ||
$('#<%= @registration.html_id %>').replaceWith('<%= j render_registration_form(model: @registration) %>'); |
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 |
---|---|---|
|
@@ -80,32 +80,6 @@ | |
<p class="lead"> | ||
Nechajte nám Váš emailový kontakt alebo nám napíšte na <a href="mailto:[email protected]">[email protected]</a>. <em>Tešíme sa na spoluprácu.</em> | ||
</p> | ||
|
||
<div id="sk-api-error" style="display: none;"> | ||
<%= render 'services/share/flash_message', {type: :alert, message: 'Vyplňte prosím email a skúste znova.'} %> | ||
</div> | ||
<div id="sk-api-form-sent" style="display: none;"> | ||
<%= render 'services/share/flash_message', {type: :notice, message: 'Ďakujeme, za Váš záujem. Budeme Vás kontaktovať cez zadaný email.'} %> | ||
</div> | ||
|
||
<!-- <iframe name="form-result" style="display: none;"></iframe>--> | ||
<!-- <div class="row">--> | ||
<%#= form_tag 'https://docs.google.com/forms/d/e/1FAIpQLSfUuAjnqGjDvSc-Miy6bP0xODXsjr6g04hGAeYlYkJo-3Iu1Q/formResponse', target: 'form-result', id: 'sk-api-form' do %> | ||
<!-- <div class="col-md-3 col-md-pad">--> | ||
<!-- <div class="form-group">--> | ||
<%#= label_tag 'emailAddress', 'Email', class: 'control-label' %> | ||
<%#= email_field_tag 'emailAddress', nil, class: 'form-control input-lg', id: 'sk-api-email' %> | ||
<!-- </div>--> | ||
<!-- </div>--> | ||
<!-- <div class="col-md-4 col-md-pad">--> | ||
<!-- <%#= label_tag :a, ' '.html_safe %> <br>--> | ||
<%#= button_tag id: 'submit_to_datahub', class: 'btn btn-default btn-lg btn-strong' do %> | ||
<!-- <strong>Odoslať</strong>--> | ||
<%# end %> | ||
<!-- </div>--> | ||
<%# end %> | ||
<!-- </div>--> | ||
|
||
<%= render_registration_form %> | ||
</section> | ||
|
||
|
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 |
---|---|---|
|
@@ -43,6 +43,7 @@ | |
end | ||
|
||
resources :registrations | ||
resources :autoform_registrations, controller: :registrations, path: 'registrations' | ||
|
||
resource 'open_data', path: 'otvorene-data' | ||
resource 'open_api', path: 'otvorene-api' | ||
|
@@ -72,8 +73,8 @@ | |
get '422', to: 'errors#unacceptable' | ||
get '500', to: 'errors#internal_error' | ||
|
||
# redirect all /api request to to datahub.ekosystem | ||
match '/api/(*endpoint)', to: redirect(host: 'datahub.ekosystem.slovensko.digital'), via: :all | ||
# redirect all /api request to proper datahub.ekosystem api | ||
match '/api/(*endpoint)', to: redirect(host: Environment.api_host), via: :all | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rozmyslam, ze na co toto tu vobec mame. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. napadaju ma len historicke dovody alebo zbludile requesty |
||
|
||
# backward compatibility for generating url in views | ||
concern :syncable do | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co robi ten block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
block sa pusti medzi validaciou fieldov (ak je nevalidny email/iny field, ani neposielame captcha request) a medzi finalnym registracnym POSTom
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Toto je velmi zvlastny pattern, ja by som skor vytiahol von ten block aj ten post do controllera.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nechcem rypat ale
#97 (comment)
... teda, potom je
save
zbytocne nie?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mozno taketo cosi jedine. ale to asi nesedi na ten tvoj pattern ktory som linkol vyssie

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No patterny su dva. bud sa to udeje v controlleri alebo v save. Ty si spravil nieco medzi co nebude fungovat ked tam ten block nedas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Podla mna ten druhy pattern pouzime. Nech sa to deje v controlleri.