2013-06-14 03:34:34 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
require 'builder'
|
|
|
|
|
|
2014-02-15 21:11:06 +00:00
|
|
|
class Slide
|
|
|
|
|
attr_accessor :img_url, :header, :vid_url
|
|
|
|
|
|
2014-03-05 23:18:53 +00:00
|
|
|
def initialize(header, img_url, vid_url)
|
2014-02-15 21:11:06 +00:00
|
|
|
@img_url = img_url # preview image
|
2014-03-05 23:18:53 +00:00
|
|
|
@header = header
|
2014-02-15 21:11:06 +00:00
|
|
|
@vid_url = vid_url + '?autoplay=1'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2012-08-31 03:01:52 +00:00
|
|
|
class UsersController < ApplicationController
|
2014-02-13 18:27:38 +00:00
|
|
|
|
|
|
|
|
include ClientHelper
|
|
|
|
|
|
2012-11-12 12:59:43 +00:00
|
|
|
before_filter :signed_in_user,
|
2012-09-03 22:03:16 +00:00
|
|
|
only: [:index, :edit, :update, :destroy]
|
2012-08-31 03:01:52 +00:00
|
|
|
before_filter :correct_user, only: [:edit, :update]
|
|
|
|
|
before_filter :admin_user, only: :destroy
|
2014-02-13 18:27:38 +00:00
|
|
|
before_filter :is_native_client
|
|
|
|
|
|
2012-08-31 03:01:52 +00:00
|
|
|
|
2013-02-08 03:11:47 +00:00
|
|
|
rescue_from 'JamRuby::PermissionError' do |exception|
|
|
|
|
|
@exception = exception
|
|
|
|
|
render :file => 'public/403.html', :status => 403, :layout => false
|
|
|
|
|
end
|
2012-11-12 12:59:43 +00:00
|
|
|
|
2012-08-31 03:01:52 +00:00
|
|
|
def index
|
|
|
|
|
@users = User.paginate(page: params[:page])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def show
|
|
|
|
|
@user = User.find(params[:id])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def new
|
2015-03-10 15:29:40 +00:00
|
|
|
@no_user_dropdown = true
|
2013-10-22 17:38:21 +00:00
|
|
|
if current_user
|
2014-02-02 19:34:53 +00:00
|
|
|
redirect_to client_url
|
2013-10-22 17:38:21 +00:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2014-02-03 21:19:14 +00:00
|
|
|
@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
|
|
|
|
|
|
2013-03-15 04:23:37 +00:00
|
|
|
@invited_user = load_invited_user(params)
|
|
|
|
|
|
2014-02-02 03:48:46 +00:00
|
|
|
if !@invited_user.nil? && @invited_user.has_required_email? && @invited_user.accepted
|
2013-03-15 04:23:37 +00:00
|
|
|
# short-circuit out if this invitation is already accepted
|
2013-08-07 15:39:34 +00:00
|
|
|
render "already_signed_up", :layout => 'landing'
|
2013-03-15 04:23:37 +00:00
|
|
|
return
|
|
|
|
|
end
|
2014-02-03 21:19:14 +00:00
|
|
|
@signup_postback = load_postback(@invited_user, @fb_signup)
|
2013-10-01 18:57:02 +00:00
|
|
|
|
2013-10-01 21:49:41 +00:00
|
|
|
load_location(request.remote_ip)
|
2013-03-15 04:23:37 +00:00
|
|
|
|
2012-08-31 03:01:52 +00:00
|
|
|
@user = User.new
|
2013-07-07 03:55:18 +00:00
|
|
|
@user.musician = true # default the UI to musician as selected option
|
2013-03-15 04:23:37 +00:00
|
|
|
|
|
|
|
|
# preseed the form with the invited email as a convenience to the user
|
2014-02-03 21:19:14 +00:00
|
|
|
@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
|
2013-03-15 04:23:37 +00:00
|
|
|
end
|
2013-06-24 21:40:04 +00:00
|
|
|
|
2013-10-22 17:38:21 +00:00
|
|
|
render :layout => 'web'
|
2012-08-31 03:01:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
2014-02-03 21:19:14 +00:00
|
|
|
|
2013-10-22 17:38:21 +00:00
|
|
|
if current_user
|
2014-02-02 19:34:53 +00:00
|
|
|
redirect_to client_url
|
2013-10-22 17:38:21 +00:00
|
|
|
return
|
|
|
|
|
end
|
2013-03-15 04:23:37 +00:00
|
|
|
|
2015-04-14 19:12:24 +00:00
|
|
|
signup_hint = SignupHint.where(anonymous_user_id: anonymous_user.id).where('expires_at > ?', Time.now).first if anonymous_user
|
|
|
|
|
|
2014-02-03 21:19:14 +00:00
|
|
|
@fb_signup = load_facebook_signup(params)
|
|
|
|
|
|
2014-03-21 22:37:15 +00:00
|
|
|
# check if the email specified by @fb_signup already exists in the database--if so, log them in and redirect
|
2014-02-03 21:19:14 +00:00
|
|
|
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)
|
2015-04-14 19:12:24 +00:00
|
|
|
redirect_url = handle_signup_hint(user, signup_hint, client_url)
|
|
|
|
|
redirect_to redirect_url
|
2014-02-03 21:19:14 +00:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-03-21 22:37:15 +00:00
|
|
|
# check if the uid specified by @fb_signup already exists in the database--if so, log them in and redirect
|
2014-02-03 21:19:14 +00:00
|
|
|
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)
|
2015-04-14 19:12:24 +00:00
|
|
|
|
|
|
|
|
redirect_url = handle_signup_hint(user_authorization.user, signup_hint, client_url)
|
|
|
|
|
redirect_to redirect_url
|
2014-02-03 21:19:14 +00:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-03-15 04:23:37 +00:00
|
|
|
@invited_user = load_invited_user(params)
|
2014-02-03 21:19:14 +00:00
|
|
|
@signup_postback = load_postback(@invited_user, @fb_signup)
|
2013-03-15 04:23:37 +00:00
|
|
|
|
2015-01-05 23:01:28 +00:00
|
|
|
|
2013-03-15 04:23:37 +00:00
|
|
|
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)"])
|
|
|
|
|
location = { :country => params[:jam_ruby_user][:country], :state => params[:jam_ruby_user][:state], :city => params[:jam_ruby_user][:city]}
|
2014-07-01 18:19:33 +00:00
|
|
|
terms_of_service = params[:jam_ruby_user][:terms_of_service].nil? || params[:jam_ruby_user][:terms_of_service] == "0"? false : true
|
2013-06-24 21:40:04 +00:00
|
|
|
musician = params[:jam_ruby_user][:musician]
|
2013-03-15 04:23:37 +00:00
|
|
|
|
2014-02-03 21:19:14 +00:00
|
|
|
@user = UserManager.new.signup(remote_ip: request.remote_ip,
|
2014-04-20 22:54:49 +00:00
|
|
|
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,
|
2015-01-11 23:04:16 +00:00
|
|
|
recaptcha_response: params['g-recaptcha-response'],
|
2014-04-20 22:54:49 +00:00
|
|
|
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))
|
2015-01-05 23:01:28 +00:00
|
|
|
|
2012-11-14 05:57:10 +00:00
|
|
|
# check for errors
|
|
|
|
|
if @user.errors.any?
|
|
|
|
|
# render any @user.errors on error
|
2013-03-15 04:23:37 +00:00
|
|
|
load_location(request.remote_ip, location)
|
2013-03-21 03:56:47 +00:00
|
|
|
gon.signup_errors = true
|
2013-03-21 05:04:44 +00:00
|
|
|
gon.musician_instruments = instruments
|
2014-03-06 22:17:32 +00:00
|
|
|
render "new", :layout => 'web'
|
2012-11-14 05:57:10 +00:00
|
|
|
else
|
2013-06-24 21:40:04 +00:00
|
|
|
sign_in @user
|
|
|
|
|
|
2015-04-16 02:37:22 +00:00
|
|
|
new_user(@user, signup_hint) # sets a cookie used for GA analytics (one-time new user stuff in JavaScript)
|
2014-03-27 20:59:03 +00:00
|
|
|
destination = @user.musician ? :congratulations_musician : :congratulations_fan
|
2015-04-14 19:12:24 +00:00
|
|
|
redirect_url = handle_signup_hint(@user, signup_hint, {:action => destination, :type => @user.user_authorization('facebook') ? 'Facebook' : 'Native'})
|
|
|
|
|
redirect_to redirect_url
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-06-24 21:40:04 +00:00
|
|
|
def congratulations_fan
|
2015-03-10 15:29:40 +00:00
|
|
|
@no_user_dropdown = true
|
2013-10-19 19:46:06 +00:00
|
|
|
render :layout => "web"
|
2013-06-24 21:40:04 +00:00
|
|
|
end
|
2012-11-12 12:59:43 +00:00
|
|
|
|
2013-06-24 21:40:04 +00:00
|
|
|
def congratulations_musician
|
2015-03-10 15:29:40 +00:00
|
|
|
@no_user_dropdown = true
|
2013-10-19 19:46:06 +00:00
|
|
|
render :layout => "web"
|
2012-11-12 12:59:43 +00:00
|
|
|
end
|
|
|
|
|
|
2013-09-25 15:34:53 +00:00
|
|
|
def downloads
|
2015-03-10 15:29:40 +00:00
|
|
|
@no_user_dropdown = true
|
2015-04-27 15:35:09 +00:00
|
|
|
@page_context = 'standalone'
|
2013-10-19 19:46:06 +00:00
|
|
|
render :layout => "web"
|
2013-09-25 15:34:53 +00:00
|
|
|
end
|
|
|
|
|
|
2015-04-09 03:43:57 +00:00
|
|
|
# DO NOT USE CURRENT_USER IN THIS ROUTINE. IT'S CACHED FOR THE WHOLE SITE
|
|
|
|
|
def home
|
|
|
|
|
|
2015-05-05 14:31:11 +00:00
|
|
|
@no_user_dropdown = false
|
2015-04-09 03:43:57 +00:00
|
|
|
@promo_buzz = PromoBuzz.active
|
|
|
|
|
|
|
|
|
|
if Rails.application.config.use_promos_on_homepage
|
|
|
|
|
@promo_latest = PromoLatest.active
|
|
|
|
|
else
|
|
|
|
|
@promo_latest, start = Feed.index(nil, limit: 10)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gon.signed_in = !current_user.nil?
|
2014-02-01 19:17:30 +00:00
|
|
|
render :layout => "web"
|
|
|
|
|
end
|
|
|
|
|
|
2012-11-12 12:59:43 +00:00
|
|
|
def signup_confirm
|
2013-03-08 06:45:06 +00:00
|
|
|
signup_token = params[:signup_token]
|
|
|
|
|
|
|
|
|
|
@user = UserManager.new.signup_confirm(signup_token, request.remote_ip)
|
2012-11-12 12:59:43 +00:00
|
|
|
|
2013-03-01 13:36:25 +00:00
|
|
|
if !@user.nil? && !@user.errors.any?
|
2013-09-27 04:08:10 +00:00
|
|
|
UserMailer.welcome_message(@user).deliver
|
2013-03-01 13:36:25 +00:00
|
|
|
elsif !@user.nil?
|
2013-03-08 06:45:06 +00:00
|
|
|
# new user with validation errors;
|
2013-03-01 13:36:25 +00:00
|
|
|
logger.debug("#{@user} has errors. can not sign in until remedied. #{@user.errors.inspect}")
|
2013-03-08 06:45:06 +00:00
|
|
|
end
|
|
|
|
|
# let page have signup_token in javascript
|
|
|
|
|
gon.signup_token = signup_token
|
2013-03-01 13:36:25 +00:00
|
|
|
|
2012-11-12 12:59:43 +00:00
|
|
|
# let errors fall through to signup_confirm.html.erb
|
2014-03-15 01:25:37 +00:00
|
|
|
render :layout => 'web'
|
2012-11-12 12:59:43 +00:00
|
|
|
end
|
|
|
|
|
|
2012-08-31 03:01:52 +00:00
|
|
|
def edit
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
2012-09-01 20:24:51 +00:00
|
|
|
if @user.update_attributes(params[:jam_ruby_user])
|
2012-08-31 03:01:52 +00:00
|
|
|
flash[:success] = "Profile updated"
|
|
|
|
|
sign_in @user
|
|
|
|
|
redirect_to @user
|
|
|
|
|
else
|
|
|
|
|
render 'edit'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
User.find(params[:id]).destroy
|
|
|
|
|
flash[:success] = "User destroyed."
|
|
|
|
|
redirect_to users_url
|
|
|
|
|
end
|
|
|
|
|
|
2012-12-28 07:31:12 +00:00
|
|
|
def request_reset_password
|
2013-07-05 08:24:43 +00:00
|
|
|
render 'request_reset_password', :layout => 'landing'
|
2012-12-28 07:31:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def reset_password
|
|
|
|
|
begin
|
2013-07-05 08:24:43 +00:00
|
|
|
@reset_password_email = params[:jam_ruby_user][:email]
|
|
|
|
|
|
2014-04-01 23:38:36 +00:00
|
|
|
if @reset_password_email.blank?
|
|
|
|
|
@reset_password_error = "Please enter an email address"
|
|
|
|
|
render 'request_reset_password', :layout => 'landing'
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@reset_password_email.strip!
|
|
|
|
|
|
|
|
|
|
unless User::VALID_EMAIL_REGEX.match(@reset_password_email)
|
|
|
|
|
@reset_password_error = "Please enter a valid email address"
|
2013-07-05 08:24:43 +00:00
|
|
|
render 'request_reset_password', :layout => 'landing'
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@user = User.reset_password(@reset_password_email, ApplicationHelper.base_uri(request))
|
|
|
|
|
render 'sent_reset_password', :layout => 'landing'
|
2012-12-28 07:31:12 +00:00
|
|
|
rescue JamRuby::JamArgumentError
|
2013-07-05 08:24:43 +00:00
|
|
|
# Dont tell the user if this error occurred to prevent scraping email addresses.
|
|
|
|
|
render 'sent_reset_password', :layout => 'landing'
|
2012-12-28 07:31:12 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def reset_password_token
|
2013-07-05 08:24:43 +00:00
|
|
|
render 'reset_password_token', :layout => 'landing'
|
2012-12-28 07:31:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def reset_password_complete
|
|
|
|
|
begin
|
|
|
|
|
User.set_password_from_token(params[:jam_ruby_user][:email], params[:jam_ruby_user][:token],
|
|
|
|
|
params[:jam_ruby_user][:password], params[:jam_ruby_user][:password_confirmation])
|
2013-07-05 08:24:43 +00:00
|
|
|
render 'reset_password_complete', :layout => 'landing'
|
|
|
|
|
rescue JamRuby::JamArgumentError
|
|
|
|
|
@password_error = "Entries don't match or are too short"
|
2012-12-28 07:31:12 +00:00
|
|
|
params[:email] = params[:jam_ruby_user][:email]
|
|
|
|
|
params[:token] = params[:jam_ruby_user][:token]
|
2013-07-05 08:24:43 +00:00
|
|
|
render 'reset_password_token', :layout => 'landing'
|
2012-12-28 07:31:12 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-05-13 19:34:03 +00:00
|
|
|
def finalize_update_email
|
|
|
|
|
# this corresponds to when the user clink a link in their new email address to configure they want to use it,
|
|
|
|
|
# and verify their new address is real
|
|
|
|
|
token = params[:token]
|
|
|
|
|
|
2013-05-20 18:23:49 +00:00
|
|
|
gon.ensure = true
|
2013-05-13 19:34:03 +00:00
|
|
|
gon.update_email_token = token
|
|
|
|
|
|
2013-05-20 18:23:49 +00:00
|
|
|
render :layout => 'landing'
|
2013-05-13 19:34:03 +00:00
|
|
|
end
|
|
|
|
|
|
2013-06-14 03:34:34 +00:00
|
|
|
def jnlp
|
|
|
|
|
headers["Content-Type"] = "application/x-java-jnlp-file"
|
|
|
|
|
headers["Cache-Control"] = "public"
|
|
|
|
|
headers["Content-Disposition"] = "attachment;filename='ping#{params[:isp]}.jnlp'"
|
|
|
|
|
jnlp = ''
|
|
|
|
|
xml = Builder::XmlMarkup.new(:indent => 2, :target => jnlp)
|
|
|
|
|
xml.instruct!
|
2013-06-19 15:03:02 +00:00
|
|
|
jnlpurl = isp_ping_url(:isp => params[:isp],
|
|
|
|
|
:format => :jnlp,
|
|
|
|
|
:host => 'www.jamkazam.com',
|
|
|
|
|
:port => '80')
|
2013-06-14 03:34:34 +00:00
|
|
|
xml.jnlp(:spec => '1.0+',
|
2013-06-19 15:03:02 +00:00
|
|
|
:href => jnlpurl,
|
2013-06-19 18:21:49 +00:00
|
|
|
:codebase => "http://www.jamkazam.com/isp") do
|
2013-06-14 03:34:34 +00:00
|
|
|
xml.information do
|
|
|
|
|
xml.title 'Ping'
|
|
|
|
|
xml.vendor 'JamKazam'
|
|
|
|
|
end
|
|
|
|
|
xml.resources do
|
2013-06-19 08:14:22 +00:00
|
|
|
xml.j2se(:version => "1.6+", :href => "http://java.sun.com/products/autodl/j2se")
|
2013-06-19 18:21:49 +00:00
|
|
|
xml.jar(:href => 'http://www.jamkazam.com/isp/ping.jar', :main => 'true')
|
2013-06-14 03:34:34 +00:00
|
|
|
end
|
|
|
|
|
xml.tag!('application-desc',
|
|
|
|
|
:name => "Ping",
|
|
|
|
|
'main-class' => "com.jamkazam.ping.Ping",
|
|
|
|
|
:width => "400",
|
|
|
|
|
:height => "600") do
|
|
|
|
|
xml.comment!('usage: Ping [label=]addr[:port] ... [-c <count>] [-s <size>] -u <url> -i <isp> [-a]')
|
|
|
|
|
xml.argument('foo=etch.dyndns.org:4442')
|
|
|
|
|
xml.argument('bar=etch.dyndns.org:4442')
|
|
|
|
|
xml.argument("-uhttp://www.jamkazam.com#{isp_scoring_path}")
|
|
|
|
|
xml.argument("-i#{params[:isp]}")
|
|
|
|
|
xml.argument('-a')
|
|
|
|
|
end
|
|
|
|
|
xml.update(:check => 'background')
|
|
|
|
|
end
|
|
|
|
|
send_data jnlp, :type=>"application/x-java-jnlp-file"
|
|
|
|
|
end
|
|
|
|
|
|
2013-06-09 14:12:03 +00:00
|
|
|
def isp
|
2013-06-14 03:34:34 +00:00
|
|
|
@isps = {
|
2013-06-15 10:46:30 +00:00
|
|
|
'tw' => ['Time Warner', 'tw.jpg'],
|
|
|
|
|
'vz' => ['Verizon', 'vz.png'],
|
|
|
|
|
'att' => ['AT&T', 'att.png'],
|
|
|
|
|
'cc' => ['Comcast', 'cc.png'],
|
|
|
|
|
'other' => ['Other', 'other.jpg']
|
2013-06-14 03:34:34 +00:00
|
|
|
}
|
2013-06-09 14:12:03 +00:00
|
|
|
render :layout => "landing"
|
|
|
|
|
end
|
|
|
|
|
|
2014-04-07 07:54:17 +00:00
|
|
|
def endorse
|
2014-05-11 00:17:44 +00:00
|
|
|
if uu = current_user ||
|
2014-05-19 15:12:59 +00:00
|
|
|
uu = User.where(['id = ? AND first_social_promoted_at IS NULL',params[:id]]).limit(1).first
|
|
|
|
|
uu.first_social_promoted_at = Time.now
|
2014-04-07 07:54:17 +00:00
|
|
|
uu.save!
|
2014-05-11 00:17:44 +00:00
|
|
|
end if params[:id].present? && (service=params[:service]).present?
|
2014-04-07 07:54:17 +00:00
|
|
|
|
2014-05-11 00:17:44 +00:00
|
|
|
service ||= 'facebook'
|
2015-05-15 21:14:18 +00:00
|
|
|
url = CGI::escape('https://www.jamkazam.com')
|
2014-05-11 00:17:44 +00:00
|
|
|
txt = CGI::escape('Check out JamKazam -- Play music together over the Internet as if in the same room')
|
2014-04-07 07:54:17 +00:00
|
|
|
if 'twitter'==service
|
2014-05-11 00:17:44 +00:00
|
|
|
url = "https://twitter.com/intent/tweet?text=#{txt}&url=#{url}"
|
2014-04-07 07:54:17 +00:00
|
|
|
elsif 'facebook'==service
|
2015-05-15 21:14:18 +00:00
|
|
|
url = "https://www.facebook.com/sharer/sharer.php?u=#{url}&t=#{txt}"
|
2014-04-07 07:54:17 +00:00
|
|
|
elsif 'google'==service
|
2014-05-11 00:17:44 +00:00
|
|
|
url = "https://plus.google.com/share?url=#{url}"
|
2014-04-07 07:54:17 +00:00
|
|
|
end
|
2014-05-11 06:42:20 +00:00
|
|
|
if 'email'==params[:src]
|
|
|
|
|
js =<<JS
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
$(function() {
|
2014-05-11 07:42:14 +00:00
|
|
|
JK.GA.trackJKSocial(JK.GA.Categories.jkLike, '#{service}', 'email');
|
2014-05-11 06:42:20 +00:00
|
|
|
window.location = "#{url}";
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
JS
|
|
|
|
|
render :inline => js, :layout => 'landing'
|
|
|
|
|
else
|
|
|
|
|
redirect_to url
|
|
|
|
|
end
|
2014-04-07 07:54:17 +00:00
|
|
|
end
|
|
|
|
|
|
2015-04-12 06:18:31 +00:00
|
|
|
def unsubscribe
|
|
|
|
|
unless @user = User.read_access_token(params[:user_token])
|
|
|
|
|
redirect_to '/'
|
|
|
|
|
end if params[:user_token].present?
|
|
|
|
|
|
|
|
|
|
if request.get?
|
|
|
|
|
|
|
|
|
|
elsif request.post?
|
|
|
|
|
@user.subscribe_email = false
|
|
|
|
|
@user.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2012-08-31 03:01:52 +00:00
|
|
|
private
|
|
|
|
|
|
2014-02-13 18:27:38 +00:00
|
|
|
def is_native_client
|
|
|
|
|
@nativeClient = is_native_client?
|
|
|
|
|
end
|
|
|
|
|
|
2012-12-22 00:56:49 +00:00
|
|
|
def correct_user
|
|
|
|
|
@user = User.find(params[:id])
|
|
|
|
|
redirect_to(root_url) unless current_user?(@user)
|
|
|
|
|
end
|
2012-08-31 03:01:52 +00:00
|
|
|
|
2013-03-15 04:23:37 +00:00
|
|
|
# the User Model expects instruments in a different format than the form submits it
|
|
|
|
|
# so we have to fix it up.
|
|
|
|
|
def fixup_instruments(original_instruments)
|
|
|
|
|
# if an instrument is selected by the user in the form, it'll show up in this array
|
|
|
|
|
instruments = []
|
|
|
|
|
|
|
|
|
|
# ok, sweep through all the fields submitted, looking for selected instruments.
|
|
|
|
|
# also, make up priority because we don't ask for it (but users can fix it later on their profile)
|
|
|
|
|
priority = 0
|
2013-07-07 03:55:18 +00:00
|
|
|
unless original_instruments == nil
|
|
|
|
|
original_instruments.each do |key, value|
|
|
|
|
|
if !value["selected"].nil?
|
|
|
|
|
instruments << { :instrument_id => key, :proficiency_level => value["proficiency"].to_i, :priority => priority }
|
|
|
|
|
priority = priority + 1
|
|
|
|
|
end
|
2013-03-15 04:23:37 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return instruments
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# the User Model expects instruments in a different format than the form submits it
|
|
|
|
|
# so we have to fix it up.
|
|
|
|
|
def fixup_birthday(month, day, year)
|
|
|
|
|
if month.blank? || day.blank? || year.blank?
|
|
|
|
|
# invalid birthdate, so return nil
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return Date.new(year.to_i, month.to_i, day.to_i)
|
|
|
|
|
end
|
|
|
|
|
|
2014-02-03 21:19:14 +00:00
|
|
|
def load_facebook_signup(params)
|
|
|
|
|
lookup_id = params[:facebook_signup]
|
|
|
|
|
|
|
|
|
|
FacebookSignup.find_by_lookup_id(lookup_id)
|
|
|
|
|
end
|
|
|
|
|
|
2013-03-15 04:23:37 +00:00
|
|
|
def load_invited_user(params)
|
|
|
|
|
# check if this an anonymous request, or result of invitation code
|
|
|
|
|
invitation_code = params[:invitation_code]
|
|
|
|
|
|
|
|
|
|
invited_user = nil
|
|
|
|
|
unless invitation_code.nil?
|
|
|
|
|
# we only want to find invitations that have not been accepted
|
|
|
|
|
invited_user = InvitedUser.find_by_invitation_code(invitation_code)
|
|
|
|
|
end
|
|
|
|
|
return invited_user
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def load_location(remote_ip, location = nil)
|
2014-07-29 23:49:36 +00:00
|
|
|
# useful if you need to repro something on 127.0.0.1
|
|
|
|
|
# remote_ip = ' 23.119.29.89'
|
|
|
|
|
|
2013-03-15 04:23:37 +00:00
|
|
|
@location = location
|
|
|
|
|
|
|
|
|
|
if @location.nil?
|
2014-07-20 02:11:16 +00:00
|
|
|
@location = GeoIpLocations.lookup(remote_ip)
|
2013-03-15 04:23:37 +00:00
|
|
|
end
|
|
|
|
|
|
2013-05-18 18:04:04 +00:00
|
|
|
@location[:country] = "US" if @location[:country].nil?
|
2013-03-15 04:23:37 +00:00
|
|
|
|
2014-07-20 02:11:16 +00:00
|
|
|
@countriesx = MaxMindManager.countries
|
2013-03-15 04:23:37 +00:00
|
|
|
# populate regions based on current country
|
|
|
|
|
@regions = MaxMindManager.regions(@location[:country])
|
|
|
|
|
@cities = @location[:state].nil? ? [] : MaxMindManager.cities(@location[:country], @location[:state])
|
|
|
|
|
end
|
|
|
|
|
|
2014-02-03 21:19:14 +00:00
|
|
|
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
|
2014-03-06 22:17:32 +00:00
|
|
|
if query.length > 0
|
|
|
|
|
signup_path + "?" + query.to_query
|
|
|
|
|
else
|
|
|
|
|
signup_path
|
|
|
|
|
end
|
2015-01-05 23:01:28 +00:00
|
|
|
end
|
2012-08-31 13:18:37 +00:00
|
|
|
end
|