GRN2-125: Added a configurable reCAPTCHA on sign up (#502)

* Added a configurable reCAPTCHA on sign up

* Added missing code
This commit is contained in:
farhatahmad
2019-05-07 09:21:04 -04:00
committed by Jesus Federico
parent f6dd3d34eb
commit 75f48f4979
8 changed files with 39 additions and 3 deletions

View File

@ -31,8 +31,15 @@ class UsersController < ApplicationController
@user = User.new(user_params)
@user.provider = @user_domain
# Handle error on user creation.
render(:new) && return unless @user.save
# Add validation errors to model if they exist
valid_user = @user.valid?
valid_captcha = config.recaptcha_enabled ? verify_recaptcha(model: @user) : true
if valid_user && valid_captcha
@user.save
else
render(:new) && return
end
# Sign in automatically if email verification is disabled.
login(@user) && return unless Rails.configuration.enable_email_verification

View File

@ -17,4 +17,7 @@
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
module UsersHelper
def recaptcha_enabled?
config.recaptcha_enabled
end
end

View File

@ -70,8 +70,13 @@
</div>
<% end %>
<div class="card-footer px-0 pb-0">
<% if recaptcha_enabled? %>
<div class="form-group">
<%= recaptcha_tags %>
<div class="invalid-feedback d-block"><%= @user.errors.full_messages_for(:base).first %></div>
</div>
<% end %>
<%= f.submit t("signup.title"), class: "btn btn-primary btn-block signin-button" %>
<%= link_to t("cancel"), root_path, class: "btn btn-secondary btn-block signin-button" %>
</div>
<% end %>
</div>