jam-cloud/lib/managers/user_manager.rb

55 lines
1.9 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.
2013-03-15 04:23:37 +00:00
def signup(remote_ip, first_name, last_name, email, password = nil, password_confirmation = nil, terms_of_service = nil, subscribe_email = nil,
instruments = nil, birth_date = nil, location = nil, musician = nil, photo_url = nil, invited_user = nil, signup_confirm_url = nil)
2012-11-14 05:37:50 +00:00
@user = User.new
# check if we have disabled open signup for this site. open == invited users can still get in
unless SampleApp::Application.config.signup_enabled && invited_user.nil?
2013-02-08 03:11:47 +00:00
raise PermissionError, "Signups are currently disabled"
end
2013-03-15 04:23:37 +00:00
# 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
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
2012-11-14 05:57:10 +00:00
#unless verify_recaptcha(:model => @user, :message => "recaptcha")
# return @user # @user.errors.any? is true now
#else
# sends email to email account for confirmation
2013-03-15 04:23:37 +00:00
@user = User.signup(first_name, last_name, email, password, password_confirmation, terms_of_service, subscribe_email,
location, instruments, birth_date, musician, photo_url, invited_user, signup_confirm_url)
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
end
return @user
end
2012-11-15 08:47:19 +00:00
end