Compare commits
20 Commits
a389e8cc38
...
33ca930055
| Author | SHA1 | Date |
|---|---|---|
|
|
33ca930055 | 1 month ago |
|
|
3b396f8421 | 1 month ago |
|
|
aa77e3a8d3 | 1 month ago |
|
|
75316d8d87 | 1 month ago |
|
|
a999109a5c | 1 month ago |
|
|
bdd33c7d6b | 1 month ago |
|
|
61c5ee22a0 | 1 month ago |
|
|
12c5b909e0 | 1 month ago |
|
|
871ef6dda6 | 1 month ago |
|
|
40052a2d7c | 1 month ago |
|
|
347be0137d | 1 month ago |
|
|
fe6baba8bf | 1 month ago |
|
|
ed8c313bd4 | 1 month ago |
|
|
ca0acb34d6 | 1 month ago |
|
|
34ea639c25 | 1 month ago |
|
|
680ab9dbed | 1 month ago |
|
|
9377766e52 | 1 month ago |
|
|
7a2c37454e | 1 month ago |
|
|
8f6f418f54 | 1 month ago |
|
|
9b7745c565 | 1 month ago |
@ -0,0 +1,45 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Submitters
|
||||||
|
module AuthorizedForForm
|
||||||
|
Unauthorized = Class.new(StandardError)
|
||||||
|
|
||||||
|
module_function
|
||||||
|
|
||||||
|
def call(submitter, current_user, request)
|
||||||
|
pass_email_2fa?(submitter, request) && pass_link_2fa?(submitter, current_user, request)
|
||||||
|
end
|
||||||
|
|
||||||
|
def pass_email_2fa?(submitter, request)
|
||||||
|
return false unless submitter
|
||||||
|
|
||||||
|
return true if submitter.submission.template&.preferences&.dig('require_email_2fa') != true &&
|
||||||
|
submitter.preferences['require_email_2fa'] != true
|
||||||
|
return true if request.cookie_jar.encrypted[:email_2fa_slug] == submitter.slug
|
||||||
|
|
||||||
|
token = request.params[:two_factor_token].presence || request.headers['x-two-factor-token'].presence
|
||||||
|
|
||||||
|
return true if token.present? &&
|
||||||
|
Submitter.signed_id_verifier.verified(token, purpose: :email_two_factor) == submitter.slug
|
||||||
|
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def pass_link_2fa?(submitter, current_user, request)
|
||||||
|
return false unless submitter
|
||||||
|
|
||||||
|
return true if submitter.submission.source != 'link'
|
||||||
|
return true unless submitter.submission.template&.preferences&.dig('shared_link_2fa') == true
|
||||||
|
return true if request.cookie_jar.encrypted[:email_2fa_slug] == submitter.slug
|
||||||
|
return true if submitter.email == current_user&.email && current_user&.account_id == submitter.account_id
|
||||||
|
|
||||||
|
if (token = request.params[:two_factor_token].presence || request.headers['x-two-factor-token'].presence)
|
||||||
|
link_2fa_key = [submitter.email.downcase.squish, submitter.submission.template.slug].join(':')
|
||||||
|
|
||||||
|
return true if Submitter.signed_id_verifier.verified(token, purpose: :email_two_factor) == link_2fa_key
|
||||||
|
end
|
||||||
|
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 695 B After Width: | Height: | Size: 807 B |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 4.7 KiB |