Merge branch 'feature/nocaptcha' into develop

This commit is contained in:
Steven Miers 2015-01-05 23:09:35 -06:00
commit 8540cd6b90
15 changed files with 132 additions and 61 deletions

View File

@ -909,6 +909,7 @@ module JamRuby
fb_signup = options[:fb_signup]
signup_confirm_url = options[:signup_confirm_url]
affiliate_referral_id = options[:affiliate_referral_id]
recaptcha_failed = options[:recaptcha_failed]
user = User.new
@ -1031,6 +1032,12 @@ module JamRuby
UserMailer.confirm_email(user, signup_confirm_url.nil? ? nil : (signup_confirm_url + "/" + user.signup_token) ).deliver
end
end
if recaptcha_failed
user.errors.add "recaptcha", "verification failed"
raise ActiveRecord::Rollback
end
end
return user

View File

@ -50,7 +50,6 @@ gem 'signet', '0.5.0'
gem 'twitter'
gem 'fb_graph', '2.5.9'
gem 'sendgrid', '1.2.0'
gem 'recaptcha', '0.3.4'
gem 'filepicker-rails', '0.1.0'
gem 'aws-sdk' #, '1.29.1'
gem 'aasm', '3.0.16'
@ -66,6 +65,7 @@ gem 'postgres-copy'
#end
gem 'geokit-rails'
gem 'postgres_ext'
gem 'recaptcha', '0.3.6'
gem 'resque'
gem 'resque-retry'
gem 'resque-failed-job-mailer'

View File

@ -1,4 +1,5 @@
== TODO:
TODO:
====
Jasmine Javascript Unit Tests
=============================

View File

@ -67,7 +67,7 @@ body.web {
.landing-content {
background-color:black;
width:100%;
min-height: 366px;
min-height: 460px;
position:relative;
padding-bottom:30px;

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
require 'builder'
require 'recaptcha/rails'
class Slide
attr_accessor :img_url, :header, :vid_url
@ -133,14 +134,7 @@ class UsersController < ApplicationController
@invited_user = load_invited_user(params)
@signup_postback = load_postback(@invited_user, @fb_signup)
@user = User.new
# check recaptcha; if any errors seen, contribute it to the model
unless verify_recaptcha(:model => @user, :message => "recaptcha")
render 'new', :layout => 'web'
return
end
instruments = fixup_instruments(params[:jam_ruby_user][:instruments])
birth_date = fixup_birthday(params[:jam_ruby_user]["birth_date(2i)"], params[:jam_ruby_user]["birth_date(3i)"], params[:jam_ruby_user]["birth_date(1i)"])
@ -148,6 +142,10 @@ class UsersController < ApplicationController
terms_of_service = params[:jam_ruby_user][:terms_of_service].nil? || params[:jam_ruby_user][:terms_of_service] == "0"? false : true
musician = params[:jam_ruby_user][:musician]
if Rails.application.config.recaptcha_enable
recaptcha_failed = verify_recaptcha(:private_key=>Rails.application.config.recaptcha_private_key, :timeout=>10)
end
@user = UserManager.new.signup(remote_ip: request.remote_ip,
first_name: params[:jam_ruby_user][:first_name],
last_name: params[:jam_ruby_user][:last_name],
@ -159,11 +157,12 @@ class UsersController < ApplicationController
birth_date: birth_date,
location: location,
musician: musician,
recaptcha_failed: recaptcha_failed,
invited_user: @invited_user,
fb_signup: @fb_signup,
signup_confirm_url: ApplicationHelper.base_uri(request) + "/confirm",
affiliate_referral_id: AffiliatePartner.coded_id(self.affiliate_code))
# check for errors
if @user.errors.any?
# render any @user.errors on error
@ -486,5 +485,5 @@ JS
else
signup_path
end
end
end
end

View File

@ -132,6 +132,7 @@
<%= render "shared/ga" %>
<%= render "shared/twttr" %>
<%= render "shared/facebook_sdk" %>
<%= render "shared/google_nocaptcha" %>
<!-- version: <%= version %> -->
</body>
</html>

View File

@ -0,0 +1 @@
script src="https://www.google.com/recaptcha/api.js" async defer

View File

@ -6,7 +6,6 @@
<%= form_for(@user, :url => @signup_postback, :method => :post) do |f| %>
<!-- register left column -->
<div class="register-left left w45">
<div class="register-container">
<div class="register-as">
@ -38,7 +37,7 @@
<div class="field country right-side">
<%= f.label :country, "Country:" %>
<select id="country_select" name="jam_ruby_user[country]" autocomplete="off" class="easydropdown">
<option class="label" value="" <%= @location[:country].blank? ? "selected" : "" %>>Select Country</option>
<option class="label" value="" <%= (@location.nil? || @location[:country].nil? || @location[:country].blank?) ? "selected" : "" %>>Select Country</option>
<% @countriesx.each do |country| %>
<% unless country[:countrycode].blank? %>
<option value="<%= country[:countrycode] %>" <%= @location[:country] == country[:countrycode] ? "selected" : "" %>><%= country[:countryname] %></option>
@ -125,9 +124,12 @@
</small>
</div>
<% if Rails.application.config.recaptcha_enable %>
<%= recaptcha_tags %>
<% end %>
<div class="field recaptcha">
<% if Rails.application.config.recaptcha_enable %>
<div id="recaptcha_select" name="recaptcha_response_field" class="g-recaptcha" data-sitekey="<%=Rails.application.config.recaptcha_public_key%>">
</div>
<% end %>
</div>
<!--
<img src="images/content/captcha.png" width="152" height="50" align="left" class="mr10" /><small>Enter the characters from the box to the left:<br />
@ -192,6 +194,7 @@
var country = get_first_error("country")
var state = get_first_error("state")
var city = get_first_error("city")
var recaptcha = get_first_error("recaptcha")
if (email) {
@ -230,7 +233,12 @@
cityInput.after("<div class='error-text'>" + city + "</div>")
}
if (recaptcha) {
var recaptchaInput = $('#recaptcha_select');
recaptchaInput.closest('div.field').addClass('error')
recaptchaInput.after("<div class='error-text'>" + recaptcha + "</div>")
}
if (musician_instruments) {
var musicianInstrumentsInput = $('#instrument_selector');
musicianInstrumentsInput.closest('div.ftue-instrumentlist-wrapper').addClass('error')

View File

@ -95,7 +95,11 @@ if defined?(Bundler)
config.filepicker_upload_dir = 'avatars'
config.fp_secret = 'FTDL4TYDENBWZKK3UZCFIQWXS4'
config.recaptcha_enable = false
config.recaptcha_enable = true
# created using seth@jamkazam.com; can't see way to delegate
config.recaptcha_public_key = '6Let8dgSAAAAAFheKGWrs6iaq_hIlPOZ2f3Bb56B'
config.recaptcha_private_key = '6Let8dgSAAAAAJzFxL9w2QR5auxjk0ol1_xAtOGO'
# create one user per real jamkazam employee?
config.bootstrap_dev_users = true

View File

@ -1,24 +0,0 @@
# this gem turns recaptcha verification off during tests by default.
# The public key/private keys shown below valid for all jamkazam.com domains
# note that all recaptcha keys work on localhost/127.0.0.1
# the keys are created at https://www.google.com/recaptcha/admin/create
Recaptcha.configure do |config|
# created using seth@jamkazam.com; can't see way to delegate
config.public_key = '6Let8dgSAAAAAFheKGWrs6iaq_hIlPOZ2f3Bb56B'
config.private_key = '6Let8dgSAAAAAJzFxL9w2QR5auxjk0ol1_xAtOGO'
if Rails.application.config.recaptcha_enable
# mirrors default behavior, but it's nice to see it without digging in recaptcha gem source
config.skip_verify_env = ['test', 'cucumber']
else
# disabled in all environments at the moment
config.skip_verify_env = ['test', 'cucumber', 'development', 'production']
end
# other config options available with this gem:
#nonssl_api_server_url,
#ssl_api_server_url,
#verify_url,
#skip_verify_env,
#proxy,
#handle_timeouts_gracefully
end

View File

@ -1,9 +1,5 @@
require 'recaptcha'
class
MusicSessionManager < BaseManager
class MusicSessionManager < BaseManager
include Recaptcha::Verify
def initialize(options={})
super(options)
@log = Logging.logger[self]

View File

@ -1,8 +1,5 @@
require 'recaptcha'
class UserManager < BaseManager
include Recaptcha::Verify
def initialize(options={})
super(options)
@log = Logging.logger[self]
@ -27,7 +24,7 @@ class UserManager < BaseManager
fb_signup = options[:fb_signup]
signup_confirm_url = options[:signup_confirm_url]
affiliate_referral_id = options[:affiliate_referral_id]
recaptcha_failed = Rails.application.config.recaptcha_enable && options[:recaptcha_failed]
user = User.new
# check if we have disabled open signup for this site. open == invited users can still get in
@ -46,13 +43,6 @@ class UserManager < BaseManager
loc[:country] = location[:country]
end
# TODO: figure out why can't user verify_recaptcha here
# ALSO: make sure we dont do the recaptcha stuff if used facebook.
# check recaptcha; if any errors seen, contribute it to the model
#unless verify_recaptcha(:model => user, :message => "recaptcha")
# return user # user.errors.any? is true now
#else
# sends email to email account for confirmation
user = User.signup(first_name: first_name,
last_name: last_name,
@ -65,11 +55,13 @@ class UserManager < BaseManager
birth_date: birth_date,
musician: musician,
photo_url: photo_url,
recaptcha_failed: recaptcha_failed,
invited_user: invited_user,
fb_signup: fb_signup,
signup_confirm_url: signup_confirm_url,
affiliate_referral_id: affiliate_referral_id)
return user
#end
end

View File

@ -4,6 +4,15 @@ describe "Signup", :js => true, :type => :feature, :capybara_feature => true do
subject { page }
before(:all) do
@old_recaptcha=Rails.application.config.recaptcha_enable
Rails.application.config.recaptcha_enable=false
end
after(:all) do
Rails.application.config.recaptcha_enable=@old_recaptcha
end
before(:each) do
@mac_client = FactoryGirl.create(:artifact_update)
UserMailer.deliveries.clear

View File

@ -10,8 +10,15 @@ describe "User Progression", :js => true, :type => :feature, :capybara_feature
Capybara.javascript_driver = :poltergeist
Capybara.current_driver = Capybara.javascript_driver
Capybara.default_wait_time = 10
@old_recaptcha=Rails.application.config.recaptcha_enable
Rails.application.config.recaptcha_enable=false
end
after(:all) do
Rails.application.config.recaptcha_enable=@old_recaptcha
end
let(:user) { FactoryGirl.create(:user) }
describe "downloaded client" do

View File

@ -633,4 +633,74 @@ describe UserManager do
UserMailer.deliveries.length.should == 0
end
end
describe "without nocaptcha" do
before(:all) do
@old_recaptcha=Rails.application.config.recaptcha_enable
Rails.application.config.recaptcha_enable=false
end
after(:all) do
Rails.application.config.recaptcha_enable=@old_recaptcha
end
it "passes even with true recaptcha" do
user = @user_manager.signup(remote_ip: "1.2.3.4",
first_name: "bob",
last_name: "smith",
email: "userman30@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
location: @loca,
recaptcha_failed: true,
signup_confirm_url: "http://localhost:3000/confirm")
user.errors.any?.should be_false
end # it "passes even with true recaptcha"
end # describe "without nocaptcha"
describe "with nocaptcha" do
before(:all) do
@old_recaptcha=Rails.application.config.recaptcha_enable
Rails.application.config.recaptcha_enable=true
end
after(:all) do
Rails.application.config.recaptcha_enable=@old_recaptcha
end
it "fails when nocaptcha fails" do
user = @user_manager.signup(remote_ip: "1.2.3.4",
first_name: "bob",
last_name: "smith",
email: "userman31@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
location: @loca,
recaptcha_failed: true,
signup_confirm_url: "http://localhost:3000/confirm")
user.errors.any?.should be_true
user = @user_manager.signup(remote_ip: "1.2.3.4",
first_name: "bob",
last_name: "smith",
email: "userman31@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
recaptcha_failed: false,
instruments: @instruments,
musician: true,
location: @loca,
signup_confirm_url: "http://localhost:3000/confirm")
user.errors.any?.should be_false
end # it "fails when nocaptcha fails"
end # describe "with nocaptcha"
end # test