2013-08-18 10:37:38 -04:00
|
|
|
class UserActivator
|
2013-11-12 17:37:38 -05:00
|
|
|
attr_reader :user, :request, :session, :cookies, :message
|
2013-10-09 00:10:37 -04:00
|
|
|
|
|
|
|
def initialize(user, request, session, cookies)
|
2013-08-18 10:37:38 -04:00
|
|
|
@user = user
|
|
|
|
@session = session
|
|
|
|
@cookies = cookies
|
2013-10-09 00:10:37 -04:00
|
|
|
@request = request
|
2013-11-12 17:37:38 -05:00
|
|
|
@settings = SiteSetting
|
|
|
|
@hub = DiscourseHub
|
|
|
|
@message = nil
|
2013-08-18 10:37:38 -04:00
|
|
|
end
|
|
|
|
|
2013-11-12 17:37:38 -05:00
|
|
|
def start
|
2014-03-12 12:39:27 -04:00
|
|
|
register_username
|
2013-11-12 17:37:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def finish
|
|
|
|
@message = activator.activate
|
2013-08-18 10:37:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def activator
|
2013-10-09 00:10:37 -04:00
|
|
|
factory.new(user, request, session, cookies)
|
2013-08-18 10:37:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def factory
|
2013-11-12 17:37:38 -05:00
|
|
|
if @settings.must_approve_users?
|
2013-08-18 10:37:38 -04:00
|
|
|
ApprovalActivator
|
|
|
|
elsif !user.active?
|
|
|
|
EmailActivator
|
|
|
|
else
|
|
|
|
LoginActivator
|
|
|
|
end
|
2013-11-12 17:37:38 -05:00
|
|
|
end
|
2013-08-18 10:37:38 -04:00
|
|
|
|
2014-03-12 12:39:27 -04:00
|
|
|
def register_username
|
2013-11-12 17:37:38 -05:00
|
|
|
if user.valid? && @settings.call_discourse_hub?
|
2014-03-12 12:39:27 -04:00
|
|
|
@hub.register_username(user.username, user.email)
|
2013-11-12 17:37:38 -05:00
|
|
|
end
|
2013-08-18 10:37:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ApprovalActivator < UserActivator
|
|
|
|
def activate
|
|
|
|
I18n.t("login.wait_approval")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class EmailActivator < UserActivator
|
|
|
|
def activate
|
|
|
|
Jobs.enqueue(:user_email,
|
|
|
|
type: :signup,
|
|
|
|
user_id: user.id,
|
|
|
|
email_token: user.email_tokens.first.token
|
|
|
|
)
|
|
|
|
I18n.t("login.activate_email", email: user.email)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class LoginActivator < UserActivator
|
|
|
|
include CurrentUser
|
|
|
|
|
|
|
|
def activate
|
|
|
|
log_on_user(user)
|
|
|
|
user.enqueue_welcome_message('welcome_user')
|
|
|
|
I18n.t("login.active")
|
|
|
|
end
|
|
|
|
end
|