mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-21 21:12:39 -05:00
51eff92170
* Simplify controller action * Extract service classes
70 lines
1.3 KiB
Ruby
70 lines
1.3 KiB
Ruby
class UserActivator
|
|
attr_reader :user, :request, :session, :cookies, :message
|
|
|
|
def initialize(user, request, session, cookies)
|
|
@user = user
|
|
@session = session
|
|
@cookies = cookies
|
|
@request = request
|
|
@settings = SiteSetting
|
|
@hub = DiscourseHub
|
|
@message = nil
|
|
end
|
|
|
|
def start
|
|
register_nickname
|
|
end
|
|
|
|
def finish
|
|
@message = activator.activate
|
|
end
|
|
|
|
private
|
|
|
|
def activator
|
|
factory.new(user, request, session, cookies)
|
|
end
|
|
|
|
def factory
|
|
if @settings.must_approve_users?
|
|
ApprovalActivator
|
|
elsif !user.active?
|
|
EmailActivator
|
|
else
|
|
LoginActivator
|
|
end
|
|
end
|
|
|
|
def register_nickname
|
|
if user.valid? && @settings.call_discourse_hub?
|
|
@hub.register_nickname(user.username, user.email)
|
|
end
|
|
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
|