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
|
|
|
@message = nil
|
2013-08-18 10:37:38 -04:00
|
|
|
end
|
|
|
|
|
2013-11-12 17:37:38 -05:00
|
|
|
def start
|
|
|
|
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
|
2014-07-16 12:25:24 -04:00
|
|
|
if SiteSetting.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
|
|
|
|
|
|
|
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
|