jam-cloud/web/lib/user_manager.rb

123 lines
4.8 KiB
Ruby
Raw Normal View History

require 'google_client'
2012-11-14 05:37:50 +00:00
class UserManager < BaseManager
def initialize(options={})
super(options)
@log = Logging.logger[self]
@google_client = GoogleClient.new()
2012-11-14 05:37:50 +00:00
end
2017-06-10 20:34:08 +00:00
def get_google_client
@google_client
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]
signup_hint = options[:signup_hint]
2015-05-28 13:20:14 +00:00
affiliate_partner = options[:affiliate_partner]
gift_card = options[:gift_card]
2016-02-11 03:09:45 +00:00
student = options[:student]
teacher = options[:teacher]
school_invitation_code = options[:school_invitation_code]
school_id = options[:school_id]
2016-09-27 02:56:12 +00:00
retailer_invitation_code = options[:retailer_invitation_code]
retailer_id = options[:retailer_id]
2016-10-07 13:28:17 +00:00
retailer_interest = options[:retailer_interest]
school_interest = options[:school_interest]
education_interest = options[:education_interest]
2016-05-23 17:26:32 +00:00
origin = options[:origin]
test_drive_package = options[:test_drive_package]
2017-10-15 21:42:45 +00:00
under_13 = options[:under_13]
2018-02-15 04:16:32 +00:00
timezone = options[:timezone]
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
user = User.new
2012-11-14 05:37:50 +00:00
# check if we have disabled open signup for this site. open == invited users can still get in
if !SampleApp::Application.config.signup_enabled && invited_user.nil?
raise JamPermissionError, "Signups are currently disabled"
2013-02-08 03:11:47 +00:00
end
loc = GeoIpLocations.lookup(remote_ip)
# 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.
unless location.nil?
loc[:city] = location[:city]
loc[:state] = location[:state]
loc[:country] = location[:country]
2013-03-15 04:23:37 +00:00
end
# sends email to email account for confirmation
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,
location: loc,
2014-02-03 21:19:14 +00:00
instruments: instruments,
birth_date: birth_date,
musician: musician,
photo_url: photo_url,
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,
any_user: any_user,
2015-05-28 13:20:14 +00:00
signup_hint: signup_hint,
affiliate_partner: affiliate_partner,
2016-02-11 03:09:45 +00:00
gift_card: gift_card,
student: student,
teacher: teacher,
school_invitation_code: school_invitation_code,
school_id: school_id,
2016-09-27 02:56:12 +00:00
retailer_invitation_code: retailer_invitation_code,
retailer_id: retailer_id,
2016-10-07 13:28:17 +00:00
retailer_interest: retailer_interest,
2016-05-23 17:26:32 +00:00
school_interest: school_interest,
education_interest: education_interest,
origin: origin,
2017-10-15 21:42:45 +00:00
test_drive_package: test_drive_package,
2018-02-15 04:16:32 +00:00
under_13: under_13,
timezone: timezone)
2015-03-20 13:48:00 +00:00
user
2012-11-14 05:37:50 +00:00
end
def signup_confirm(signup_token, remote_ip=nil)
2012-11-14 05:37:50 +00:00
begin
user = User.signup_confirm(signup_token)
user.location = GeoIpLocations.lookup(remote_ip) if remote_ip
2012-11-14 05:37:50 +00:00
rescue ActiveRecord::RecordNotFound
user = nil
2012-11-14 05:37:50 +00:00
end
return user
2012-11-14 05:37:50 +00:00
end
2012-11-15 08:47:19 +00:00
end