2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-08-18 22:37:38 +08:00
|
|
|
class UserActivator
|
2013-11-13 06:37:38 +08:00
|
|
|
attr_reader :user, :request, :session, :cookies, :message
|
2013-10-09 12:10:37 +08:00
|
|
|
|
|
|
|
def initialize(user, request, session, cookies)
|
2013-08-18 22:37:38 +08:00
|
|
|
@user = user
|
|
|
|
@session = session
|
|
|
|
@cookies = cookies
|
2013-10-09 12:10:37 +08:00
|
|
|
@request = request
|
2013-11-13 06:37:38 +08:00
|
|
|
@message = nil
|
2013-08-18 22:37:38 +08:00
|
|
|
end
|
|
|
|
|
2013-11-13 06:37:38 +08:00
|
|
|
def start
|
|
|
|
end
|
|
|
|
|
|
|
|
def finish
|
|
|
|
@message = activator.activate
|
2013-08-18 22:37:38 +08:00
|
|
|
end
|
|
|
|
|
2017-10-04 02:08:37 +08:00
|
|
|
def success_message
|
|
|
|
activator.success_message
|
|
|
|
end
|
|
|
|
|
2013-08-18 22:37:38 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
def activator
|
2013-10-09 12:10:37 +08:00
|
|
|
factory.new(user, request, session, cookies)
|
2013-08-18 22:37:38 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def factory
|
2015-06-26 03:51:26 +08:00
|
|
|
invite = Invite.find_by(email: Email.downcase(@user.email))
|
2017-09-13 03:04:39 +08:00
|
|
|
|
|
|
|
if !user.active?
|
2013-08-18 22:37:38 +08:00
|
|
|
EmailActivator
|
2021-03-19 08:20:10 +08:00
|
|
|
elsif SiteSetting.must_approve_users? && !(invite.present? && invite.redeemable?)
|
2017-09-13 03:04:39 +08:00
|
|
|
ApprovalActivator
|
2013-08-18 22:37:38 +08:00
|
|
|
else
|
|
|
|
LoginActivator
|
|
|
|
end
|
2013-11-13 06:37:38 +08:00
|
|
|
end
|
2013-08-18 22:37:38 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
class ApprovalActivator < UserActivator
|
|
|
|
def activate
|
2017-10-04 02:08:37 +08:00
|
|
|
success_message
|
|
|
|
end
|
|
|
|
|
|
|
|
def success_message
|
2013-08-18 22:37:38 +08:00
|
|
|
I18n.t("login.wait_approval")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class EmailActivator < UserActivator
|
|
|
|
def activate
|
2021-11-25 15:34:39 +08:00
|
|
|
email_token = user.email_tokens.create!(email: user.email, scope: EmailToken.scopes[:signup])
|
|
|
|
EmailToken.enqueue_signup_email(email_token)
|
2017-10-04 02:08:37 +08:00
|
|
|
success_message
|
|
|
|
end
|
|
|
|
|
|
|
|
def success_message
|
2016-08-06 00:01:16 +08:00
|
|
|
I18n.t("login.activate_email", email: Rack::Utils.escape_html(user.email))
|
2013-08-18 22:37:38 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class LoginActivator < UserActivator
|
|
|
|
include CurrentUser
|
|
|
|
|
|
|
|
def activate
|
|
|
|
log_on_user(user)
|
|
|
|
user.enqueue_welcome_message("welcome_user")
|
2017-10-04 02:08:37 +08:00
|
|
|
success_message
|
|
|
|
end
|
|
|
|
|
|
|
|
def success_message
|
2013-08-18 22:37:38 +08:00
|
|
|
I18n.t("login.active")
|
|
|
|
end
|
|
|
|
end
|