2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-03-09 15:24:16 -04:00
|
|
|
module GlobalPath
|
|
|
|
def path(p)
|
|
|
|
"#{GlobalSetting.relative_url_root}#{p}"
|
|
|
|
end
|
2015-05-26 01:41:50 -04:00
|
|
|
|
|
|
|
def cdn_path(p)
|
2018-11-23 10:11:05 -05:00
|
|
|
GlobalSetting.cdn_url.blank? ? p : "#{GlobalSetting.cdn_url}#{path(p)}"
|
2015-05-26 01:41:50 -04:00
|
|
|
end
|
2016-02-04 21:05:47 -05:00
|
|
|
|
2017-05-08 11:38:48 -04:00
|
|
|
def upload_cdn_path(p)
|
2017-10-06 01:20:01 -04:00
|
|
|
p = Discourse.store.cdn_url(p) if SiteSetting.Upload.s3_cdn_url.present?
|
2019-01-03 18:50:35 -05:00
|
|
|
|
|
|
|
(p =~ /^http/ || p =~ %r{^//}) ? p : cdn_path(p)
|
2017-05-08 11:38:48 -04:00
|
|
|
end
|
|
|
|
|
2016-02-04 21:05:47 -05:00
|
|
|
def cdn_relative_path(path)
|
|
|
|
if (cdn_url = GlobalSetting.cdn_url).present?
|
|
|
|
URI.parse(cdn_url).path + path
|
|
|
|
else
|
|
|
|
path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-19 04:20:48 -05:00
|
|
|
def full_cdn_url(url)
|
|
|
|
uri = URI.parse(UrlHelper.absolute(upload_cdn_path(url)))
|
|
|
|
uri.scheme = SiteSetting.scheme if uri.scheme.blank?
|
|
|
|
uri.to_s
|
|
|
|
end
|
|
|
|
|
FEATURE: Centralized 2FA page (#15377)
2FA support in Discourse was added and grown gradually over the years: we first
added support for TOTP for logins, then we implemented backup codes, and last
but not least, security keys. 2FA usage was initially limited to logging in,
but it has been expanded and we now require 2FA for risky actions such as
adding a new admin to the site.
As a result of this gradual growth of the 2FA system, technical debt has
accumulated to the point where it has become difficult to require 2FA for more
actions. We now have 5 different 2FA UI implementations and each one has to
support all 3 2FA methods (TOTP, backup codes, and security keys) which makes
it difficult to maintain a consistent UX for these different implementations.
Moreover, there is a lot of repeated logic in the server-side code behind these
5 UI implementations which hinders maintainability even more.
This commit is the first step towards repaying the technical debt: it builds a
system that centralizes as much as possible of the 2FA server-side logic and
UI. The 2 main components of this system are:
1. A dedicated page for 2FA with support for all 3 methods.
2. A reusable server-side class that centralizes the 2FA logic (the
`SecondFactor::AuthManager` class).
From a top-level view, the 2FA flow in this new system looks like this:
1. User initiates an action that requires 2FA;
2. Server is aware that 2FA is required for this action, so it redirects the
user to the 2FA page if the user has a 2FA method, otherwise the action is
performed.
3. User submits the 2FA form on the page;
4. Server validates the 2FA and if it's successful, the action is performed and
the user is redirected to the previous page.
A more technically-detailed explanation/documentation of the new system is
available as a comment at the top of the `lib/second_factor/auth_manager.rb`
file. Please note that the details are not set in stone and will likely change
in the future, so please don't use the system in your plugins yet.
Since this is a new system that needs to be tested, we've decided to migrate
only the 2FA for adding a new admin to the new system at this time (in this
commit). Our plan is to gradually migrate the remaining 2FA implementations to
the new system.
For screenshots of the 2FA page, see PR #15377 on GitHub.
2022-02-17 04:12:59 -05:00
|
|
|
extend self
|
2015-03-09 15:24:16 -04:00
|
|
|
end
|