89 lines
3.2 KiB
Ruby
89 lines
3.2 KiB
Ruby
require 'recaptcha'
|
|
class UserManager < BaseManager
|
|
|
|
include Recaptcha::Verify
|
|
|
|
def initialize(options={})
|
|
super(options)
|
|
@log = Logging.logger[self]
|
|
end
|
|
|
|
# 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(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]
|
|
affiliate_referral_id = options[:affiliate_referral_id]
|
|
|
|
@user = User.new
|
|
|
|
# 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 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.
|
|
if location
|
|
loc[:city] = location[:city]
|
|
loc[:state] = location[:state]
|
|
loc[:country] = location[:country]
|
|
end
|
|
|
|
# TODO: figure out why can't user verify_recaptcha here
|
|
# ALSO: make sure we dont do the recaptcha stuff if used facebook.
|
|
|
|
# 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
|
|
#else
|
|
# sends email to email account for confirmation
|
|
@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: loc,
|
|
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,
|
|
affiliate_referral_id: affiliate_referral_id)
|
|
|
|
return @user
|
|
#end
|
|
end
|
|
|
|
def signup_confirm(signup_token, remote_ip=nil)
|
|
begin
|
|
@user = User.signup_confirm(signup_token)
|
|
@user.location = MaxMindManager.lookup(remote_ip) if remote_ip
|
|
rescue ActiveRecord::RecordNotFound
|
|
@user = nil
|
|
end
|
|
|
|
return @user
|
|
end
|
|
|
|
end
|