* VRFS-1025 finished

This commit is contained in:
Seth Call 2014-02-03 21:19:14 +00:00
parent aa68a4e2f4
commit d4a5737c51
34 changed files with 830 additions and 124 deletions

View File

@ -96,4 +96,5 @@ ms_user_history_add_instruments.sql
icecast_config_changed.sql
invited_users_facebook_support.sql
first_recording_at.sql
share_token.sql
share_token.sql
facebook_signup.sql

16
db/up/facebook_signup.sql Normal file
View File

@ -0,0 +1,16 @@
-- when a user authorizes our application to signup, we create this row
CREATE UNLOGGED TABLE facebook_signups (
id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
lookup_id VARCHAR(255) UNIQUE NOT NULL,
last_name VARCHAR(100),
first_name VARCHAR(100),
gender VARCHAR(1),
email VARCHAR(1024),
uid VARCHAR(1024),
token VARCHAR(1024),
token_expires_at TIMESTAMP,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE user_authorizations ADD CONSTRAINT user_authorizations_uniqkey UNIQUE (provider, uid);

View File

@ -35,6 +35,7 @@ require "jam_ruby/resque/resque_hooks"
require "jam_ruby/resque/scheduled/audiomixer_retry"
require "jam_ruby/resque/scheduled/icecast_config_retry"
require "jam_ruby/resque/scheduled/icecast_source_check"
require "jam_ruby/resque/scheduled/cleanup_facebook_signup"
require "jam_ruby/mq_router"
require "jam_ruby/base_manager"
require "jam_ruby/connection_manager"
@ -117,6 +118,7 @@ require "jam_ruby/models/icecast_server_socket"
require "jam_ruby/models/icecast_template_socket"
require "jam_ruby/models/icecast_server_group"
require "jam_ruby/models/icecast_mount_template"
require "jam_ruby/models/facebook_signup"
include Jampb

View File

@ -0,0 +1,15 @@
module JamRuby
class FacebookSignup < ActiveRecord::Base
before_create :generate_lookup_id
def self.delete_old
FacebookSignup.where("created_at < :week", {:week => 1.week.ago}).delete_all
end
private
def generate_lookup_id
self.lookup_id = SecureRandom.urlsafe_base64
end
end
end

View File

@ -697,8 +697,23 @@ module JamRuby
# throws ActiveRecord::RecordNotFound if instrument is invalid
# throws an email delivery error if unable to connect out to SMTP
def self.signup(first_name, last_name, email, password, password_confirmation, terms_of_service,
location, instruments, birth_date, musician, photo_url, invited_user, signup_confirm_url)
def self.signup(options)
first_name = options[:first_name]
last_name = options[:last_name]
email = options[:email]
password = options[:password]
password_confirmation = options[:password_confirmation]
terms_of_service = options[:terms_of_service]
location = options[:location]
instruments = options[:instruments]
birth_date = options[:birth_date]
musician = options[:musician]
photo_url = options[:photo_url]
invited_user = options[:invited_user]
fb_signup = options[:fb_signup]
signup_confirm_url = options[:signup_confirm_url]
user = User.new
UserManager.active_record_transaction do |user_manager|
@ -744,11 +759,25 @@ module JamRuby
user.photo_url = photo_url
unless fb_signup.nil?
user.update_fb_authorization(fb_signup)
if fb_signup.email.casecmp(user.email).zero?
user.email_confirmed = true
user.signup_token = nil
else
user.email_confirmed = false
user.signup_token = SecureRandom.urlsafe_base64
end
end
if invited_user.nil?
user.can_invite = Limits::USERS_CAN_INVITE
user.email_confirmed = false
user.signup_token = SecureRandom.urlsafe_base64
unless user.email_confirmed # important that the only time this goes true is if some other mechanism, like fb_signup, set this high
user.email_confirmed = false
user.signup_token = SecureRandom.urlsafe_base64
end
else
# if you are invited by an admin, we'll say you can invite too.
# but if not, then you can not invite
@ -785,15 +814,10 @@ module JamRuby
if user.errors.any?
raise ActiveRecord::Rollback
else
# don't send an signup email if the user was invited already *and* they used the same email that they were invited with
if !invited_user.nil? && invited_user.email.casecmp(user.email).zero?
# don't send an signup email if email is already confirmed
if user.email_confirmed
UserMailer.welcome_message(user).deliver
else
# FIXME:
# It's not standard to require a confirmation when a user signs up with Facebook.
# We should stop asking for it.
#
# any errors here should also rollback the transaction; that's OK. If emails aren't going to be delivered,
# it's already a really bad situation; make user signup again
UserMailer.confirm_email(user, signup_confirm_url.nil? ? nil : (signup_confirm_url + "/" + user.signup_token) ).deliver
@ -941,6 +965,30 @@ module JamRuby
end
end
# updates an existing user_authorization for facebook, or creates a new one if none exist
def update_fb_authorization(fb_signup)
if fb_signup.uid && fb_signup.token && fb_signup.token_expires_at
user_authorization = nil
unless self.new_record?
# see if this user has an existing user_authorization for this provider
user_authorization = UserAuthorization.find_by_user_id_and_provider(self.id, 'facebook')
end
if user_authorization.nil?
self.user_authorizations.build provider: 'facebook',
uid: fb_signup.uid,
token: fb_signup.token,
token_expiration: fb_signup.token_expires_at
else
user_authorization.uid = fb_signup.uid
user_authorization.token = fb_signup.token
user_authorization.token_expiration = fb_signup.token_expires_at
end
end
end
def provides_location?
!self.city.blank? && (!self.state.blank? || !self.country.blank?)
end

View File

@ -9,8 +9,10 @@ module JamRuby
belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "user_id"
validates :provider, :uid, :presence => true
validates_uniqueness_of :uid, scope: :provider
# token and token_expiration can be missing
end
end

View File

@ -0,0 +1,19 @@
module JamRuby
class CleanupFacebookSignup
@queue = :cleanup_facebook_signup
@@log = Logging.logger[CleanupFacebookSignup]
def self.perform
@@log.debug("waking up")
FacebookSignup.delete_old
@@log.debug("done")
end
end
end

View File

@ -317,4 +317,14 @@ FactoryGirl.define do
association :authentication, :factory => :icecast_user_authentication
end
factory :facebook_signup, :class => JamRuby::FacebookSignup do
sequence(:lookup_id) { |n| "lookup-#{n}"}
sequence(:first_name) { |n| "first-#{n}"}
sequence(:last_name) { |n| "last-#{n}"}
gender 'M'
sequence(:email) { |n| "jammin-#{n}@jamkazam.com"}
sequence(:uid) { |n| "uid-#{n}"}
sequence(:token) { |n| "token-#{n}"}
token_expires_at Time.now
end
end

View File

@ -0,0 +1,20 @@
require 'spec_helper'
describe FacebookSignup do
it "does not delete new one" do
new_signup = FactoryGirl.create(:facebook_signup)
FacebookSignup.delete_old
FacebookSignup.find(new_signup)
end
it "does delete old one" do
old_signup = FactoryGirl.create(:facebook_signup, :created_at => 10.days.ago)
FacebookSignup.delete_old
FacebookSignup.find_by_id(old_signup.id).should be_nil
end
end

View File

@ -397,6 +397,34 @@ describe User do
end
end
describe "user_authorizations" do
it "can create" do
@user.user_authorizations.build provider: 'facebook',
uid: '1',
token: '1',
token_expiration: Time.now
@user.save!
end
it "fails on duplicate" do
@user.user_authorizations.build provider: 'facebook',
uid: '1',
token: '1',
token_expiration: Time.now
@user.save!
@user2 = FactoryGirl.create(:user)
@user2.user_authorizations.build provider: 'facebook',
uid: '1',
token: '1',
token_expiration: Time.now
@user2.save.should be_false
@user2.errors[:user_authorizations].should == ['is invalid']
end
end
=begin
describe "update avatar" do

View File

@ -322,10 +322,15 @@
var hash = context.location.hash;
if(!this.layout.isScreenName(hash)) {
hash = null;
}
var url = '#/home';
if (hash) {
url = hash;
}
logger.debug("Changing screen to " + url);
context.location = url;
}

View File

@ -428,6 +428,18 @@
dialogEvent(dialog, 'afterHide');
}
function isScreenName(screenName) {
if(!screenName) return false;
var hashIndex = screenName.indexOf('#');
if(hashIndex > -1) {
screenName = screenName.substr(hashIndex);
}
return screenBindings[screenName];
}
function screenEvent(screen, evtName, data) {
if (screen && screen in screenBindings) {
if (evtName in screenBindings[screen]) {
@ -752,6 +764,10 @@
};
};
this.isScreenName = function(screenName) {
return isScreenName(screenName);
}
this.bindScreen = function(screen, handler) {
screenBindings[screen] = handler;
};

View File

@ -0,0 +1,43 @@
(function(context,$) {
"use strict";
context.JK = context.JK || {};
context.JK.SigninDialog = function(app) {
var logger = context.JK.logger;
var rest = context.JK.Rest();
var dialogId = '#signin-dialog';
function events() {
$(dialogId + ' .signin-cancel').click(function(e) {
app.layout.closeDialog('signin-dialog');
e.stopPropagation();
return false;
});
}
function beforeShow() {
}
function afterHide() {
}
function initialize(){
var dialogBindings = {
'beforeShow' : beforeShow,
'afterHide': afterHide
};
app.bindDialog('signin-dialog', dialogBindings);
events();
}
this.initialize = initialize;
}
})(window, jQuery);

View File

@ -10,8 +10,11 @@
var dialogId = '#signup-dialog';
function events() {
$(dialogId + ' .signup-cancel').click(function(e) {
app.layout.closeDialog('signup-dialog');
e.stopPropagation();
return false;
});
}
function beforeShow() {
@ -31,7 +34,6 @@
app.bindDialog('signup-dialog', dialogBindings);
console.log("honuth")
events();
}

View File

@ -6,6 +6,7 @@
//= require AAC_underscore
//= require globals
//= require web/signupDialog
//= require web/signinDialog
//= require invitationDialog
//= require shareDialog
//= require layout

View File

@ -10,6 +10,12 @@
e.preventDefault();
return false;
});
$('#signin').click(function(e) {
context.JK.app.layout.showDialog('signin-dialog');
e.preventDefault();
return false;
});
}
initialize()

View File

@ -27,32 +27,6 @@ class ApiUsersController < ApiController
respond_with @user, responder: ApiResponder, :status => 200
end
# this API call is disabled by virtue of it being commented out in routes.rb
# the reason is that it has no captcha, and is therefore a bit abuseable
# if someone wants to use it, please add in captcha or some other bot-protector
def create
# sends email to email account for confirmation
@user = UserManager.new.signup(params[:first_name],
params[:last_name],
params[:email],
params[:password],
params[:password_confirmation],
params[:city],
params[:state],
params[:country],
params[:instruments],
params[:photo_url],
ApplicationHelper.base_uri(request) + "/confirm")
# check for errors
unless @user.errors.any?
render :json => {}, :status => :ok # an empty response, but 200 OK
else
response.status = :unprocessable_entity
respond_with @user, responder: ApiResponder
end
end
def update
@user = User.find(params[:id])

View File

@ -48,15 +48,10 @@ class SessionsController < ApplicationController
# an email and whatnot.
#
# Also, should we grab their photo from facebook?
user = UserManager.new.signup(remote_ip(),
auth_hash[:info][:first_name],
auth_hash[:info][:last_name],
auth_hash[:info][:email],
nil,
nil,
nil, # instruments
nil, # photo_url
nil)
user = UserManager.new.signup(remote_ip: remote_ip(),
first_name: auth_hash[:info][:first_name],
last_name: auth_hash[:info][:last_name],
email: auth_hash[:info][:email])
# Users who sign up using oauth are presumed to have valid email adddresses.
user.confirm_email!
@ -72,18 +67,49 @@ class SessionsController < ApplicationController
def oauth_callback
auth_hash = request.env['omniauth.auth']
provider = auth_hash[:provider]
if provider == 'facebook'
fb_uid = auth_hash[:uid]
token = auth_hash[:credentials][:token]
token_expiration = Time.at(auth_hash[:credentials][:expires_at])
first_name = auth_hash[:extra][:raw_info][:first_name]
last_name = auth_hash[:extra][:raw_info][:last_name]
email = auth_hash[:extra][:raw_info][:email]
gender = auth_hash[:extra][:raw_info][:gender]
fb_signup = FacebookSignup.new
fb_signup.uid = fb_uid
fb_signup.token = token
fb_signup.token_expires_at = token_expiration
fb_signup.first_name = first_name
fb_signup.last_name = last_name
fb_signup.email = email
if gender == 'male'
fb_signup.gender = 'M'
elsif gender == 'female'
fb_signup.gender = 'F'
end
fb_signup.save!
redirect_to "#{signup_path}?facebook_signup=#{fb_signup.lookup_id}"
return
end
if current_user.nil?
render :nothing => true, :status => 404
return
end
auth_hash = request.env['omniauth.auth']
#authorization = UserAuthorization.find_by_provider_and_uid(auth_hash["provider"], auth_hash["uid"])
# Always make and save a new authorization. This is because they expire, and honestly there's no cost
# to just making and saving it.
#if authorization.nil?
authorization = current_user.user_authorizations.build :provider => auth_hash[:provider],
authorization = current_user.user_authorizations.build :provider => auth_hash[:provider],
:uid => auth_hash[:uid],
:token => auth_hash[:credentials][:token],
:token_expiration => Time.at(auth_hash[:credentials][:expires_at])

View File

@ -27,6 +27,33 @@ class UsersController < ApplicationController
return
end
@fb_signup = load_facebook_signup(params)
# check if the email specified by @fb_signup already exists in the databse--if so, log them in and redirect
if @fb_signup && @fb_signup.email
user = User.find_by_email_and_email_confirmed(@fb_signup, true)
if user
# update user_authorization for user because this is fresher
user.update_fb_authorization(@fb_signup)
sign_in(user)
redirect_to client_url
return
end
end
# check if the uid specified by @fb_signup already exists in the databse--if so, log them in and redirect
if @fb_signup && @fb_signup.uid
user_authorization = UserAuthorization.find_by_uid_and_provider(@fb_signup.uid, 'facebook')
# update user_authorization for user because this is fresher
if user_authorization
user_authorization.user.update_fb_authorization(@fb_signup)
sign_in(user_authorization.user)
redirect_to client_url
return
end
end
@invited_user = load_invited_user(params)
if !@invited_user.nil? && @invited_user.has_required_email? && @invited_user.accepted
@ -34,7 +61,7 @@ class UsersController < ApplicationController
render "already_signed_up", :layout => 'landing'
return
end
@signup_postback = load_postback(@invited_user)
@signup_postback = load_postback(@invited_user, @fb_signup)
load_location(request.remote_ip)
@ -42,21 +69,54 @@ class UsersController < ApplicationController
@user.musician = true # default the UI to musician as selected option
# preseed the form with the invited email as a convenience to the user
unless @invited_user.nil?
@user.email = @invited_user.email
@user.email = @invited_user.email unless @invited_user.nil?
if @fb_signup
@user.email = @fb_signup.email
@user.first_name = @fb_signup.first_name
@user.last_name = @fb_signup.last_name
@user.gender = @fb_signup.gender
end
render :layout => 'web'
end
def create
if current_user
redirect_to client_url
return
end
@fb_signup = load_facebook_signup(params)
# check if the email specified by @fb_signup already exists in the databse--if so, log them in and redirect
if @fb_signup && @fb_signup.email
user = User.find_by_email_and_email_confirmed(@fb_signup, true)
if user
# update user_authorization for user because this is fresher
user.update_fb_authorization(@fb_signup)
sign_in(user)
redirect_to client_url
return
end
end
# check if the uid specified by @fb_signup already exists in the databse--if so, log them in and redirect
if @fb_signup && @fb_signup.uid
user_authorization = UserAuthorization.find_by_uid_and_provider(@fb_signup.uid, 'facebook')
# update user_authorization for user because this is fresher
if user_authorization
user_authorization.user.update_fb_authorization(@fb_signup)
sign_in(user_authorization.user)
redirect_to client_url
return
end
end
@invited_user = load_invited_user(params)
@signup_postback = load_postback(@invited_user)
@signup_postback = load_postback(@invited_user, @fb_signup)
@user = User.new
@ -73,21 +133,20 @@ class UsersController < ApplicationController
terms_of_service = params[:jam_ruby_user][:terms_of_service].nil? ? false : true
musician = params[:jam_ruby_user][:musician]
@user = UserManager.new.signup(request.remote_ip,
params[:jam_ruby_user][:first_name],
params[:jam_ruby_user][:last_name],
params[:jam_ruby_user][:email],
params[:jam_ruby_user][:password],
params[:jam_ruby_user][:password_confirmation],
terms_of_service,
instruments,
birth_date,
location,
musician,
nil, # we don't accept photo url on the signup form yet
@invited_user,
ApplicationHelper.base_uri(request) + "/confirm")
@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],
email: params[:jam_ruby_user][:email],
password: params[:jam_ruby_user][:password],
password_confirmation: params[:jam_ruby_user][:password_confirmation],
terms_of_service: terms_of_service,
instruments: instruments,
birth_date: birth_date,
location: location,
musician: musician,
invited_user: @invited_user,
fb_signup: @fb_signup,
signup_confirm_url: ApplicationHelper.base_uri(request) + "/confirm")
# check for errors
if @user.errors.any?
@ -308,6 +367,12 @@ class UsersController < ApplicationController
return Date.new(year.to_i, month.to_i, day.to_i)
end
def load_facebook_signup(params)
lookup_id = params[:facebook_signup]
FacebookSignup.find_by_lookup_id(lookup_id)
end
def load_invited_user(params)
# check if this an anonymous request, or result of invitation code
invitation_code = params[:invitation_code]
@ -336,11 +401,10 @@ class UsersController < ApplicationController
@cities = @location[:state].nil? ? [] : MaxMindManager.cities(@location[:country], @location[:state])
end
def load_postback(invited_user)
if invited_user.nil?
signup_path
else
signup_path + "?invitation_code=" + invited_user.invitation_code
end
def load_postback(invited_user, fb_signup)
query = {}
query[:invitation_code] = invited_user.invitation_code if invited_user
query[:facebook_signup] = fb_signup.lookup_id if fb_signup
signup_path + "?" + params.to_query
end
end

View File

@ -50,6 +50,7 @@
<%= render "clients/invitationDialog" %>
<%= render "users/signupDialog" %>
<%= render "users/signinDialog" %>
<script type="text/javascript">
$(function () {
@ -73,6 +74,9 @@
var signupDialog = new JK.SignupDialog(JK.app);
signupDialog.initialize();
var signinDialog = new JK.SigninDialog(JK.app);
signinDialog.initialize();
})
</script>

View File

@ -0,0 +1,58 @@
<div class="dialog thin-dialog overlay-small" layout-id="signin-dialog" id="signin-dialog">
<!-- ftue header -->
<div class="content-head">
<h1>sign in</h1>
</div>
<!-- inner wrapper -->
<div class="overlay-inner">
<%= link_to image_tag("content/button_facebook_signin.png", {:width => 249, :height => 46 }), '/auth/facebook', class: "signin-facebook" %>
<br>
<br>
<br>
<strong class="white">Or sign in with JamKazam Account</strong>
<br>
<br>
<form>
<table cellpadding="10" cellspacing="2">
<tbody>
<tr>
<td>Email Address:<br>
<input type="text"><br><br>
</td>
</tr>
<tr>
<td>Password:<br>
<input type="password"></td>
</tr>
<tr>
<td valign="top">
<small><input type="checkbox"> Keep me signed in</small>
<br><br>
<div align="center">
<a href="web_home.html" class="button-grey signin-cancel">CANCEL</a>&nbsp;&nbsp;<a href="#" class="button-orange m0">SIGN
IN</a><br>
<br>
<small><a href="#">Forgot Password?</a></small>
</div>
</td>
</tr>
</tbody>
</table>
</form>
<br>
<div class="center">
<small>Don't have an account? <a href="signup.shtml">Sign Up</a></small>
</div>
</div>
<!-- end inner -->
<br clear="all">
</div>

View File

@ -8,7 +8,7 @@
<!-- inner wrapper -->
<div class="overlay-inner">
<%= image_tag "content/button_facebook_signup.png", {:width => 249, :height => 46 } %>
<%= link_to image_tag("content/button_facebook_signup.png", {:width => 249, :height => 46 }), '/auth/facebook', class: "signup-facebook" %>
<br>
<br><br>
@ -16,14 +16,14 @@
<br>
<br>
<div class="center"><%= link_to "SIGN UP WITH YOUR EMAIL", signup_path, class: "button-orange block" %>
<div class="center"><%= link_to "SIGN UP WITH YOUR EMAIL", signup_path, class: "button-orange block signup-email" %>
<br>
<div class="center">
<small>Already have an account? <a href="#" class='signin'>Sign In</a><br>
<br>
<a href="#" layout-action="close">Cancel</a></small>
<a href="#" class="signup-cancel">Cancel</a></small>
</div>
</div>
<!-- end inner -->

View File

@ -194,5 +194,8 @@ include JamRuby
config.email_smtp_user_name = 'jamkazam'
config.email_smtp_password = 'jamjamblueberryjam'
config.email_smtp_starttls_auto = true
config.facebook_app_id = '468555793186398'
config.facebook_app_secret = '546a5b253972f3e2e8b36d9a3dd5a06e'
end
end

View File

@ -86,4 +86,7 @@ SampleApp::Application.configure do
config.fp_secret = 'HZBIMSOI5VAQ5LXT4XLG6XA7IE'
config.allow_force_native_client = false
config.facebook_app_id = '1412328362347190' # staging
config.facebook_app_secret = '8b1f20430356d44fb49c0a504a9ff401' # staging
end

View File

@ -59,5 +59,8 @@ SampleApp::Application.configure do
config.aws_secret_access_key = 'h0V0ffr3JOp/UtgaGrRfAk25KHNiO9gm8Pj9m6v3'
config.icecast_wait_after_reload = 0
config.facebook_app_id = '1441492266082868'
config.facebook_app_secret = '233bd040a07e47dcec1cff3e490bfce7'
end

View File

@ -1,5 +1,5 @@
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, '468555793186398', '546a5b253972f3e2e8b36d9a3dd5a06e', {name: "facebook", :scope => 'email,user_location'}
provider :facebook, Rails.application.config.facebook_app_id, Rails.application.config.facebook_app_secret, {name: "facebook", :scope => 'email,user_location'}
provider :google_oauth2, Rails.application.config.google_client_id, Rails.application.config.google_secret, {name: "google_login", approval_prompt: '', scope: 'userinfo.email, userinfo.profile, https://www.google.com/m8/feeds'}
end

View File

@ -9,9 +9,13 @@ IcecastConfigRetry:
class: "JamRuby::IcecastConfigRetry"
description: "Finds icecast servers that have had their config_changed, but no IcecastConfigWriter check recently"
IcecastSourceCheck:
cron: "10 * * * * *"
class: "JamRuby::IcecastSourceCheck"
description: "Finds icecast mounts that need their 'sourced' state to change, but haven't in some time"
CleanupFacebookSignup:
cron: "30 2 * * *"
class: "JamRuby::CleanupFacebookSignup"
description: "Deletes facebook_signups that are old"

View File

@ -10,8 +10,22 @@ class UserManager < BaseManager
# Note that almost everything can be nil here. This is because when users sign up via social media,
# we don't know much about them.
def signup(remote_ip, first_name, last_name, email, password = nil, password_confirmation = nil, terms_of_service = nil,
instruments = nil, birth_date = nil, location = nil, musician = nil, photo_url = nil, invited_user = nil, signup_confirm_url = nil)
def signup(options)
remote_ip = options[:remote_ip]
first_name = options[:first_name]
last_name = options[:last_name]
email = options[:email]
password = options[:password]
password_confirmation = options[:password_confirmation]
terms_of_service = options[:terms_of_service]
instruments = options[:instruments]
birth_date = options[:birth_date]
location = options[:location]
musician = options[:musician]
photo_url = options[:photo_url]
invited_user = options[:invited_user]
fb_signup = options[:fb_signup]
signup_confirm_url = options[:signup_confirm_url]
@user = User.new
@ -33,8 +47,20 @@ class UserManager < BaseManager
# return @user # @user.errors.any? is true now
#else
# sends email to email account for confirmation
@user = User.signup(first_name, last_name, email, password, password_confirmation, terms_of_service,
location, instruments, birth_date, musician, photo_url, invited_user, signup_confirm_url)
@user = User.signup(first_name: first_name,
last_name: last_name,
email: email,
password: password,
password_confirmation: password_confirmation,
terms_of_service: terms_of_service,
location: location,
instruments: instruments,
birth_date: birth_date,
musician: musician,
photo_url: photo_url,
invited_user: invited_user,
fb_signup: fb_signup,
signup_confirm_url: signup_confirm_url)
return @user
#end

View File

@ -70,18 +70,6 @@ describe SessionsController do
visit '/auth/facebook'
end.should change(User, :count).by(0)
end
it "should not create a user when oauth comes in with a currently existing user" do
user = FactoryGirl.create(:user) # in the jam session
OmniAuth.config.mock_auth[:facebook][:info][:email] = user.email
OmniAuth.config.mock_auth[:facebook] = OmniAuth.config.mock_auth[:facebook]
lambda do
visit '/auth/facebook'
end.should change(User, :count).by(0)
end
end

View File

@ -308,5 +308,14 @@ FactoryGirl.define do
association :authentication, :factory => :icecast_user_authentication
end
factory :facebook_signup, :class => JamRuby::FacebookSignup do
sequence(:lookup_id) { |n| "lookup-#{n}"}
sequence(:first_name) { |n| "first-#{n}"}
sequence(:last_name) { |n| "last-#{n}"}
gender 'M'
sequence(:email) { |n| "jammin-#{n}@jamkazam.com"}
sequence(:uid) { |n| "uid-#{n}"}
sequence(:token) { |n| "token-#{n}"}
token_expires_at Time.now
end
end

View File

@ -83,9 +83,12 @@ describe "Signup", :js => true, :type => :feature, :capybara_feature => true do
before do
@invited_user = FactoryGirl.create(:invited_user, :email => "noone@jamkazam.com")
visit "#{signup_path}?invitation_code=#{@invited_user.invitation_code}"
find('#jam_ruby_user_first_name')
sleep 1 # if I don't do this, first_name and/or last name intermittently fail to fill out
UserMailer.deliveries.clear
fill_in "jam_ruby_user[first_name]", with: "Mike"
fill_in "jam_ruby_user[first_name]", with: "Mike"
fill_in "jam_ruby_user[last_name]", with: "Jones"
fill_in "jam_ruby_user[email]", with: "newuser2@jamkazam.com"
fill_in "jam_ruby_user[password]", with: "jam123"
@ -110,6 +113,8 @@ describe "Signup", :js => true, :type => :feature, :capybara_feature => true do
@user = FactoryGirl.create(:user)
@invited_user = FactoryGirl.create(:invited_user, :sender => @user, :autofriend => true, :email => "noone@jamkazam.com")
visit "#{signup_path}?invitation_code=#{@invited_user.invitation_code}"
find('#jam_ruby_user_first_name')
sleep 1 # if I don't do this, first_name and/or last name intermittently fail to fill out
fill_in "jam_ruby_user[first_name]", with: "Mike"
fill_in "jam_ruby_user[last_name]", with: "Jones"
@ -136,6 +141,8 @@ describe "Signup", :js => true, :type => :feature, :capybara_feature => true do
before do
@invited_user = FactoryGirl.create(:invited_user, :email => "noone@jamkazam.com")
visit "#{signup_path}?invitation_code=#{@invited_user.invitation_code}"
find('#jam_ruby_user_first_name')
sleep 1 # if I don't do this, first_name and/or last name intermittently fail to fill out
fill_in "jam_ruby_user[first_name]", with: "Mike"
fill_in "jam_ruby_user[last_name]", with: "Jones"
@ -159,6 +166,8 @@ describe "Signup", :js => true, :type => :feature, :capybara_feature => true do
before do
@invited_user = FactoryGirl.create(:invited_user, :email => "what@jamkazam.com")
visit "#{signup_path}?invitation_code=#{@invited_user.invitation_code}"
find('#jam_ruby_user_first_name')
sleep 1 # if I don't do this, first_name and/or last name intermittently fail to fill out
UserMailer.deliveries.clear

View File

@ -0,0 +1,66 @@
require 'spec_helper'
describe "Welcome", :js => true, :type => :feature, :capybara_feature => true do
subject { page }
before(:all) do
Capybara.javascript_driver = :poltergeist
Capybara.current_driver = Capybara.javascript_driver
Capybara.default_wait_time = 10
end
before(:each) do
page.driver.headers = { 'User-Agent' => ' JamKazam ' }
visit "/"
find('h1', text: 'Play music together over the Internet as if in the same room')
end
let(:user) { FactoryGirl.create(:user) }
describe "signup" do
before(:each) do
find('#signup').trigger(:click)
end
it "show dialog" do
should have_selector('h1', text: 'sign up for jamkazam')
end
describe "signup with email" do
it "click will redirect to signup page" do
find('.signup-email').trigger(:click)
find('h2', text: 'Create a JamKazam account')
end
end
# this works becuause OmniAuth.config_mode.test = true
describe "signup with facebook" do
before(:each) do
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new({
:provider => "facebook",
:uid => "1234",
:info => {:name => "John Doe",
:email => "johndoe@email.com"},
:credentials => {:token => "testtoken234tsdf", :expires_at => 2391456019},
:extra => { :raw_info => {:first_name => 'John', :last_name => 'Doe', :email => 'facebook@jamkazam.com', :gender => 'male'}} })
end
it "click will redirect to facebook for authorization" do
find('.signup-facebook').trigger(:click)
find('h2', text: 'Create a JamKazam account')
find_field('jam_ruby_user[first_name]').value.should eq 'John'
find_field('jam_ruby_user[last_name]').value.should eq 'Doe'
find_field('jam_ruby_user[email]').value.should eq 'facebook@jamkazam.com'
end
end
end
end

View File

@ -15,7 +15,16 @@ describe UserManager do
MaxMindIsp.delete_all # prove that city/state/country will remain nil if no maxmind data
MaxMindGeo.delete_all
@user = @user_manager.signup("127.0.0.1", "bob", "smith", "userman1@jamkazam.com", "foobar", "foobar", true, @instruments, nil, nil, true, nil, nil, "http://localhost:3000/confirm" )
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "bob",
last_name: "smith",
email: "userman1@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician:true,
signup_confirm_url: "http://localhost:3000/confirm" )
@user.errors.any?.should be_false
@user.first_name.should == "bob"
@ -33,8 +42,16 @@ describe UserManager do
end
it "signup successfully with instruments" do
@user = @user_manager.signup("127.0.0.1", "bob", "smith", "userman2@jamkazam.com", "foobar", "foobar", true,
@instruments, nil, nil, true, nil, nil, "http://localhost:3000/confirm")
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "bob",
last_name: "smith",
email: "userman2@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
signup_confirm_url: "http://localhost:3000/confirm")
@user.errors.any?.should be_false
@user.instruments.length.should == 1
@ -44,7 +61,15 @@ describe UserManager do
end
it "doesnt fail if ip address is nil" do
@user = @user_manager.signup(nil, "bob", "smith", "userman3@jamkazam.com", "foobar", "foobar", true, @instruments, nil, nil, true, nil, nil, "http://localhost:3000/confirm" )
@user = @user_manager.signup(first_name: "bob",
last_name: "smith",
email: "userman3@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
signup_confirm_url: "http://localhost:3000/confirm" )
@user.errors.any?.should be_false
@user.city.should be_nil
@ -56,7 +81,16 @@ describe UserManager do
MaxMindManager.active_record_transaction do |manager|
manager.create_phony_database()
end
@user = @user_manager.signup("127.0.0.1", "bob", "smith", "userman4@jamkazam.com", "foobar", "foobar", true, @instruments, nil, nil, true, nil, nil, "http://localhost:3000/confirm" )
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "bob",
last_name: "smith",
email: "userman4@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
signup_confirm_url: "http://localhost:3000/confirm" )
@user.errors.any?.should be_false
@user.city.should == 'City 127'
@ -68,7 +102,17 @@ describe UserManager do
MaxMindManager.active_record_transaction do |manager|
manager.create_phony_database()
end
@user = @user_manager.signup("127.0.0.1", "bob", "smith", "userman5@jamkazam.com", "foobar", "foobar", true, @instruments, nil, @location, true, nil, nil, "http://localhost:3000/confirm" )
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "bob",
last_name: "smith",
email: "userman5@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
location: @location,
musician: true,
signup_confirm_url: "http://localhost:3000/confirm" )
@user.errors.any?.should be_false
@user.city.should == 'Little Rock'
@ -80,7 +124,17 @@ describe UserManager do
MaxMindManager.active_record_transaction do |manager|
manager.create_phony_database()
end
@user = @user_manager.signup("127.0.0.1", "bob", "smith", "userman6@jamkazam.com", "foobar", "foobar", true, @instruments, nil, {}, true, nil, nil, "http://localhost:3000/confirm" )
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "bob",
last_name: "smith",
email: "userman6@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
location: {},
musician: true,
signup_confirm_url: "http://localhost:3000/confirm" )
@user.errors.any?.should be_false
@user.city.should be_nil
@ -93,7 +147,17 @@ describe UserManager do
MaxMindManager.active_record_transaction do |manager|
manager.create_phony_database()
end
@user = @user_manager.signup("127.0.0.1", "bob", "smith", "userman7@jamkazam.com", "foobar", "foobar", true, @instruments, Date.new(2001, 1, 1), nil, true, nil, nil, "http://localhost:3000/confirm" )
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "bob",
last_name: "smith",
email: "userman7@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
birth_date: Date.new(2001, 1, 1),
musician: true,
signup_confirm_url: "http://localhost:3000/confirm" )
@user.errors.any?.should be_false
@user.birth_date.should == Date.new(2001, 1, 1)
@ -101,26 +165,64 @@ describe UserManager do
it "duplicate signup failure" do
@user = @user_manager.signup("127.0.0.1", "bob", "smith", "userman8@jamkazam.com", "foobar", "foobar", true, @instruments, nil, nil, true, nil, nil, "http://localhost:3000/confirm")
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "bob",
last_name: "smith",
email: "userman8@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
signup_confirm_url: "http://localhost:3000/confirm")
UserMailer.deliveries.length.should == 1
@user.errors.any?.should be_false
# exactly the same parameters; should dup on email, and send no email
@user = @user_manager.signup("127.0.0.1", "bob", "smith", "userman8@jamkazam.com", "foobar", "foobar", true, @instruments, nil, nil, true, nil, nil, "http://localhost:3000/confirm")
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "bob",
last_name: "smith",
email: "userman8@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
signup_confirm_url: "http://localhost:3000/confirm")
UserMailer.deliveries.length.should == 1
@user.errors.any?.should be_true
@user.errors[:email][0].should == "has already been taken"
end
it "fail on no username" do
@user = @user_manager.signup("127.0.0.1", "", "", "userman10@jamkazam.com", "foobar", "foobar", true, @instruments, nil, nil, true, nil, nil, "http://localhost:3000/confirm")
it "fail on no first_name/last_name" do
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "",
last_name: "",
email: "userman10@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
signup_confirm_url: "http://localhost:3000/confirm")
UserMailer.deliveries.length.should == 0
@user.errors.any?.should be_true
@user.errors[:first_name][0].should == "can't be blank"
end
it "fail on no email" do
@user = @user_manager.signup("127.0.0.1", "murp", "blurp", "", "foobar", "foobar", true, @instruments, nil, nil, true, nil, nil, "http://localhost:3000/confirm" )
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "murp",
last_name: "blurp",
email: "",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
signup_confirm_url: "http://localhost:3000/confirm")
UserMailer.deliveries.length.should == 0
@user.errors.any?.should be_true
@user.errors[:email][0].should == "can't be blank"
@ -130,7 +232,16 @@ describe UserManager do
describe "signup_confirm" do
it "fail on no username" do
@user = @user_manager.signup("127.0.0.1", "bob", "smith", "userman11@jamkazam.com", "foobar", "foobar", true, @instruments, nil, nil, true, nil, nil, "http://localhost:3000/confirm" )
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "bob",
last_name: "smith",
email: "userman11@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
signup_confirm_url: "http://localhost:3000/confirm")
@user = @user_manager.signup_confirm(@user.signup_token)
@user.email_confirmed.should be_true
end
@ -156,8 +267,17 @@ describe UserManager do
@invitation.accepted.should be_false
@user = @user_manager.signup("127.0.0.1", "bob", "smith", @invitation.email, "foobar", "foobar", true,
@instruments, nil, nil, true, nil, @invitation, "http://localhost:3000/confirm")
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "bob",
last_name: "smith",
email: @invitation.email,
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
invited_user: @invitation,
signup_confirm_url: "http://localhost:3000/confirm")
@user.errors.any?.should be_false
@user.email_confirmed.should be_true
@ -176,8 +296,17 @@ describe UserManager do
UserMailer.deliveries.clear
@user = @user_manager.signup("127.0.0.1", "bob", "smith", @invitation.email, "foobar", "foobar", true,
@instruments, nil, nil, true, nil, @invitation, "http://localhost:3000/confirm")
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "bob",
last_name: "smith",
email: @invitation.email,
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
invited_user: @invitation,
signup_confirm_url: "http://localhost:3000/confirm")
@user.errors.any?.should be_false
@user.email_confirmed.should be_true
@ -196,8 +325,17 @@ describe UserManager do
UserMailer.deliveries.clear
@user = @user_manager.signup("127.0.0.1", "bob", "smith", @invitation.email, "foobar", "foobar", true,
@instruments, nil, nil, true, nil, @invitation, "http://localhost:3000/confirm")
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "bob",
last_name: "smith",
email: @invitation.email,
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
invited_user: @invitation,
signup_confirm_url: "http://localhost:3000/confirm")
@user.errors.any?.should be_false
@user.email_confirmed.should be_true
@ -218,8 +356,17 @@ describe UserManager do
UserMailer.deliveries.clear
@user = @user_manager.signup("127.0.0.1", "bob", "smith", "userman12@jamkazam.com", "foobar", "foobar", true,
@instruments, nil, nil, true, nil, @invitation, "http://localhost:3000/confirm")
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "bob",
last_name: "smith",
email: "userman12@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
invited_user: @invitation,
signup_confirm_url: "http://localhost:3000/confirm")
@user.errors.any?.should be_false
@user.email_confirmed.should be_false
@ -229,6 +376,91 @@ describe UserManager do
@user.friends?(@some_user).should be_true
@user.friends?(@some_user).should be_true
UserMailer.deliveries.length.should == 1 # no emails should be sent, in this case
UserMailer.deliveries.length.should == 1
end
it "signup successfully with facebook signup additional info" do
fb_signup = FactoryGirl.create(:facebook_signup)
UserMailer.deliveries.clear
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "bob",
last_name: "smith",
email: fb_signup.email,
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
fb_signup: fb_signup,
signup_confirm_url: "http://localhost:3000/confirm")
@user.errors.any?.should be_false
@user.email_confirmed.should be_true
@user.signup_token.should be_nil
@user.user_authorizations.length.should == 1
@user.user_authorizations[0].uid = fb_signup.uid
@user.user_authorizations[0].token = fb_signup.token
@user.user_authorizations[0].token_expiration = fb_signup.token_expires_at
UserMailer.deliveries.length.should == 1
end
it "signup successfully with facebook signup additional info, but different email" do
fb_signup = FactoryGirl.create(:facebook_signup)
UserMailer.deliveries.clear
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "bob",
last_name: "smith",
email: "userman13@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
fb_signup: fb_signup,
signup_confirm_url: "http://localhost:3000/confirm")
@user.errors.any?.should be_false
@user.email_confirmed.should be_false
@user.signup_token.should_not be_nil
@user.user_authorizations.length.should == 1
@user.user_authorizations[0].uid = fb_signup.uid
@user.user_authorizations[0].token = fb_signup.token
@user.user_authorizations[0].token_expiration = fb_signup.token_expires_at
UserMailer.deliveries.length.should == 1
end
it "fail to signup when facebook UID already taken" do
fb_signup = FactoryGirl.create(:facebook_signup)
@some_user = FactoryGirl.create(:user)
@some_user.update_fb_authorization(fb_signup)
@some_user.save!
UserMailer.deliveries.clear
@user = @user_manager.signup(remote_ip: "127.0.0.1",
first_name: "bob",
last_name: "smith",
email: "userman13@jamkazam.com",
password: "foobar",
password_confirmation: "foobar",
terms_of_service: true,
instruments: @instruments,
musician: true,
fb_signup: fb_signup,
signup_confirm_url: "http://localhost:3000/confirm")
@user.errors.any?.should be_true
@user.errors[:user_authorizations].should == ['is invalid']
UserMailer.deliveries.length.should == 0
end
end

View File

@ -1,5 +1,6 @@
require 'rubygems'
require 'spork'
require 'omniauth'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
@ -25,6 +26,8 @@ include JamRuby
# put ActionMailer into test mode
ActionMailer::Base.delivery_method = :test
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll