jam-cloud/web/lib/user_manager.rb

89 lines
3.2 KiB
Ruby
Raw Normal View History

2012-11-14 05:37:50 +00:00
require 'recaptcha'
class UserManager < BaseManager
include Recaptcha::Verify
def initialize(options={})
super(options)
@log = Logging.logger[self]
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]
2012-11-14 05:37:50 +00:00
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?
2013-02-08 03:11:47 +00:00
raise PermissionError, "Signups are currently disabled"
end
loc = MaxMindManager.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
2012-11-14 05:57:10 +00:00
# TODO: figure out why can't user verify_recaptcha here
2012-11-15 08:47:19 +00:00
# ALSO: make sure we dont do the recaptcha stuff if used facebook.
2012-11-14 05:57:10 +00:00
2012-11-14 05:37:50 +00:00
# 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
2012-11-14 05:57:10 +00:00
#else
# 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,
invited_user: invited_user,
fb_signup: fb_signup,
2014-04-20 22:54:49 +00:00
signup_confirm_url: signup_confirm_url,
affiliate_referral_id: affiliate_referral_id)
2012-11-14 05:37:50 +00:00
return user
2012-11-14 05:57:10 +00:00
#end
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 = MaxMindManager.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