mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-12-09 05:37:36 +08:00
integrate reCaptcha into sciNote
This commit is contained in:
parent
c5bc3a4dc6
commit
60f23b109b
6 changed files with 27 additions and 0 deletions
1
Gemfile
1
Gemfile
|
|
@ -12,6 +12,7 @@ gem 'sass-rails', '~> 5.0'
|
||||||
gem 'bootstrap_form'
|
gem 'bootstrap_form'
|
||||||
gem 'yomu'
|
gem 'yomu'
|
||||||
gem 'font-awesome-rails', '~> 4.6'
|
gem 'font-awesome-rails', '~> 4.6'
|
||||||
|
gem 'recaptcha', require: 'recaptcha/rails'
|
||||||
|
|
||||||
# JS datetime library, requirement of datetime picker
|
# JS datetime library, requirement of datetime picker
|
||||||
gem 'momentjs-rails', '>= 2.9.0'
|
gem 'momentjs-rails', '>= 2.9.0'
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
class Users::RegistrationsController < Devise::RegistrationsController
|
class Users::RegistrationsController < Devise::RegistrationsController
|
||||||
before_action :load_paperclip_vars
|
before_action :load_paperclip_vars
|
||||||
|
prepend_before_action :check_captcha, only: [:create]
|
||||||
|
|
||||||
def avatar
|
def avatar
|
||||||
user = User.find_by_id(params[:id]) || current_user
|
user = User.find_by_id(params[:id]) || current_user
|
||||||
|
|
@ -253,6 +254,15 @@ class Users::RegistrationsController < Devise::RegistrationsController
|
||||||
|
|
||||||
private
|
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
|
# Redirect to login page after signing up
|
||||||
def after_sign_up_path_for(resource)
|
def after_sign_up_path_for(resource)
|
||||||
new_user_session_path
|
new_user_session_path
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,13 @@
|
||||||
<span><small><%= t 'users.registrations.new.team_name_help' %></small></span>
|
<span><small><%= t 'users.registrations.new.team_name_help' %></small></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% if Rails.configuration.x.enable_recaptcha %>
|
||||||
|
<div class="form-group">
|
||||||
|
<%= recaptcha_tags %>
|
||||||
|
<%= flash[:recaptcha_error] %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<%= f.submit "Sign up", class: "btn btn-primary" %>
|
<%= f.submit "Sign up", class: "btn btn-primary" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -68,4 +68,7 @@ Rails.application.configure do
|
||||||
# Enable first-time tutorial for users signing in the sciNote for
|
# Enable first-time tutorial for users signing in the sciNote for
|
||||||
# the first time.
|
# the first time.
|
||||||
config.x.enable_tutorial = ENV["ENABLE_TUTORIAL"] == "true"
|
config.x.enable_tutorial = ENV["ENABLE_TUTORIAL"] == "true"
|
||||||
|
|
||||||
|
# Enable reCAPTCHA
|
||||||
|
config.x.enable_recaptcha = ENV["ENABLE_RECAPTCHA"] == "true"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -101,4 +101,7 @@ Rails.application.configure do
|
||||||
# Enable first-time tutorial for users signing in the sciNote for
|
# Enable first-time tutorial for users signing in the sciNote for
|
||||||
# the first time.
|
# the first time.
|
||||||
config.x.enable_tutorial = ENV["ENABLE_TUTORIAL"] != "false"
|
config.x.enable_tutorial = ENV["ENABLE_TUTORIAL"] != "false"
|
||||||
|
|
||||||
|
# Enable reCAPTCHA
|
||||||
|
config.x.enable_recaptcha = ENV["ENABLE_RECAPTCHA"] == "true"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -68,4 +68,7 @@ Rails.application.configure do
|
||||||
# Enable first-time tutorial for users signing in the sciNote for
|
# Enable first-time tutorial for users signing in the sciNote for
|
||||||
# the first time.
|
# the first time.
|
||||||
config.x.enable_tutorial = false
|
config.x.enable_tutorial = false
|
||||||
|
|
||||||
|
# Enable reCAPTCHA
|
||||||
|
config.x.enable_recaptcha = true
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue