mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
58 lines
1.1 KiB
Ruby
58 lines
1.1 KiB
Ruby
|
# Responsible for dealing with different activation processes when a user is created
|
||
|
class UserActivator
|
||
|
attr_reader :user, :session, :cookies
|
||
|
def initialize(user, session, cookies)
|
||
|
@user = user
|
||
|
@session = session
|
||
|
@cookies = cookies
|
||
|
end
|
||
|
|
||
|
def activation_message
|
||
|
activator.activate
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def activator
|
||
|
factory.new(user, session, cookies)
|
||
|
end
|
||
|
|
||
|
def factory
|
||
|
if SiteSetting.must_approve_users?
|
||
|
ApprovalActivator
|
||
|
elsif !user.active?
|
||
|
EmailActivator
|
||
|
else
|
||
|
LoginActivator
|
||
|
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
|