2015-01-11 23:04:16 +00:00
|
|
|
require 'google_client'
|
2012-11-14 05:37:50 +00:00
|
|
|
class UserManager < BaseManager
|
|
|
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
|
super(options)
|
|
|
|
|
@log = Logging.logger[self]
|
2015-01-11 23:04:16 +00:00
|
|
|
@google_client = GoogleClient.new()
|
2012-11-14 05:37:50 +00:00
|
|
|
end
|
|
|
|
|
|
2012-11-30 09:36:41 +00:00
|
|
|
# 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.
|
2014-02-03 21:19:14 +00:00
|
|
|
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]
|
2014-04-20 22:54:49 +00:00
|
|
|
affiliate_referral_id = options[:affiliate_referral_id]
|
2015-03-20 13:48:00 +00:00
|
|
|
any_user = options[:any_user]
|
2015-05-15 17:34:35 +00:00
|
|
|
signup_hint = options[:signup_hint]
|
2015-05-28 13:20:14 +00:00
|
|
|
affiliate_partner = options[:affiliate_partner]
|
2015-11-13 13:12:58 +00:00
|
|
|
gift_card = options[:gift_card]
|
2016-02-11 03:09:45 +00:00
|
|
|
student = options[:student]
|
|
|
|
|
teacher = options[:teacher]
|
2015-05-15 17:34:35 +00:00
|
|
|
|
2015-03-20 13:48:00 +00:00
|
|
|
recaptcha_failed = false
|
|
|
|
|
unless options[:skip_recaptcha] # allow callers to opt-of recaptcha
|
|
|
|
|
recaptcha_failed = fb_signup ? false : !@google_client.verify_recaptcha(options[:recaptcha_response])
|
|
|
|
|
end
|
|
|
|
|
|
2014-05-13 19:56:58 +00:00
|
|
|
user = User.new
|
2012-11-14 05:37:50 +00:00
|
|
|
|
2013-07-31 14:09:09 +00:00
|
|
|
# check if we have disabled open signup for this site. open == invited users can still get in
|
2013-07-31 15:07:41 +00:00
|
|
|
if !SampleApp::Application.config.signup_enabled && invited_user.nil?
|
2015-04-20 14:50:33 +00:00
|
|
|
raise JamPermissionError, "Signups are currently disabled"
|
2013-02-08 03:11:47 +00:00
|
|
|
end
|
|
|
|
|
|
2014-07-20 02:11:16 +00:00
|
|
|
loc = GeoIpLocations.lookup(remote_ip)
|
2014-05-09 00:44:52 +00:00
|
|
|
# there are three cases here: if location is missing, we'll auto set the city, etc. from
|
|
|
|
|
# the ip address; if location is present, empty or not empty, we'll set the city, etc. from
|
|
|
|
|
# what is present in location. we should NOT normally default city, etc. for the user, they
|
|
|
|
|
# own it, they may want it to be unspecified, that is their right.
|
2014-05-13 19:56:58 +00:00
|
|
|
unless location.nil?
|
2014-05-09 00:44:52 +00:00
|
|
|
loc[:city] = location[:city]
|
|
|
|
|
loc[:state] = location[:state]
|
|
|
|
|
loc[:country] = location[:country]
|
2013-03-15 04:23:37 +00:00
|
|
|
end
|
2012-12-02 06:46:30 +00:00
|
|
|
|
|
|
|
|
# sends email to email account for confirmation
|
2014-05-13 19:56:58 +00:00
|
|
|
user = User.signup(first_name: first_name,
|
2014-02-03 21:19:14 +00:00
|
|
|
last_name: last_name,
|
|
|
|
|
email: email,
|
|
|
|
|
password: password,
|
|
|
|
|
password_confirmation: password_confirmation,
|
|
|
|
|
terms_of_service: terms_of_service,
|
2014-05-09 00:44:52 +00:00
|
|
|
location: loc,
|
2014-02-03 21:19:14 +00:00
|
|
|
instruments: instruments,
|
|
|
|
|
birth_date: birth_date,
|
|
|
|
|
musician: musician,
|
|
|
|
|
photo_url: photo_url,
|
2015-01-05 23:01:28 +00:00
|
|
|
recaptcha_failed: recaptcha_failed,
|
2014-02-03 21:19:14 +00:00
|
|
|
invited_user: invited_user,
|
|
|
|
|
fb_signup: fb_signup,
|
2014-04-20 22:54:49 +00:00
|
|
|
signup_confirm_url: signup_confirm_url,
|
2015-03-20 13:48:00 +00:00
|
|
|
affiliate_referral_id: affiliate_referral_id,
|
2015-05-15 17:34:35 +00:00
|
|
|
any_user: any_user,
|
2015-05-28 13:20:14 +00:00
|
|
|
signup_hint: signup_hint,
|
2015-11-13 13:12:58 +00:00
|
|
|
affiliate_partner: affiliate_partner,
|
2016-02-11 03:09:45 +00:00
|
|
|
gift_card: gift_card,
|
|
|
|
|
student: student,
|
|
|
|
|
teacher: teacher)
|
2015-03-20 13:48:00 +00:00
|
|
|
user
|
2012-11-14 05:37:50 +00:00
|
|
|
end
|
|
|
|
|
|
2013-01-06 12:36:55 +00:00
|
|
|
def signup_confirm(signup_token, remote_ip=nil)
|
2012-11-14 05:37:50 +00:00
|
|
|
begin
|
2014-05-13 19:56:58 +00:00
|
|
|
user = User.signup_confirm(signup_token)
|
2014-07-20 02:11:16 +00:00
|
|
|
user.location = GeoIpLocations.lookup(remote_ip) if remote_ip
|
2012-11-14 05:37:50 +00:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
2014-05-13 19:56:58 +00:00
|
|
|
user = nil
|
2012-11-14 05:37:50 +00:00
|
|
|
end
|
|
|
|
|
|
2014-05-13 19:56:58 +00:00
|
|
|
return user
|
2012-11-14 05:37:50 +00:00
|
|
|
end
|
|
|
|
|
|
2012-11-15 08:47:19 +00:00
|
|
|
end
|