mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 11:24:38 +08:00
FEATURE: add ability to have multiple totp factors (#7626)
Adds a second factor landing page that centralizes a user's second factor configuration. This contains both TOTP and Backup, and also allows multiple TOTP tokens to be registered and organized by a name. Access to this page is authenticated via password, and cached for 30 minutes via a secure session.
This commit is contained in:
@ -11,6 +11,10 @@ class UserSecondFactor < ActiveRecord::Base
|
||||
where(method: UserSecondFactor.methods[:totp], enabled: true)
|
||||
end
|
||||
|
||||
scope :all_totps, -> do
|
||||
where(method: UserSecondFactor.methods[:totp])
|
||||
end
|
||||
|
||||
def self.methods
|
||||
@methods ||= Enum.new(
|
||||
totp: 1,
|
||||
@ -18,8 +22,12 @@ class UserSecondFactor < ActiveRecord::Base
|
||||
)
|
||||
end
|
||||
|
||||
def self.totp
|
||||
where(method: self.methods[:totp]).first
|
||||
def get_totp_object
|
||||
ROTP::TOTP.new(self.data, issuer: SiteSetting.title)
|
||||
end
|
||||
|
||||
def totp_provisioning_uri
|
||||
get_totp_object.provisioning_uri(user.email)
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user