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] @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 # a user should be able to specify their location, but if they don't, we'll best effort it if location.nil? location = MaxMindManager.lookup(remote_ip) 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: location, 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) 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