Merge pull request #4659 from jaywink/simple-captca-for-signup-page
Simple captca for signup page
This commit is contained in:
commit
70f74dc972
16 changed files with 189 additions and 57 deletions
|
|
@ -76,6 +76,7 @@ For more details see https://wiki.diasporafoundation.org/Updating
|
||||||
* Add actions on aspects on the contact page [#4570](https://github.com/diaspora/diaspora/pull/4570)
|
* Add actions on aspects on the contact page [#4570](https://github.com/diaspora/diaspora/pull/4570)
|
||||||
* Added a statistics route with general pod information, and if enabled in pod settings, total user, half year/monthly active users and local post counts [#4602](https://github.com/diaspora/diaspora/pull/4602)
|
* Added a statistics route with general pod information, and if enabled in pod settings, total user, half year/monthly active users and local post counts [#4602](https://github.com/diaspora/diaspora/pull/4602)
|
||||||
* Add indication about markdown formatting in the publisher [#4589](https://github.com/diaspora/diaspora/pull/4589)
|
* Add indication about markdown formatting in the publisher [#4589](https://github.com/diaspora/diaspora/pull/4589)
|
||||||
|
* Add captcha to signup form [#4659](https://github.com/diaspora/diaspora/pull/4659)
|
||||||
|
|
||||||
## Gem updates
|
## Gem updates
|
||||||
* selenium-webdriver 2.34.0 -> 2.39.0
|
* selenium-webdriver 2.34.0 -> 2.39.0
|
||||||
|
|
|
||||||
4
Gemfile
4
Gemfile
|
|
@ -15,6 +15,10 @@ gem 'json', '1.8.0'
|
||||||
|
|
||||||
gem 'devise', '3.0.2'
|
gem 'devise', '3.0.2'
|
||||||
|
|
||||||
|
# Captcha
|
||||||
|
|
||||||
|
gem 'galetahub-simple_captcha', '0.1.5', :require => 'simple_captcha'
|
||||||
|
|
||||||
# Background processing
|
# Background processing
|
||||||
|
|
||||||
gem 'sidekiq', '2.17.0'
|
gem 'sidekiq', '2.17.0'
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,7 @@ GEM
|
||||||
rspec (~> 2.0)
|
rspec (~> 2.0)
|
||||||
rspec-instafail (~> 0.2.0)
|
rspec-instafail (~> 0.2.0)
|
||||||
ruby-progressbar (~> 1.0)
|
ruby-progressbar (~> 1.0)
|
||||||
|
galetahub-simple_captcha (0.1.5)
|
||||||
gherkin (2.12.0)
|
gherkin (2.12.0)
|
||||||
multi_json (~> 1.3)
|
multi_json (~> 1.3)
|
||||||
gon (4.1.1)
|
gon (4.1.1)
|
||||||
|
|
@ -448,6 +449,7 @@ DEPENDENCIES
|
||||||
foreigner (= 1.4.2)
|
foreigner (= 1.4.2)
|
||||||
foreman (= 0.62)
|
foreman (= 0.62)
|
||||||
fuubar (= 1.1.1)
|
fuubar (= 1.1.1)
|
||||||
|
galetahub-simple_captcha (= 0.1.5)
|
||||||
gon (= 4.1.1)
|
gon (= 4.1.1)
|
||||||
guard-cucumber (= 1.4.0)
|
guard-cucumber (= 1.4.0)
|
||||||
guard-rspec (= 3.0.2)
|
guard-rspec (= 3.0.2)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class RegistrationsController < Devise::RegistrationsController
|
||||||
@user = User.build(user_params)
|
@user = User.build(user_params)
|
||||||
@user.process_invite_acceptence(invite) if invite.present?
|
@user.process_invite_acceptence(invite) if invite.present?
|
||||||
|
|
||||||
if @user.save
|
if @user.sign_up
|
||||||
flash[:notice] = I18n.t 'registrations.create.success'
|
flash[:notice] = I18n.t 'registrations.create.success'
|
||||||
@user.seed_aspects
|
@user.seed_aspects
|
||||||
sign_in_and_redirect(:user, @user)
|
sign_in_and_redirect(:user, @user)
|
||||||
|
|
@ -56,6 +56,6 @@ class RegistrationsController < Devise::RegistrationsController
|
||||||
helper_method :invite
|
helper_method :invite
|
||||||
|
|
||||||
def user_params
|
def user_params
|
||||||
params.require(:user).permit(:username, :email, :getting_started, :password, :password_confirmation, :language, :disable_mail, :invitation_service, :invitation_identifier, :show_community_spotlight_in_stream, :auto_follow_back, :auto_follow_back_aspect_id, :remember_me)
|
params.require(:user).permit(:username, :email, :getting_started, :password, :password_confirmation, :language, :disable_mail, :invitation_service, :invitation_identifier, :show_community_spotlight_in_stream, :auto_follow_back, :auto_follow_back_aspect_id, :remember_me, :captcha, :captcha_key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ class User < ActiveRecord::Base
|
||||||
include Querying
|
include Querying
|
||||||
include SocialActions
|
include SocialActions
|
||||||
|
|
||||||
|
apply_simple_captcha :message => I18n.t('simple_captcha.message.failed'), :add_to_base => true
|
||||||
|
|
||||||
scope :logged_in_since, lambda { |time| where('last_sign_in_at > ?', time) }
|
scope :logged_in_since, lambda { |time| where('last_sign_in_at > ?', time) }
|
||||||
scope :monthly_actives, lambda { |time = Time.now| logged_in_since(time - 1.month) }
|
scope :monthly_actives, lambda { |time = Time.now| logged_in_since(time - 1.month) }
|
||||||
scope :daily_actives, lambda { |time = Time.now| logged_in_since(time - 1.day) }
|
scope :daily_actives, lambda { |time = Time.now| logged_in_since(time - 1.day) }
|
||||||
|
|
@ -476,6 +478,14 @@ class User < ActiveRecord::Base
|
||||||
self.save(:validate => false)
|
self.save(:validate => false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sign_up
|
||||||
|
if AppConfig.settings.captcha.enable?
|
||||||
|
save_with_captcha
|
||||||
|
else
|
||||||
|
save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def clearable_fields
|
def clearable_fields
|
||||||
self.attributes.keys - ["id", "username", "encrypted_password",
|
self.attributes.keys - ["id", "username", "encrypted_password",
|
||||||
|
|
|
||||||
|
|
@ -2,70 +2,77 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="span4" id="image-container">
|
<div class="span4" id="image-container">
|
||||||
<%= image_tag('signupimages@2x_mini.jpg', :id => "collage") %>
|
<%= image_tag('signupimages@2x_mini.jpg', :id => "collage") %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="span8">
|
<div class="span8">
|
||||||
<h1 id="create-something-text">
|
<h1 id="create-something-text">
|
||||||
<%= t('.hey_make').html_safe %>
|
<%= t('.hey_make').html_safe %>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<h3 id="diaspora-hearts">
|
<h3 id="diaspora-hearts">
|
||||||
<%= t('.diaspora') %>
|
<%= t('.diaspora') %>
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
<h4 id="sign-up-text">
|
<h4 id="sign-up-text">
|
||||||
<%= t('.sign_up') %>
|
<%= t('.sign_up') %>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
<%= form_for(resource, :validate => true, :url => registration_path(resource_name), :html => {:class => "form-horizontal block-form", :autocomplete => "off"}) do |f| %>
|
<%= form_for(resource, :validate => true, :url => registration_path(resource_name), :html => {:class => "form-horizontal block-form", :autocomplete => "off"}) do |f| %>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label" for="user_email">
|
<label class="control-label" for="user_email">
|
||||||
<%= t('.email') %>
|
<%= t('.email') %>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<%= f.email_field :email, :placeholder => "luke@hoth.net", :title => t('registrations.new.enter_email'), :required => true %>
|
<%= f.email_field :email, :placeholder => "luke@hoth.net", :title => t('registrations.new.enter_email'), :required => true %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label" for="user_username">
|
<label class="control-label" for="user_username">
|
||||||
<%= t('.username') %>
|
<%= t('.username') %>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<%= f.text_field :username, :placeholder => "jedi_guy", :title => t('registrations.new.enter_username'), :required => true, :pattern => "[A-Za-z0-9_]+" %>
|
<%= f.text_field :username, :placeholder => "jedi_guy", :title => t('registrations.new.enter_username'), :required => true, :pattern => "[A-Za-z0-9_]+" %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label" for="user_password">
|
<label class="control-label" for="user_password">
|
||||||
<%= t('.password') %>
|
<%= t('.password') %>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<%= f.password_field :password, :placeholder => "••••••••", :title => t('registrations.new.enter_password'), :required => true, :pattern => "......+" %>
|
<%= f.password_field :password, :placeholder => "••••••••", :title => t('registrations.new.enter_password'), :required => true, :pattern => "......+" %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label" for="user_password_confirmation">
|
<label class="control-label" for="user_password_confirmation">
|
||||||
<%= t('.password_confirmation') %>
|
<%= t('.password_confirmation') %>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<%= f.password_field :password_confirmation, :placeholder => "••••••••", :title => t('registrations.new.enter_password_again'), :required => true, :pattern => "......+" %>
|
<%= f.password_field :password_confirmation, :placeholder => "••••••••", :title => t('registrations.new.enter_password_again'), :required => true, :pattern => "......+" %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<%= invite_hidden_tag(invite) %>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<%= f.submit t('.continue'), :class => "new-btn", :disable_with => t('.submitting') %>
|
<% if AppConfig.settings.captcha.enable? %>
|
||||||
<% end %>
|
<div class="control-group" id="captcha">
|
||||||
</div>
|
<%= show_simple_captcha(:object => 'user', :code_type => 'numeric') %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<%= invite_hidden_tag(invite) %>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
|
||||||
|
<%= f.submit t('.continue'), :class => "new-btn", :disable_with => t('.submitting') %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,9 @@
|
||||||
.controls
|
.controls
|
||||||
= f.password_field :password_confirmation, :placeholder => "••••••••"
|
= f.password_field :password_confirmation, :placeholder => "••••••••"
|
||||||
|
|
||||||
|
- if AppConfig.settings.captcha.enable?
|
||||||
|
= show_simple_captcha(:object => 'user', :code_type => 'numeric')
|
||||||
|
|
||||||
.controls
|
.controls
|
||||||
= f.submit t('registrations.new.create_my_account'), :class => 'btn primary', :disable_with => t('registrations.new.submitting')
|
= f.submit t('registrations.new.create_my_account'), :class => 'btn primary', :disable_with => t('registrations.new.submitting')
|
||||||
= link_to t('devise.sessions.new.sign_in'), new_user_session_path(), :class => 'btn primary', :style => "float: right;"
|
= link_to t('devise.sessions.new.sign_in'), new_user_session_path(), :class => 'btn primary', :style => "float: right;"
|
||||||
|
|
|
||||||
4
app/views/simple_captcha/_simple_captcha.haml
Normal file
4
app/views/simple_captcha/_simple_captcha.haml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
.control-label
|
||||||
|
= simple_captcha_options[:image]
|
||||||
|
.controls
|
||||||
|
= simple_captcha_options[:field]
|
||||||
4
app/views/simple_captcha/_simple_captcha.mobile.haml
Normal file
4
app/views/simple_captcha/_simple_captcha.mobile.haml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
.control-group#captcha
|
||||||
|
= simple_captcha_options[:image]
|
||||||
|
.controls
|
||||||
|
= simple_captcha_options[:field]
|
||||||
|
|
@ -82,6 +82,12 @@ defaults:
|
||||||
- 'support'
|
- 'support'
|
||||||
- 'contact'
|
- 'contact'
|
||||||
- 'example_user1dsioaioedfhgoiesajdigtoearogjaidofgjo'
|
- 'example_user1dsioaioedfhgoiesajdigtoearogjaidofgjo'
|
||||||
|
captcha:
|
||||||
|
enable: true
|
||||||
|
image_size: '120x20'
|
||||||
|
captcha_length: 5
|
||||||
|
image_style: 'simply_green'
|
||||||
|
distortion: 'low'
|
||||||
services:
|
services:
|
||||||
facebook:
|
facebook:
|
||||||
enable: false
|
enable: false
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ configuration: ## Section
|
||||||
## from the internet. This should be the URL you want to use to
|
## from the internet. This should be the URL you want to use to
|
||||||
## access the pod. So if you plan to reverse proxy it, it should be
|
## access the pod. So if you plan to reverse proxy it, it should be
|
||||||
## the URL the proxy listens on.
|
## the URL the proxy listens on.
|
||||||
## DO NOT CHNANGE THIS AFTER INITIAL SETUP
|
## DO NOT CHANGE THIS AFTER INITIAL SETUP
|
||||||
## UNLESS YOU KNOW WHAT YOU'RE DOING!
|
## UNLESS YOU KNOW WHAT YOU'RE DOING!
|
||||||
## However changing http to https is okay and has no consequences.
|
## However changing http to https is okay and has no consequences.
|
||||||
## If you do change it you have to start over as it's hardcoded into
|
## If you do change it you have to start over as it's hardcoded into
|
||||||
|
|
@ -224,6 +224,28 @@ configuration: ## Section
|
||||||
## below or set autofollow_on_join to false
|
## below or set autofollow_on_join to false
|
||||||
#autofollow_on_join_user: 'diasporahq@joindiaspora.com'
|
#autofollow_on_join_user: 'diasporahq@joindiaspora.com'
|
||||||
|
|
||||||
|
## Settings about captcha
|
||||||
|
captcha: ## Section
|
||||||
|
|
||||||
|
## Set this to false if you don't want to use captcha for signup process
|
||||||
|
#enable: true
|
||||||
|
|
||||||
|
## Change this value to use different captcha image size
|
||||||
|
#image_size: '120x20'
|
||||||
|
|
||||||
|
## Length of captcha text. Default value is 5
|
||||||
|
#captcha_length: 5
|
||||||
|
|
||||||
|
## Change this value to use various image style.
|
||||||
|
## Available options are: 'simply_blue', 'simply_red'
|
||||||
|
## 'simply_green', 'charcoal_grey', 'embosed_silver', 'all_black',
|
||||||
|
## 'distorted_black', 'almost_invisible', 'random'
|
||||||
|
#image_style: 'simply_green'
|
||||||
|
|
||||||
|
## Set this value to use various level of distortion
|
||||||
|
## Available options are: 'low', 'medium', 'high', 'random'
|
||||||
|
#distortion: 'low'
|
||||||
|
|
||||||
## Settings about invitations
|
## Settings about invitations
|
||||||
invitations: ## Section
|
invitations: ## Section
|
||||||
|
|
||||||
|
|
|
||||||
7
config/initializers/setup_simple_captcha.rb
Normal file
7
config/initializers/setup_simple_captcha.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
SimpleCaptcha.setup do |sc|
|
||||||
|
sc.image_size = AppConfig.settings.captcha.image_size
|
||||||
|
sc.length = AppConfig.settings.captcha.captcha_length.to_i
|
||||||
|
sc.image_style = AppConfig.settings.captcha.image_style
|
||||||
|
sc.distortion = AppConfig.settings.captcha.distortion
|
||||||
|
p AppConfig.settings.captcha
|
||||||
|
end
|
||||||
|
|
@ -1270,3 +1270,11 @@ en:
|
||||||
xrd_fetch_failed: "there was an error getting the xrd from account %{account}"
|
xrd_fetch_failed: "there was an error getting the xrd from account %{account}"
|
||||||
not_enabled: "webfinger does not seem to be enabled for %{account}'s host"
|
not_enabled: "webfinger does not seem to be enabled for %{account}'s host"
|
||||||
no_person_constructed: "No person could be constructed from this hcard."
|
no_person_constructed: "No person could be constructed from this hcard."
|
||||||
|
|
||||||
|
simple_captcha:
|
||||||
|
placeholder: "Enter the image value"
|
||||||
|
label: "Enter the code in the box:"
|
||||||
|
message:
|
||||||
|
default: "Secret Code did not match with the Image"
|
||||||
|
user: "The secret Image and code were different"
|
||||||
|
failed: "Human verification failed"
|
||||||
|
|
|
||||||
15
db/migrate/20131213171804_create_simple_captcha_data.rb
Normal file
15
db/migrate/20131213171804_create_simple_captcha_data.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
class CreateSimpleCaptchaData < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
create_table :simple_captcha_data do |t|
|
||||||
|
t.string :key, :limit => 40
|
||||||
|
t.string :value, :limit => 6
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :simple_captcha_data, :key, :name => "idx_key"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
drop_table :simple_captcha_data
|
||||||
|
end
|
||||||
|
end
|
||||||
11
db/schema.rb
11
db/schema.rb
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20130801063213) do
|
ActiveRecord::Schema.define(:version => 20131213171804) do
|
||||||
|
|
||||||
create_table "account_deletions", :force => true do |t|
|
create_table "account_deletions", :force => true do |t|
|
||||||
t.string "diaspora_handle"
|
t.string "diaspora_handle"
|
||||||
|
|
@ -401,6 +401,15 @@ ActiveRecord::Schema.define(:version => 20130801063213) do
|
||||||
add_index "share_visibilities", ["shareable_id", "shareable_type", "hidden", "contact_id"], :name => "shareable_and_hidden_and_contact_id"
|
add_index "share_visibilities", ["shareable_id", "shareable_type", "hidden", "contact_id"], :name => "shareable_and_hidden_and_contact_id"
|
||||||
add_index "share_visibilities", ["shareable_id"], :name => "index_post_visibilities_on_post_id"
|
add_index "share_visibilities", ["shareable_id"], :name => "index_post_visibilities_on_post_id"
|
||||||
|
|
||||||
|
create_table "simple_captcha_data", :force => true do |t|
|
||||||
|
t.string "key", :limit => 40
|
||||||
|
t.string "value", :limit => 6
|
||||||
|
t.datetime "created_at", :null => false
|
||||||
|
t.datetime "updated_at", :null => false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "simple_captcha_data", ["key"], :name => "idx_key"
|
||||||
|
|
||||||
create_table "tag_followings", :force => true do |t|
|
create_table "tag_followings", :force => true do |t|
|
||||||
t.integer "tag_id", :null => false
|
t.integer "tag_id", :null => false
|
||||||
t.integer "user_id", :null => false
|
t.integer "user_id", :null => false
|
||||||
|
|
|
||||||
|
|
@ -1018,4 +1018,34 @@ describe User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "sign up" do
|
||||||
|
before do
|
||||||
|
params = {:username => "ohai",
|
||||||
|
:email => "ohai@example.com",
|
||||||
|
:password => "password",
|
||||||
|
:password_confirmation => "password",
|
||||||
|
:captcha => "12345",
|
||||||
|
|
||||||
|
:person =>
|
||||||
|
{:profile =>
|
||||||
|
{:first_name => "O",
|
||||||
|
:last_name => "Hai"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@user = User.build(params)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "saves with captcha off" do
|
||||||
|
AppConfig.settings.captcha.enable = false
|
||||||
|
@user.should_receive(:save).and_return(true)
|
||||||
|
@user.sign_up
|
||||||
|
end
|
||||||
|
|
||||||
|
it "saves with captcha on" do
|
||||||
|
AppConfig.settings.captcha.enable = true
|
||||||
|
@user.should_receive(:save_with_captcha).and_return(true)
|
||||||
|
@user.sign_up
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue