integrate reCaptcha into sciNote

This commit is contained in:
Mojca Lorber 2016-11-22 14:57:41 +01:00
parent c5bc3a4dc6
commit 60f23b109b
6 changed files with 27 additions and 0 deletions

View file

@ -12,6 +12,7 @@ gem 'sass-rails', '~> 5.0'
gem 'bootstrap_form'
gem 'yomu'
gem 'font-awesome-rails', '~> 4.6'
gem 'recaptcha', require: 'recaptcha/rails'
# JS datetime library, requirement of datetime picker
gem 'momentjs-rails', '>= 2.9.0'

View file

@ -1,5 +1,6 @@
class Users::RegistrationsController < Devise::RegistrationsController
before_action :load_paperclip_vars
prepend_before_action :check_captcha, only: [:create]
def avatar
user = User.find_by_id(params[:id]) || current_user
@ -253,6 +254,15 @@ class Users::RegistrationsController < Devise::RegistrationsController
private
def check_captcha
if Rails.configuration.x.enable_recaptcha
unless verify_recaptcha
self.resource = resource_class.new sign_up_params
respond_with_navigational(resource) { render :new }
end
end
end
# Redirect to login page after signing up
def after_sign_up_path_for(resource)
new_user_session_path

View file

@ -38,6 +38,13 @@
<span><small><%= t 'users.registrations.new.team_name_help' %></small></span>
</div>
<% if Rails.configuration.x.enable_recaptcha %>
<div class="form-group">
<%= recaptcha_tags %>
<%= flash[:recaptcha_error] %>
</div>
<% end %>
<div class="form-group">
<%= f.submit "Sign up", class: "btn btn-primary" %>
</div>

View file

@ -68,4 +68,7 @@ Rails.application.configure do
# Enable first-time tutorial for users signing in the sciNote for
# the first time.
config.x.enable_tutorial = ENV["ENABLE_TUTORIAL"] == "true"
# Enable reCAPTCHA
config.x.enable_recaptcha = ENV["ENABLE_RECAPTCHA"] == "true"
end

View file

@ -101,4 +101,7 @@ Rails.application.configure do
# Enable first-time tutorial for users signing in the sciNote for
# the first time.
config.x.enable_tutorial = ENV["ENABLE_TUTORIAL"] != "false"
# Enable reCAPTCHA
config.x.enable_recaptcha = ENV["ENABLE_RECAPTCHA"] == "true"
end

View file

@ -68,4 +68,7 @@ Rails.application.configure do
# Enable first-time tutorial for users signing in the sciNote for
# the first time.
config.x.enable_tutorial = false
# Enable reCAPTCHA
config.x.enable_recaptcha = true
end