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
|
|
|
|
|
|
|
|
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))
|
|
|
|
if SiteSetting.must_approve_users? && !(invite.present? && !invite.expired? && !invite.destroyed? && invite.link_valid?)
|
2013-08-18 22:37:38 +08:00
|
|
|
ApprovalActivator
|
|
|
|
elsif !user.active?
|
|
|
|
EmailActivator
|
|
|
|
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
|
|
|
|
I18n.t("login.wait_approval")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class EmailActivator < UserActivator
|
|
|
|
def activate
|
2015-08-24 14:21:34 +08:00
|
|
|
email_token = user.email_tokens.unconfirmed.active.first
|
|
|
|
email_token = user.email_tokens.create(email: user.email) if email_token.nil?
|
|
|
|
|
2013-08-18 22:37:38 +08:00
|
|
|
Jobs.enqueue(:user_email,
|
|
|
|
type: :signup,
|
|
|
|
user_id: user.id,
|
2015-08-24 14:21:34 +08:00
|
|
|
email_token: email_token.token
|
2013-08-18 22:37:38 +08:00
|
|
|
)
|
|
|
|
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
|