Implement UI for 2FA setup and verification (#3541)
* Add 2FA actions to `AuthController` * Hook up new `AuthController` actions to router * Add `qr_code` to project dependencies * Implement generic `qr_code` component rendering SVG QR code from text * Implement enabled and disabled 2FA setting state in user settings view * Implement view for initiating 2FA setup * Implement view for verifying 2FA setup * Implement view for rendering generated 2FA recovery codes * Implement view for verifying 2FA code * Implement view for verifying 2FA recovery code * Improve `input_with_clipboard` component * Improve view for initiating 2FA setup * Improve verify 2FA setup view * Implement `verify_2fa_input` component * Improve view for verifying 2FA setup * Improve view rendering generated 2FA recovery codes * Use `verify_2fa_input` component in verify 2FA view * Do not render PA contact on self-hosted instances * Improve flash message phrasing on generated recovery codes * Add byline with a warning to disable 2FA modal * Extract modal to component and move 2FA components to dedicated module * First pass on loading state for "generate new codes" * Adjust modal button logic * Fix button in verify_2fa_input component * Use button component in activate view * Implement wait states for recovery code related actions properly * Apply rate limiting to 2FA verification * Log failed 2FA code input attempts * Add ability to trust device and skip 2FA for 30 days * Improve styling in dark mode * Fix waiting state under Chrome and Safari * Delete trust cookie when disabling 2FA * Put 2FA behind a feature flag * Extract 2FA cookie deletion * ff fixup * Improve session management during 2FA login * Extract part of 2FA controller logic to a separate module and clean up a bit * Clear 2FA user session when rate limit hit * Add id to form in verify 2FA setup view * Add controller tests for 2FA actions and login action * Update CHANGELOG.md * Use `full_build?()` instead of `@is_selfhost` removed after rebase * Update `Auth.TOTP` moduledoc * Add TOTP token management and make `TOTP.enable` more test-friendly * Use TOTP token for device trust feature * Use zero-deps `eqrcode` instead of deps-heavy `qr_code` * Improve flash messages copy Co-authored-by: hq1 <hq@mtod.org> * Make one more copy improvement Co-authored-by: hq1 <hq@mtod.org> * Fix copy in remaining spots * Change redirect after login to accept URLs from #3560 (h/t @aerosol) * Add tests checking handling login_dest on login and 2FA verification * Fix regression in email activation form submit button behavior * Rename `PlausibleWeb.TwoFactor` -> `PlausibleWeb.TwoFactor.Session` * Move `qr_code` component under `Components.TwoFactor` * Set domain and secure options for new cookies --------- Co-authored-by: hq1 <hq@mtod.org>pull/3595/head r2023.12.06-272
parent
4566e6b530
commit
da0fa6c355
@ -0,0 +1,155 @@
|
||||
defmodule PlausibleWeb.Components.TwoFactor do
|
||||
@moduledoc """
|
||||
Reusable components specific to 2FA
|
||||
"""
|
||||
use Phoenix.Component
|
||||
|
||||
attr :text, :string, required: true
|
||||
attr :scale, :integer, default: 4
|
||||
|
||||
def qr_code(assigns) do
|
||||
qr_code =
|
||||
assigns.text
|
||||
|> EQRCode.encode()
|
||||
|> EQRCode.svg(%{width: 160})
|
||||
|
||||
assigns = assign(assigns, :code, qr_code)
|
||||
|
||||
~H"""
|
||||
<%= Phoenix.HTML.raw(@code) %>
|
||||
"""
|
||||
end
|
||||
|
||||
attr :id, :string, default: "verify-button"
|
||||
attr :form, :any, required: true
|
||||
attr :field, :any, required: true
|
||||
attr :class, :string, default: ""
|
||||
|
||||
def verify_2fa_input(assigns) do
|
||||
~H"""
|
||||
<div class={[@class, "flex justify-center sm:justify-start"]}>
|
||||
<%= Phoenix.HTML.Form.text_input(@form, @field,
|
||||
autocomplete: "off",
|
||||
class:
|
||||
"font-mono tracking-[0.5em] w-36 pl-5 font-medium shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block border-gray-300 dark:border-gray-500 dark:text-gray-200 dark:bg-gray-900 rounded-l-md",
|
||||
oninput:
|
||||
"this.value=this.value.replace(/[^0-9]/g, ''); if (this.value.length >= 6) document.getElementById('verify-button').focus()",
|
||||
onclick: "this.select();",
|
||||
oninvalid: "document.getElementById('verify-button').disabled = false",
|
||||
maxlength: "6",
|
||||
placeholder: "••••••",
|
||||
value: "",
|
||||
required: "required"
|
||||
) %>
|
||||
<PlausibleWeb.Components.Generic.button
|
||||
type="submit"
|
||||
id={@id}
|
||||
class="rounded-l-none [&>span.label-enabled]:block [&>span.label-disabled]:hidden [&[disabled]>span.label-enabled]:hidden [&[disabled]>span.label-disabled]:block"
|
||||
>
|
||||
<span class="label-enabled pointer-events-none">
|
||||
Verify →
|
||||
</span>
|
||||
|
||||
<span class="label-disabled">
|
||||
<PlausibleWeb.Components.Generic.spinner class="inline-block h-5 w-5 mr-2 text-white dark:text-gray-400" />
|
||||
Verifying...
|
||||
</span>
|
||||
</PlausibleWeb.Components.Generic.button>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
attr :id, :string, required: true
|
||||
attr :state_param, :string, required: true
|
||||
attr :form_data, :any, required: true
|
||||
attr :form_target, :string, required: true
|
||||
attr :onsubmit, :string, default: nil
|
||||
attr :title, :string, required: true
|
||||
|
||||
slot :icon, required: true
|
||||
slot :inner_block, required: true
|
||||
slot :buttons, required: true
|
||||
|
||||
def modal(assigns) do
|
||||
~H"""
|
||||
<div
|
||||
id={@id}
|
||||
x-cloak
|
||||
x-show={@state_param}
|
||||
x-on:keyup.escape.window={"#{@state_param} = false"}
|
||||
class="fixed z-10 inset-0 overflow-y-auto"
|
||||
aria-labelledby="modal-title"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
>
|
||||
<div class="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
|
||||
<div
|
||||
x-show={@state_param}
|
||||
x-transition:enter="transition ease-out duration-300"
|
||||
x-transition:enter-start="opacity-0"
|
||||
x-transition:enter-end="opacity-100"
|
||||
x-transition:leave="transition ease-in duration-200"
|
||||
x-transition:leave-start="opacity-100"
|
||||
x-transition:leave-end="opacity-0"
|
||||
class="fixed inset-0 bg-gray-500 dark:bg-gray-800 bg-opacity-75 dark:bg-opacity-75 transition-opacity"
|
||||
aria-hidden="true"
|
||||
x-on:click={"#{@state_param} = false"}
|
||||
>
|
||||
</div>
|
||||
<!-- This element is to trick the browser into centering the modal contents. -->
|
||||
<span class="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">
|
||||
​
|
||||
</span>
|
||||
|
||||
<div
|
||||
x-show={@state_param}
|
||||
x-transition:enter="transition ease-out duration-300"
|
||||
x-transition:enter-start="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
x-transition:enter-end="opacity-100 translate-y-0 sm:scale-100"
|
||||
x-transition:leave="transition ease-in duration-200"
|
||||
x-transition:leave-start="opacity-100 translate-y-0 sm:scale-100"
|
||||
x-transition:leave-end="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
class="inline-block align-bottom bg-white dark:bg-gray-900 rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full"
|
||||
>
|
||||
<%= Phoenix.HTML.Form.form_for @form_data, @form_target, [onsubmit: @onsubmit], fn f -> %>
|
||||
<div class="bg-white dark:bg-gray-800 px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
|
||||
<div class="hidden sm:block absolute top-0 right-0 pt-4 pr-4">
|
||||
<a
|
||||
href="#"
|
||||
x-on:click.prevent={"#{@state_param} = false"}
|
||||
class="bg-white dark:bg-gray-800 rounded-md text-gray-400 dark:text-gray-500 hover:text-gray-500 dark:hover:text-gray-400 focus:outline-none"
|
||||
>
|
||||
<span class="sr-only">Close</span>
|
||||
<Heroicons.x_mark class="h-6 w-6" />
|
||||
</a>
|
||||
</div>
|
||||
<div class="sm:flex sm:items-start">
|
||||
<div class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-green-100 sm:mx-0 sm:h-10 sm:w-10">
|
||||
<%= render_slot(@icon) %>
|
||||
</div>
|
||||
<div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left text-gray-900 dark:text-gray-100">
|
||||
<h3 class="text-lg leading-6 font-medium" id="modal-title">
|
||||
<%= @title %>
|
||||
</h3>
|
||||
|
||||
<%= render_slot(@inner_block, f) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bg-gray-50 dark:bg-gray-850 px-4 py-3 sm:px-9 sm:flex sm:flex-row-reverse">
|
||||
<%= render_slot(@buttons) %>
|
||||
<button
|
||||
type="button"
|
||||
class="sm:mr-2 mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 dark:border-gray-500 shadow-sm px-4 py-2 bg-white dark:bg-gray-800 text-base font-medium text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-850 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm"
|
||||
x-on:click={"#{@state_param} = false"}
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,49 @@
|
||||
<div class="w-full max-w-3xl mt-4 mx-auto flex">
|
||||
<div class="w-full max-w-lg mx-auto bg-white dark:bg-gray-800 shadow-md rounded px-8 py-6 mb-4 mt-8">
|
||||
<h2 class="text-xl font-black dark:text-gray-100">
|
||||
<%= if @from_setup do %>
|
||||
Setup Two-Factor Authentication
|
||||
<% else %>
|
||||
Your New Recovery Codes
|
||||
<% end %>
|
||||
</h2>
|
||||
|
||||
<div class="text-sm mt-2 text-gray-500 dark:text-gray-200 leading-tight">
|
||||
Use these recovery codes to log in if you lose access to the authenticator application. Store them somewhere safe!
|
||||
<div
|
||||
id="recovery-codes-list"
|
||||
class="font-mono border-2 border-dotted border-gray-200 dark:border-gray-700 rounded-md text-gray-600 dark:text-gray-200 text-lg bg-gray-100 dark:bg-gray-900 p-2 mt-6 flex flex-wrap"
|
||||
>
|
||||
<%= for code <- @recovery_codes do %>
|
||||
<div class="basis-1/2 text-center"><%= code %></div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex sm:flex-row flex-col justify-between">
|
||||
<button onclick="print(); event.stopPropagation();" id="print" class="button">
|
||||
Print Codes <Heroicons.printer class="h-4 w-4 ml-2 mt-1" />
|
||||
</button>
|
||||
<button
|
||||
onclick="var list = document.getElementById('recovery-codes-list'); var selection = getSelection(); selection.removeAllRanges(); var range = createRange(); range.selectNodeContents(list); selection.addRange(range); document.execCommand('copy'); selection.removeAllRanges(); event.stopPropagation(); document.getElementById('copy-base-icon').classList.add('hidden'); document.getElementById('copy-done-icon').classList.remove('hidden'); setTimeout(function() { document.getElementById('copy-done-icon').classList.add('hidden'); document.getElementById('copy-base-icon').classList.remove('hidden'); }, 2000)"
|
||||
id="copy"
|
||||
class="button sm:mt-0 mt-3"
|
||||
>
|
||||
Copy to Clipboard
|
||||
<span id="copy-base-icon">
|
||||
<Heroicons.document_duplicate class="h-4 w-4 ml-2 mt-1" />
|
||||
</span>
|
||||
<span id="copy-done-icon" class="hidden">
|
||||
<Heroicons.check class="h-4 w-4 ml-2 mt-1" />
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
id="finish"
|
||||
class="button sm:mt-0 mt-3"
|
||||
onclick={"location.replace('#{Routes.auth_path(@conn, :user_settings) <> "#setup-2fa"}')"}
|
||||
>
|
||||
Finish
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -0,0 +1,71 @@
|
||||
<div class="w-full max-w-2xl mt-4 mx-auto flex">
|
||||
<div class="w-full mx-auto bg-white dark:bg-gray-800 shadow-md rounded px-8 py-6 mb-4 mt-8">
|
||||
<h2 class="text-xl font-black dark:text-gray-100">
|
||||
Setup Two-Factor Authentication
|
||||
</h2>
|
||||
|
||||
<div class="text-sm mt-2 text-gray-500 dark:text-gray-200">
|
||||
Link your Plausible account to the authenticator app you have installed either on your phone or computer.
|
||||
<div class="flex flex-col sm:flex-row items-center sm:items-start">
|
||||
<div class="mt-8">
|
||||
<div class="border-2 border-gray-300 inline-block p-2 dark:bg-white">
|
||||
<PlausibleWeb.Components.TwoFactor.qr_code text={@totp_uri} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-8 sm:ml-4">
|
||||
<ol>
|
||||
<li class="flex items-start">
|
||||
<div class="flex-shrink-0 h-5 w-5 relative flex items-center justify-center">
|
||||
<div class="h-2 w-2 bg-gray-300 dark:bg-gray-700 rounded-full"></div>
|
||||
</div>
|
||||
Open the authenticator application
|
||||
</li>
|
||||
<li class="mt-1 flex items-start">
|
||||
<div class="flex-shrink-0 h-5 w-5 relative flex items-center justify-center">
|
||||
<div class="h-2 w-2 bg-gray-300 dark:bg-gray-700 rounded-full"></div>
|
||||
</div>
|
||||
Tap Scan a QR Code
|
||||
</li>
|
||||
<li class="mt-1 flex items-start">
|
||||
<div class="flex-shrink-0 h-5 w-5 relative flex items-center justify-center">
|
||||
<div class="h-2 w-2 bg-gray-300 dark:bg-gray-700 rounded-full"></div>
|
||||
</div>
|
||||
Scan this code with your phone camera or paste the code manually
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<div class="sm:ml-2">
|
||||
<PlausibleWeb.Live.Components.Form.input_with_clipboard
|
||||
id="secret"
|
||||
name="secret_clipboard"
|
||||
label="Code"
|
||||
value={@secret}
|
||||
onfocus="this.value = this.value;"
|
||||
class="focus:ring-indigo-500 focus:border-indigo-500 bg-gray-50 dark:bg-gray-850 dark:text-gray-300 block w-7/12 rounded-md sm:text-sm border-gray-300 dark:border-gray-500 w-full p-2 mt-2"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex flex-col-reverse sm:flex-row justify-between items-center">
|
||||
<p class="text-sm mt-4 sm:mt-0">
|
||||
Changed your mind?
|
||||
<a
|
||||
href={Routes.auth_path(@conn, :user_settings) <> "#setup-2fa"}
|
||||
class="underline text-indigo-600"
|
||||
>
|
||||
Go back to Settings
|
||||
</a>
|
||||
</p>
|
||||
<.unstyled_link
|
||||
id="proceed"
|
||||
class="button sm:w-auto w-full"
|
||||
href={Routes.auth_path(@conn, :verify_2fa_setup_form)}
|
||||
>
|
||||
Proceed →
|
||||
</.unstyled_link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -1,378 +1,507 @@
|
||||
<%= if full_build?() do %>
|
||||
<div class="max-w-2xl px-8 pt-4 pb-8 mx-auto mt-24 bg-white border-t-2 border-orange-200 rounded rounded-t-none shadow-md dark:bg-gray-800 dark:border-orange-200 ">
|
||||
<div class="flex flex-wrap justify-between">
|
||||
<h2 class="text-xl font-black dark:text-gray-100 w-max mr-4 mt-2">Subscription Plan</h2>
|
||||
<div class="gap-x-2 mt-2 inline-flex">
|
||||
<span
|
||||
:if={@subscription && Plausible.Billing.Plans.business_tier?(@subscription)}
|
||||
class={[
|
||||
"w-max px-2.5 py-0.5 rounded-md text-sm font-bold leading-5 text-indigo-600 bg-blue-100 dark:text-yellow-200 dark:border dark:bg-inherit dark:border-yellow-200"
|
||||
]}
|
||||
>
|
||||
Business
|
||||
</span>
|
||||
<span
|
||||
:if={@subscription}
|
||||
class={[
|
||||
"w-max px-2.5 py-0.5 rounded-md text-sm font-bold leading-5",
|
||||
subscription_colors(@subscription.status)
|
||||
]}
|
||||
>
|
||||
<%= present_subscription_status(@subscription.status) %>
|
||||
</span>
|
||||
<div x-data="{disable2FAOpen: false, regenerate2FAOpen: false}">
|
||||
<%= if full_build?() do %>
|
||||
<div class="max-w-2xl px-8 pt-4 pb-8 mx-auto mt-24 bg-white border-t-2 border-orange-200 rounded rounded-t-none shadow-md dark:bg-gray-800 dark:border-orange-200 ">
|
||||
<div class="flex flex-wrap justify-between">
|
||||
<h2 class="text-xl font-black dark:text-gray-100 w-max mr-4 mt-2">Subscription Plan</h2>
|
||||
<div class="gap-x-2 mt-2 inline-flex">
|
||||
<span
|
||||
:if={@subscription && Plausible.Billing.Plans.business_tier?(@subscription)}
|
||||
class={[
|
||||
"w-max px-2.5 py-0.5 rounded-md text-sm font-bold leading-5 text-indigo-600 bg-blue-100 dark:text-yellow-200 dark:border dark:bg-inherit dark:border-yellow-200"
|
||||
]}
|
||||
>
|
||||
Business
|
||||
</span>
|
||||
<span
|
||||
:if={@subscription}
|
||||
class={[
|
||||
"w-max px-2.5 py-0.5 rounded-md text-sm font-bold leading-5",
|
||||
subscription_colors(@subscription.status)
|
||||
]}
|
||||
>
|
||||
<%= present_subscription_status(@subscription.status) %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="my-4 border-b border-gray-400"></div>
|
||||
|
||||
<PlausibleWeb.Components.Billing.subscription_cancelled_notice
|
||||
user={@user}
|
||||
dismissable={false}
|
||||
/>
|
||||
<div class="my-4 border-b border-gray-400"></div>
|
||||
|
||||
<div class="flex flex-col items-center justify-between mt-8 sm:flex-row sm:items-start">
|
||||
<PlausibleWeb.Components.Billing.monthly_quota_box
|
||||
<PlausibleWeb.Components.Billing.subscription_cancelled_notice
|
||||
user={@user}
|
||||
subscription={@subscription}
|
||||
business_tier={FunWithFlags.enabled?(:business_tier, for: @user)}
|
||||
dismissable={false}
|
||||
/>
|
||||
<div
|
||||
class="h-32 px-2 py-4 my-4 text-center bg-gray-100 rounded dark:bg-gray-900"
|
||||
style="width: 11.75rem;"
|
||||
>
|
||||
<h4 class="font-black dark:text-gray-100">Next bill amount</h4>
|
||||
<%= if @subscription && @subscription.status in [Plausible.Billing.Subscription.Status.active(), Plausible.Billing.Subscription.Status.past_due()] do %>
|
||||
<div class="py-2 text-xl font-medium dark:text-gray-100">
|
||||
<%= PlausibleWeb.BillingView.present_currency(@subscription.currency_code) %><%= @subscription.next_bill_amount %>
|
||||
</div>
|
||||
<.styled_link :if={@subscription.update_url} href={@subscription.update_url}>
|
||||
Update billing info
|
||||
</.styled_link>
|
||||
<% else %>
|
||||
<div class="py-2 text-xl font-medium dark:text-gray-100">---</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div
|
||||
class="h-32 px-2 py-4 my-4 text-center bg-gray-100 rounded dark:bg-gray-900"
|
||||
style="width: 11.75rem;"
|
||||
>
|
||||
<h4 class="font-black dark:text-gray-100">Next bill date</h4>
|
||||
|
||||
<%= if @subscription && @subscription.next_bill_date && @subscription.status in [Plausible.Billing.Subscription.Status.active(), Plausible.Billing.Subscription.Status.past_due()] do %>
|
||||
<div class="py-2 text-xl font-medium dark:text-gray-100">
|
||||
<%= Timex.format!(@subscription.next_bill_date, "{Mshort} {D}, {YYYY}") %>
|
||||
</div>
|
||||
<span class="text-gray-600 dark:text-gray-400">
|
||||
(<%= subscription_interval(@subscription) %> billing)
|
||||
</span>
|
||||
<% else %>
|
||||
<div class="py-2 text-xl font-medium dark:text-gray-100">---</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<PlausibleWeb.Components.Billing.render_monthly_pageview_usage
|
||||
usage={@pageview_usage}
|
||||
limit={@pageview_limit}
|
||||
/>
|
||||
|
||||
<article class="mt-8">
|
||||
<h1 class="text-xl mb-3 font-bold dark:text-gray-100">Sites & team members usage</h1>
|
||||
<PlausibleWeb.Components.Billing.usage_and_limits_table>
|
||||
<PlausibleWeb.Components.Billing.usage_and_limits_row
|
||||
id="site-usage-row"
|
||||
title="Owned sites"
|
||||
usage={@site_usage}
|
||||
limit={@site_limit}
|
||||
<div class="flex flex-col items-center justify-between mt-8 sm:flex-row sm:items-start">
|
||||
<PlausibleWeb.Components.Billing.monthly_quota_box
|
||||
user={@user}
|
||||
subscription={@subscription}
|
||||
business_tier={FunWithFlags.enabled?(:business_tier, for: @user)}
|
||||
/>
|
||||
<PlausibleWeb.Components.Billing.usage_and_limits_row
|
||||
id="team-member-usage-row"
|
||||
title="Team members"
|
||||
usage={@team_member_usage}
|
||||
limit={@team_member_limit}
|
||||
/>
|
||||
</PlausibleWeb.Components.Billing.usage_and_limits_table>
|
||||
</article>
|
||||
|
||||
<%= cond do %>
|
||||
<% Plausible.Billing.Subscriptions.resumable?(@subscription) && @subscription.cancel_url -> %>
|
||||
<div class="mt-8">
|
||||
<%= link("Cancel my subscription",
|
||||
to: @subscription.cancel_url,
|
||||
class:
|
||||
"inline-block mt-4 px-4 py-2 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-md text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 focus:outline-none focus:border-blue-300 focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150"
|
||||
) %>
|
||||
</div>
|
||||
<% true -> %>
|
||||
<div class="mt-8">
|
||||
<PlausibleWeb.Components.Billing.upgrade_link
|
||||
user={@user}
|
||||
business_tier={FunWithFlags.enabled?(:business_tier, for: @user)}
|
||||
/>
|
||||
<div
|
||||
class="h-32 px-2 py-4 my-4 text-center bg-gray-100 rounded dark:bg-gray-900"
|
||||
style="width: 11.75rem;"
|
||||
>
|
||||
<h4 class="font-black dark:text-gray-100">Next bill amount</h4>
|
||||
<%= if @subscription && @subscription.status in [Plausible.Billing.Subscription.Status.active(), Plausible.Billing.Subscription.Status.past_due()] do %>
|
||||
<div class="py-2 text-xl font-medium dark:text-gray-100">
|
||||
<%= PlausibleWeb.BillingView.present_currency(@subscription.currency_code) %><%= @subscription.next_bill_amount %>
|
||||
</div>
|
||||
<.styled_link :if={@subscription.update_url} href={@subscription.update_url}>
|
||||
Update billing info
|
||||
</.styled_link>
|
||||
<% else %>
|
||||
<div class="py-2 text-xl font-medium dark:text-gray-100">---</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div
|
||||
class="h-32 px-2 py-4 my-4 text-center bg-gray-100 rounded dark:bg-gray-900"
|
||||
style="width: 11.75rem;"
|
||||
>
|
||||
<h4 class="font-black dark:text-gray-100">Next bill date</h4>
|
||||
|
||||
<%= case @invoices do %>
|
||||
<% {:error, :no_invoices} -> %>
|
||||
<% {:error, :request_failed} -> %>
|
||||
<div class="max-w-2xl px-8 pt-6 pb-8 mx-auto mt-16 bg-white border-t-2 border-orange-200 rounded rounded-t-none shadow-md dark:bg-gray-800">
|
||||
<h2 class="text-xl font-black dark:text-gray-100">Invoices</h2>
|
||||
<div class="my-4 border-b border-gray-300 dark:border-gray-500"></div>
|
||||
<p class="text-center text-black dark:text-gray-100 m-2">
|
||||
Something went wrong
|
||||
</p>
|
||||
</div>
|
||||
<% {:ok, invoice_list} when is_list(invoice_list) -> %>
|
||||
<div class="max-w-2xl px-8 pt-6 pb-8 mx-auto mt-16 bg-white border-t-2 border-orange-200 rounded rounded-t-none shadow-md dark:bg-gray-800">
|
||||
<h2 class="text-xl font-black dark:text-gray-100">Invoices</h2>
|
||||
<div class="my-4 border-b border-gray-300 dark:border-gray-500"></div>
|
||||
<table class="min-w-full divide-y divide-gray-200">
|
||||
<thead>
|
||||
<tr>
|
||||
<th
|
||||
scope="col"
|
||||
class="py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider"
|
||||
>
|
||||
Date
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider"
|
||||
>
|
||||
Amount
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider"
|
||||
>
|
||||
Invoice
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<%= for invoice <- format_invoices(invoice_list) do %>
|
||||
<tbody class="divide-y divide-gray-200">
|
||||
<tr>
|
||||
<td class="py-4 text-sm text-gray-800 dark:text-gray-200 font-medium">
|
||||
<%= invoice.date %>
|
||||
</td>
|
||||
<td class="py-4 text-sm text-gray-800 dark:text-gray-200">
|
||||
<%= invoice.currency <> invoice.amount %>
|
||||
</td>
|
||||
<td class="py-4 text-sm text-indigo-500">
|
||||
<%= link("Link", to: invoice.url, target: "_blank") %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<%= if @subscription && @subscription.next_bill_date && @subscription.status in [Plausible.Billing.Subscription.Status.active(), Plausible.Billing.Subscription.Status.past_due()] do %>
|
||||
<div class="py-2 text-xl font-medium dark:text-gray-100">
|
||||
<%= Timex.format!(@subscription.next_bill_date, "{Mshort} {D}, {YYYY}") %>
|
||||
</div>
|
||||
<span class="text-gray-600 dark:text-gray-400">
|
||||
(<%= subscription_interval(@subscription) %> billing)
|
||||
</span>
|
||||
<% else %>
|
||||
<div class="py-2 text-xl font-medium dark:text-gray-100">---</div>
|
||||
<% end %>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<div class="max-w-2xl px-8 pt-6 pb-8 mx-auto mt-16 bg-white border-t-2 border-green-500 rounded rounded-t-none shadow-md dark:bg-gray-800">
|
||||
<h2 class="text-xl font-black dark:text-gray-100">Dashboard Appearance</h2>
|
||||
<PlausibleWeb.Components.Billing.render_monthly_pageview_usage
|
||||
usage={@pageview_usage}
|
||||
limit={@pageview_limit}
|
||||
/>
|
||||
|
||||
<div class="my-4 border-b border-gray-300 dark:border-gray-500"></div>
|
||||
<article class="mt-8">
|
||||
<h1 class="text-xl mb-3 font-bold dark:text-gray-100">Sites & team members usage</h1>
|
||||
<PlausibleWeb.Components.Billing.usage_and_limits_table>
|
||||
<PlausibleWeb.Components.Billing.usage_and_limits_row
|
||||
id="site-usage-row"
|
||||
title="Owned sites"
|
||||
usage={@site_usage}
|
||||
limit={@site_limit}
|
||||
/>
|
||||
<PlausibleWeb.Components.Billing.usage_and_limits_row
|
||||
id="team-member-usage-row"
|
||||
title="Team members"
|
||||
usage={@team_member_usage}
|
||||
limit={@team_member_limit}
|
||||
/>
|
||||
</PlausibleWeb.Components.Billing.usage_and_limits_table>
|
||||
</article>
|
||||
|
||||
<%= form_for @settings_changeset, "/settings", [class: "max-w-sm"], fn f -> %>
|
||||
<div class="col-span-4 sm:col-span-2">
|
||||
<%= label(f, :theme, "Theme Selection",
|
||||
class: "block text-sm font-medium leading-5 text-gray-700 dark:text-gray-300"
|
||||
) %>
|
||||
<%= select(f, :theme, Plausible.Themes.options(),
|
||||
class:
|
||||
"dark:bg-gray-900 mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:text-gray-100 cursor-pointer"
|
||||
) %>
|
||||
<%= cond do %>
|
||||
<% Plausible.Billing.Subscriptions.resumable?(@subscription) && @subscription.cancel_url -> %>
|
||||
<div class="mt-8">
|
||||
<%= link("Cancel my subscription",
|
||||
to: @subscription.cancel_url,
|
||||
class:
|
||||
"inline-block mt-4 px-4 py-2 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-md text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 focus:outline-none focus:border-blue-300 focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150"
|
||||
) %>
|
||||
</div>
|
||||
<% true -> %>
|
||||
<div class="mt-8">
|
||||
<PlausibleWeb.Components.Billing.upgrade_link
|
||||
user={@user}
|
||||
business_tier={FunWithFlags.enabled?(:business_tier, for: @user)}
|
||||
/>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<PlausibleWeb.Components.Generic.button type="submit" class="mt-4">
|
||||
Save
|
||||
</PlausibleWeb.Components.Generic.button>
|
||||
<%= case @invoices do %>
|
||||
<% {:error, :no_invoices} -> %>
|
||||
<% {:error, :request_failed} -> %>
|
||||
<div class="max-w-2xl px-8 pt-6 pb-8 mx-auto mt-16 bg-white border-t-2 border-orange-200 rounded rounded-t-none shadow-md dark:bg-gray-800">
|
||||
<h2 class="text-xl font-black dark:text-gray-100">Invoices</h2>
|
||||
<div class="my-4 border-b border-gray-300 dark:border-gray-500"></div>
|
||||
<p class="text-center text-black dark:text-gray-100 m-2">
|
||||
Something went wrong
|
||||
</p>
|
||||
</div>
|
||||
<% {:ok, invoice_list} when is_list(invoice_list) -> %>
|
||||
<div class="max-w-2xl px-8 pt-6 pb-8 mx-auto mt-16 bg-white border-t-2 border-orange-200 rounded rounded-t-none shadow-md dark:bg-gray-800">
|
||||
<h2 class="text-xl font-black dark:text-gray-100">Invoices</h2>
|
||||
<div class="my-4 border-b border-gray-300 dark:border-gray-500"></div>
|
||||
<table class="min-w-full divide-y divide-gray-200">
|
||||
<thead>
|
||||
<tr>
|
||||
<th
|
||||
scope="col"
|
||||
class="py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider"
|
||||
>
|
||||
Date
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider"
|
||||
>
|
||||
Amount
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider"
|
||||
>
|
||||
Invoice
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<%= for invoice <- format_invoices(invoice_list) do %>
|
||||
<tbody class="divide-y divide-gray-200">
|
||||
<tr>
|
||||
<td class="py-4 text-sm text-gray-800 dark:text-gray-200 font-medium">
|
||||
<%= invoice.date %>
|
||||
</td>
|
||||
<td class="py-4 text-sm text-gray-800 dark:text-gray-200">
|
||||
<%= invoice.currency <> invoice.amount %>
|
||||
</td>
|
||||
<td class="py-4 text-sm text-indigo-500">
|
||||
<%= link("Link", to: invoice.url, target: "_blank") %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<% end %>
|
||||
</table>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="max-w-2xl px-8 pt-6 pb-8 mx-auto mt-16 bg-white border-t-2 border-indigo-100 rounded rounded-t-none shadow-md dark:bg-gray-800 dark:border-indigo-500">
|
||||
<h2 id="change-account-name" class="text-xl font-black dark:text-gray-100">
|
||||
Change account name
|
||||
</h2>
|
||||
<div class="max-w-2xl px-8 pt-6 pb-8 mx-auto mt-16 bg-white border-t-2 border-green-500 rounded rounded-t-none shadow-md dark:bg-gray-800">
|
||||
<h2 class="text-xl font-black dark:text-gray-100">Dashboard Appearance</h2>
|
||||
|
||||
<div class="my-4 border-b border-gray-300 dark:border-gray-500"></div>
|
||||
<div class="my-4 border-b border-gray-300 dark:border-gray-500"></div>
|
||||
|
||||
<%= form_for @settings_changeset, "/settings#change-account-name", [class: "max-w-sm"], fn f -> %>
|
||||
<div class="my-4">
|
||||
<%= label(f, :name, class: "block text-sm font-medium text-gray-700 dark:text-gray-300") %>
|
||||
<div class="mt-1">
|
||||
<%= text_input(f, :name,
|
||||
<%= form_for @settings_changeset, "/settings", [class: "max-w-sm"], fn f -> %>
|
||||
<div class="col-span-4 sm:col-span-2">
|
||||
<%= label(f, :theme, "Theme Selection",
|
||||
class: "block text-sm font-medium leading-5 text-gray-700 dark:text-gray-300"
|
||||
) %>
|
||||
<%= select(f, :theme, Plausible.Themes.options(),
|
||||
class:
|
||||
"shadow-sm dark:bg-gray-900 dark:text-gray-300 focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-500 rounded-md dark:bg-gray-800"
|
||||
"dark:bg-gray-900 mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:text-gray-100 cursor-pointer"
|
||||
) %>
|
||||
<%= error_tag(f, :name) %>
|
||||
</div>
|
||||
</div>
|
||||
<PlausibleWeb.Components.Generic.button type="submit" class="mt-4">
|
||||
Save
|
||||
</PlausibleWeb.Components.Generic.button>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="max-w-2xl px-8 pt-6 pb-8 mx-auto mt-16 bg-white border-t-2 border-red-600 rounded rounded-t-none shadow-md dark:bg-gray-800">
|
||||
<h2 id="change-email-address" class="text-xl font-black dark:text-gray-100">
|
||||
Change email address
|
||||
</h2>
|
||||
<PlausibleWeb.Components.Generic.button type="submit" class="mt-4">
|
||||
Save
|
||||
</PlausibleWeb.Components.Generic.button>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="my-4 border-b border-gray-300 dark:border-gray-500"></div>
|
||||
<div
|
||||
:if={FunWithFlags.enabled?(:two_factor, for: @user)}
|
||||
class="max-w-2xl px-8 pt-6 pb-8 mx-auto mt-16 bg-white border-t-2 border-green-500 rounded rounded-t-none shadow-md dark:bg-gray-800"
|
||||
>
|
||||
<h2 id="setup-2fa" class="text-xl font-black dark:text-gray-100">
|
||||
Two-Factor Authentication (2FA)
|
||||
</h2>
|
||||
|
||||
<%= form_for @email_changeset, "/settings/email#change-email-address", [class: "max-w-sm"], fn f -> %>
|
||||
<div class="my-4">
|
||||
<%= label(f, :password, "Account password",
|
||||
class: "block text-sm font-medium text-gray-700 dark:text-gray-300"
|
||||
) %>
|
||||
<div class="mt-1">
|
||||
<%= password_input(f, :password,
|
||||
class:
|
||||
"shadow-sm dark:bg-gray-900 dark:text-gray-300 focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-500 rounded-md dark:bg-gray-800"
|
||||
<p class="text-sm mt-2 text-gray-600 dark:text-gray-400">
|
||||
Two-Factor Authentication protects your account by adding an extra security step when you log in.
|
||||
</p>
|
||||
|
||||
<%= if @totp_enabled? do %>
|
||||
<button
|
||||
x-on:click="disable2FAOpen = true; $refs.disable2FAPassword.value = ''"
|
||||
type="button"
|
||||
class="inline-block mt-4 px-4 py-2 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-md text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 dark:hover:text-red-400 focus:outline-none focus:border-blue-300 focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150"
|
||||
>
|
||||
Disable 2FA
|
||||
</button>
|
||||
|
||||
<p class="mt-2 text-gray-600 text-sm dark:text-gray-400">
|
||||
Lost your recovery codes?
|
||||
<a
|
||||
href="#setup-2fa"
|
||||
x-on:click="regenerate2FAOpen = true; $refs.regenerate2FAPassword.value = ''"
|
||||
class="underline text-indigo-600"
|
||||
>
|
||||
Generate new
|
||||
</a>
|
||||
</p>
|
||||
<% else %>
|
||||
<%= form_for @conn.params, Routes.auth_path(@conn, :initiate_2fa_setup), fn _ -> %>
|
||||
<PlausibleWeb.Components.Generic.button type="submit" class="mt-4">
|
||||
Enable 2FA
|
||||
</PlausibleWeb.Components.Generic.button>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="max-w-2xl px-8 pt-6 pb-8 mx-auto mt-16 bg-white border-t-2 border-indigo-100 rounded rounded-t-none shadow-md dark:bg-gray-800 dark:border-indigo-500">
|
||||
<h2 id="change-account-name" class="text-xl font-black dark:text-gray-100">
|
||||
Change account name
|
||||
</h2>
|
||||
|
||||
<div class="my-4 border-b border-gray-300 dark:border-gray-500"></div>
|
||||
|
||||
<%= form_for @settings_changeset, "/settings#change-account-name", [class: "max-w-sm"], fn f -> %>
|
||||
<div class="my-4">
|
||||
<%= label(f, :name, class: "block text-sm font-medium text-gray-700 dark:text-gray-300") %>
|
||||
<div class="mt-1">
|
||||
<%= text_input(f, :name,
|
||||
class:
|
||||
"shadow-sm dark:bg-gray-900 dark:text-gray-300 focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-500 rounded-md dark:bg-gray-800"
|
||||
) %>
|
||||
<%= error_tag(f, :name) %>
|
||||
</div>
|
||||
</div>
|
||||
<PlausibleWeb.Components.Generic.button type="submit" class="mt-4">
|
||||
Save
|
||||
</PlausibleWeb.Components.Generic.button>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="max-w-2xl px-8 pt-6 pb-8 mx-auto mt-16 bg-white border-t-2 border-red-600 rounded rounded-t-none shadow-md dark:bg-gray-800">
|
||||
<h2 id="change-email-address" class="text-xl font-black dark:text-gray-100">
|
||||
Change email address
|
||||
</h2>
|
||||
|
||||
<div class="my-4 border-b border-gray-300 dark:border-gray-500"></div>
|
||||
|
||||
<%= form_for @email_changeset, "/settings/email#change-email-address", [class: "max-w-sm"], fn f -> %>
|
||||
<div class="my-4">
|
||||
<%= label(f, :password, "Account password",
|
||||
class: "block text-sm font-medium text-gray-700 dark:text-gray-300"
|
||||
) %>
|
||||
<%= error_tag(f, :password) %>
|
||||
<div class="mt-1">
|
||||
<%= password_input(f, :password,
|
||||
class:
|
||||
"shadow-sm dark:bg-gray-900 dark:text-gray-300 focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-500 rounded-md dark:bg-gray-800"
|
||||
) %>
|
||||
<%= error_tag(f, :password) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="my-4">
|
||||
<%= label(f, :current_email, "Current email",
|
||||
class: "block text-sm font-medium text-gray-700 dark:text-gray-300"
|
||||
) %>
|
||||
<div class="mt-1">
|
||||
<%= email_input(f, :current_email,
|
||||
readonly: true,
|
||||
value: f.data.email,
|
||||
class:
|
||||
"shadow-sm dark:bg-gray-900 dark:text-gray-300 focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-500 rounded-md dark:bg-gray-800 bg-gray-100"
|
||||
<div class="my-4">
|
||||
<%= label(f, :current_email, "Current email",
|
||||
class: "block text-sm font-medium text-gray-700 dark:text-gray-300"
|
||||
) %>
|
||||
<div class="mt-1">
|
||||
<%= email_input(f, :current_email,
|
||||
readonly: true,
|
||||
value: f.data.email,
|
||||
class:
|
||||
"shadow-sm dark:bg-gray-900 dark:text-gray-300 focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-500 rounded-md dark:bg-gray-800 bg-gray-100"
|
||||
) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="my-4">
|
||||
<%= label(f, :email, "New email",
|
||||
class: "block text-sm font-medium text-gray-700 dark:text-gray-300"
|
||||
) %>
|
||||
<div class="mt-1">
|
||||
<%= email_input(f, :email,
|
||||
value: f.params["email"],
|
||||
class:
|
||||
"shadow-sm dark:bg-gray-900 dark:text-gray-300 focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-500 rounded-md"
|
||||
<div class="my-4">
|
||||
<%= label(f, :email, "New email",
|
||||
class: "block text-sm font-medium text-gray-700 dark:text-gray-300"
|
||||
) %>
|
||||
<%= error_tag(f, :email) %>
|
||||
<div class="mt-1">
|
||||
<%= email_input(f, :email,
|
||||
value: f.params["email"],
|
||||
class:
|
||||
"shadow-sm dark:bg-gray-900 dark:text-gray-300 focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-500 rounded-md"
|
||||
) %>
|
||||
<%= error_tag(f, :email) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= submit("Change my email",
|
||||
class:
|
||||
"inline-block mt-4 px-4 py-2 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-md text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 dark:hover:text-red-400 focus:outline-none focus:border-blue-300 focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150"
|
||||
) %>
|
||||
<% end %>
|
||||
</div>
|
||||
<%= submit("Change my email",
|
||||
class:
|
||||
"inline-block mt-4 px-4 py-2 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-md text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 dark:hover:text-red-400 focus:outline-none focus:border-blue-300 focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150"
|
||||
) %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div
|
||||
id="api-keys"
|
||||
class="max-w-2xl px-8 pt-6 pb-8 mx-auto mt-16 bg-white border-t-2 border-indigo-100 rounded rounded-t-none shadow-md dark:bg-gray-800 dark:border-indigo-500"
|
||||
>
|
||||
<h2 class="text-xl font-black dark:text-gray-100">API Keys</h2>
|
||||
<div class="my-4 border-b border-gray-300 dark:border-gray-500"></div>
|
||||
|
||||
<PlausibleWeb.Components.Billing.premium_feature_notice
|
||||
billable_user={@current_user}
|
||||
current_user={@current_user}
|
||||
feature_mod={Plausible.Billing.Feature.StatsAPI}
|
||||
/>
|
||||
|
||||
<div class="flex flex-col mt-6">
|
||||
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
|
||||
<div class="inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8">
|
||||
<%= if Enum.any?(@user.api_keys) do %>
|
||||
<div class="overflow-hidden border-b border-gray-200 shadow dark:border-gray-900 sm:rounded-lg">
|
||||
<table class="min-w-full divide-y divide-gray-200 dark:divide-gray-900">
|
||||
<thead class="bg-gray-50 dark:bg-gray-900">
|
||||
<tr>
|
||||
<th
|
||||
scope="col"
|
||||
class="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase dark:text-gray-100"
|
||||
>
|
||||
Name
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase dark:text-gray-100"
|
||||
>
|
||||
Key
|
||||
</th>
|
||||
<th scope="col" class="relative px-6 py-3">
|
||||
<span class="sr-only">Revoke</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<%= for api_key <- @user.api_keys do %>
|
||||
<tr class="bg-white dark:bg-gray-800">
|
||||
<td class="px-6 py-4 text-sm font-medium text-gray-900 dark:text-gray-100 whitespace-nowrap">
|
||||
<%= api_key.name %>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-sm text-gray-500 dark:text-gray-100 whitespace-nowrap">
|
||||
<%= api_key.key_prefix %><%= String.duplicate("*", 32 - 6) %>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-sm font-medium text-right whitespace-nowrap">
|
||||
<%= button("Revoke",
|
||||
to: "/settings/api-keys/#{api_key.id}",
|
||||
class: "text-red-600 hover:text-red-900",
|
||||
method: :delete,
|
||||
"data-confirm":
|
||||
"Are you sure you want to revoke this key? This action cannot be reversed."
|
||||
) %>
|
||||
</td>
|
||||
<div
|
||||
id="api-keys"
|
||||
class="max-w-2xl px-8 pt-6 pb-8 mx-auto mt-16 bg-white border-t-2 border-indigo-100 rounded rounded-t-none shadow-md dark:bg-gray-800 dark:border-indigo-500"
|
||||
>
|
||||
<h2 class="text-xl font-black dark:text-gray-100">API Keys</h2>
|
||||
<div class="my-4 border-b border-gray-300 dark:border-gray-500"></div>
|
||||
|
||||
<PlausibleWeb.Components.Billing.premium_feature_notice
|
||||
billable_user={@current_user}
|
||||
current_user={@current_user}
|
||||
feature_mod={Plausible.Billing.Feature.StatsAPI}
|
||||
/>
|
||||
|
||||
<div class="flex flex-col mt-6">
|
||||
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
|
||||
<div class="inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8">
|
||||
<%= if Enum.any?(@user.api_keys) do %>
|
||||
<div class="overflow-hidden border-b border-gray-200 shadow dark:border-gray-900 sm:rounded-lg">
|
||||
<table class="min-w-full divide-y divide-gray-200 dark:divide-gray-900">
|
||||
<thead class="bg-gray-50 dark:bg-gray-900">
|
||||
<tr>
|
||||
<th
|
||||
scope="col"
|
||||
class="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase dark:text-gray-100"
|
||||
>
|
||||
Name
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase dark:text-gray-100"
|
||||
>
|
||||
Key
|
||||
</th>
|
||||
<th scope="col" class="relative px-6 py-3">
|
||||
<span class="sr-only">Revoke</span>
|
||||
</th>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<% end %>
|
||||
</thead>
|
||||
<tbody>
|
||||
<%= for api_key <- @user.api_keys do %>
|
||||
<tr class="bg-white dark:bg-gray-800">
|
||||
<td class="px-6 py-4 text-sm font-medium text-gray-900 dark:text-gray-100 whitespace-nowrap">
|
||||
<%= api_key.name %>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-sm text-gray-500 dark:text-gray-100 whitespace-nowrap">
|
||||
<%= api_key.key_prefix %><%= String.duplicate("*", 32 - 6) %>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-sm font-medium text-right whitespace-nowrap">
|
||||
<%= button("Revoke",
|
||||
to: "/settings/api-keys/#{api_key.id}",
|
||||
class: "text-red-600 hover:text-red-900",
|
||||
method: :delete,
|
||||
"data-confirm":
|
||||
"Are you sure you want to revoke this key? This action cannot be reversed."
|
||||
) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<PlausibleWeb.Components.Generic.button_link
|
||||
:if={Plausible.Billing.Feature.StatsAPI.check_availability(@current_user) == :ok}
|
||||
href={Routes.auth_path(@conn, :new_api_key)}
|
||||
class="mt-4"
|
||||
>
|
||||
+ New API Key
|
||||
</PlausibleWeb.Components.Generic.button_link>
|
||||
<PlausibleWeb.Components.Generic.button_link
|
||||
:if={Plausible.Billing.Feature.StatsAPI.check_availability(@current_user) == :ok}
|
||||
href={Routes.auth_path(@conn, :new_api_key)}
|
||||
class="mt-4"
|
||||
>
|
||||
+ New API Key
|
||||
</PlausibleWeb.Components.Generic.button_link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="max-w-2xl px-8 pt-6 pb-8 mx-auto mt-16 mb-24 bg-white border-t-2 border-red-600 rounded rounded-t-none shadow-md dark:bg-gray-800">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-xl font-black dark:text-gray-100">Delete account</h2>
|
||||
<div class="max-w-2xl px-8 pt-6 pb-8 mx-auto mt-16 mb-24 bg-white border-t-2 border-red-600 rounded rounded-t-none shadow-md dark:bg-gray-800">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-xl font-black dark:text-gray-100">Delete account</h2>
|
||||
</div>
|
||||
|
||||
<div class="my-4 border-b border-gray-300 dark:border-gray-500"></div>
|
||||
|
||||
<p class="dark:text-gray-100">
|
||||
Deleting your account removes all sites and stats you've collected
|
||||
</p>
|
||||
|
||||
<%= if @subscription && @subscription.status == Plausible.Billing.Subscription.Status.active() do %>
|
||||
<span class="mt-6 bg-gray-300 button dark:bg-gray-600 hover:shadow-none hover:bg-gray-300 cursor-not-allowed">
|
||||
Delete my account
|
||||
</span>
|
||||
<p class="mt-2 text-sm text-gray-600 dark:text-gray-400">
|
||||
Your account cannot be deleted because you have an active subscription. If you want to delete your account, please cancel your subscription first.
|
||||
</p>
|
||||
<% else %>
|
||||
<%= link("Delete my account",
|
||||
to: "/me",
|
||||
class:
|
||||
"inline-block mt-4 px-4 py-2 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-md text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 dark:hover:text-red-400 focus:outline-none focus:border-blue-300 focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150",
|
||||
method: "delete",
|
||||
data: [
|
||||
confirm:
|
||||
"Deleting your account will also delete all the sites and data that you own. This action cannot be reversed. Are you sure?"
|
||||
]
|
||||
) %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="my-4 border-b border-gray-300 dark:border-gray-500"></div>
|
||||
<PlausibleWeb.Components.TwoFactor.modal
|
||||
:let={f}
|
||||
:if={FunWithFlags.enabled?(:two_factor, for: @user)}
|
||||
id="disable-2fa-modal"
|
||||
state_param="disable2FAOpen"
|
||||
form_data={@conn.params}
|
||||
form_target={Routes.auth_path(@conn, :disable_2fa)}
|
||||
title="Disable Two-Factor Authentication?"
|
||||
>
|
||||
<:icon>
|
||||
<Heroicons.shield_exclamation class="h-6 w-6" />
|
||||
</:icon>
|
||||
<:buttons>
|
||||
<.button type="submit" class="w-full sm:w-auto">
|
||||
Disable 2FA
|
||||
</.button>
|
||||
</:buttons>
|
||||
|
||||
<p class="dark:text-gray-100">
|
||||
Deleting your account removes all sites and stats you've collected
|
||||
</p>
|
||||
<div class="text-sm mt-2">
|
||||
Once disabled, verification codes from the authenticator application and current recovery codes will become invalid. 2FA will have to be setup from the start.
|
||||
</div>
|
||||
|
||||
<%= if @subscription && @subscription.status == Plausible.Billing.Subscription.Status.active() do %>
|
||||
<span class="mt-6 bg-gray-300 button dark:bg-gray-600 hover:shadow-none hover:bg-gray-300 cursor-not-allowed">
|
||||
Delete my account
|
||||
</span>
|
||||
<p class="mt-2 text-sm text-gray-600 dark:text-gray-400">
|
||||
Your account cannot be deleted because you have an active subscription. If you want to delete your account, please cancel your subscription first.
|
||||
</p>
|
||||
<% else %>
|
||||
<%= link("Delete my account",
|
||||
to: "/me",
|
||||
class:
|
||||
"inline-block mt-4 px-4 py-2 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-md text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 dark:hover:text-red-400 focus:outline-none focus:border-blue-300 focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150",
|
||||
method: "delete",
|
||||
data: [
|
||||
confirm:
|
||||
"Deleting your account will also delete all the sites and data that you own. This action cannot be reversed. Are you sure?"
|
||||
]
|
||||
) %>
|
||||
<% end %>
|
||||
<div class="text-sm mt-2">
|
||||
Enter your password to disable 2FA.
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
<%= password_input(f, :password,
|
||||
id: "disable_2fa_password",
|
||||
placeholder: "Enter password",
|
||||
"x-ref": "disable2FAPassword",
|
||||
class:
|
||||
"shadow-sm dark:bg-gray-900 dark:text-gray-300 focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-500 rounded-md dark:bg-gray-800"
|
||||
) %>
|
||||
</div>
|
||||
</PlausibleWeb.Components.TwoFactor.modal>
|
||||
|
||||
<PlausibleWeb.Components.TwoFactor.modal
|
||||
:let={f}
|
||||
:if={FunWithFlags.enabled?(:two_factor, for: @user)}
|
||||
id="regenerate-2fa-modal"
|
||||
state_param="regenerate2FAOpen"
|
||||
form_data={@conn.params}
|
||||
form_target={Routes.auth_path(@conn, :generate_2fa_recovery_codes)}
|
||||
onsubmit="document.getElementById('generate-2fa-recovery-button').disabled = true"
|
||||
title="Generate New Recovery Codes?"
|
||||
>
|
||||
<:icon>
|
||||
<Heroicons.key class="h-6 w-6" />
|
||||
</:icon>
|
||||
|
||||
<:buttons>
|
||||
<.button
|
||||
id="generate-2fa-recovery-button"
|
||||
type="submit"
|
||||
class="w-full sm:w-auto [&>span.label-enabled]:block [&>span.label-disabled]:hidden [&[disabled]>span.label-enabled]:hidden [&[disabled]>span.label-disabled]:block"
|
||||
>
|
||||
<span class="label-enabled pointer-events-none">
|
||||
Generate New Codes
|
||||
</span>
|
||||
|
||||
<span class="label-disabled">
|
||||
<.spinner class="inline-block h-5 w-5 mr-2 text-white dark:text-gray-400" />
|
||||
Generating Codes
|
||||
</span>
|
||||
</.button>
|
||||
</:buttons>
|
||||
|
||||
<div class="text-sm mt-2">
|
||||
If you generate new codes, the old ones will become invalid.
|
||||
</div>
|
||||
|
||||
<div class="text-sm mt-2">
|
||||
Enter your password to continue.
|
||||
</div>
|
||||
|
||||
<div class="mt-3 w-full">
|
||||
<%= password_input(f, :password,
|
||||
id: "regenerate_2fa_password",
|
||||
placeholder: "Enter password",
|
||||
"x-ref": "regenerate2FAPassword",
|
||||
class:
|
||||
"w-full shadow-sm dark:bg-gray-900 dark:text-gray-300 focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-500 rounded-md dark:bg-gray-800"
|
||||
) %>
|
||||
</div>
|
||||
</PlausibleWeb.Components.TwoFactor.modal>
|
||||
</div>
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
<div class="w-full max-w-3xl mt-4 mx-auto flex">
|
||||
<%= form_for @conn.params, Routes.auth_path(@conn, :verify_2fa), [
|
||||
class: "w-full max-w-lg mx-auto bg-white dark:bg-gray-800 shadow-md rounded px-8 py-6 mb-4 mt-8",
|
||||
onsubmit: "document.getElementById('verify-button').disabled = true"
|
||||
], fn f -> %>
|
||||
<h2 class="text-xl font-black dark:text-gray-100">
|
||||
Enter Your 2FA Code
|
||||
</h2>
|
||||
|
||||
<div class="text-sm mt-2 text-gray-500 dark:text-gray-200 leading-tight">
|
||||
Enter the code from your authenticator application before it expires or wait for a new one.
|
||||
<PlausibleWeb.Components.TwoFactor.verify_2fa_input form={f} field={:code} class="mt-6" />
|
||||
|
||||
<div class="mt-4 flex flex-inline items-center sm:justify-start justify-center">
|
||||
<%= checkbox(f, :remember_2fa,
|
||||
class:
|
||||
"block h-5 w-5 rounded dark:bg-gray-700 border-gray-300 text-indigo-600 focus:ring-indigo-600"
|
||||
) %>
|
||||
<label class="block ml-2" for="remember_2fa">
|
||||
Trust this device for <%= @remember_2fa_days %> days
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex flex-row justify-between items-center">
|
||||
<p class="text-sm">
|
||||
Can't access your authenticator application?
|
||||
<a
|
||||
href={Routes.auth_path(@conn, :verify_2fa_recovery_code_form)}
|
||||
class="underline text-indigo-600"
|
||||
>
|
||||
Use recovery code
|
||||
</a>
|
||||
<%= if full_build?() do %>
|
||||
<br /> Lost your recovery codes?
|
||||
<a href="https://plausible.io/contact" class="underline text-indigo-600">
|
||||
Contact us
|
||||
</a>
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
@ -0,0 +1,59 @@
|
||||
<div class="w-full max-w-3xl mt-4 mx-auto flex">
|
||||
<%= form_for @conn.params,
|
||||
Routes.auth_path(@conn, :verify_2fa_recovery_code),
|
||||
[
|
||||
class: "w-full max-w-lg mx-auto bg-white dark:bg-gray-800 shadow-md rounded px-8 py-6 mb-4 mt-8",
|
||||
onsubmit: "document.getElementById('use-code-button').disabled = true"
|
||||
], fn f -> %>
|
||||
<h2 class="text-xl font-black dark:text-gray-100">
|
||||
Enter Recovery Code
|
||||
</h2>
|
||||
|
||||
<div class="text-sm mt-2 text-gray-500 dark:text-gray-200 leading-tight">
|
||||
Can't access your authenticator application? Enter a recovery code instead.
|
||||
<div class="mt-6">
|
||||
<div>
|
||||
<%= text_input(f, :recovery_code,
|
||||
value: "",
|
||||
autocomplete: "off",
|
||||
class:
|
||||
"font-medium shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full px-2 border-gray-300 dark:border-gray-500 dark:text-gray-200 dark:bg-gray-900 rounded-md",
|
||||
maxlength: "10",
|
||||
oninvalid: "document.getElementById('use-code-button').disabled = false",
|
||||
placeholder: "Enter recovery code",
|
||||
required: "required"
|
||||
) %>
|
||||
</div>
|
||||
<.button
|
||||
id="use-code-button"
|
||||
type="submit"
|
||||
class="w-full mt-2 [&>span.label-enabled]:block [&>span.label-disabled]:hidden [&[disabled]>span.label-enabled]:hidden [&[disabled]>span.label-disabled]:block"
|
||||
>
|
||||
<span class="label-enabled pointer-events-none">
|
||||
Use Code
|
||||
</span>
|
||||
|
||||
<span class="label-disabled">
|
||||
<PlausibleWeb.Components.Generic.spinner class="inline-block h-5 w-5 mr-2 text-white dark:text-gray-400" />
|
||||
Verifying...
|
||||
</span>
|
||||
</.button>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex flex-row justify-between items-center">
|
||||
<p class="text-sm">
|
||||
Authenticator application working again?
|
||||
<a href={Routes.auth_path(@conn, :verify_2fa)} class="underline text-indigo-600">
|
||||
Enter verification code
|
||||
</a>
|
||||
<%= if full_build?() do %>
|
||||
<br /> Lost your recovery codes?
|
||||
<a href="https://plausible.io/contact" class="underline text-indigo-600">
|
||||
Contact us
|
||||
</a>
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
@ -0,0 +1,38 @@
|
||||
<div class="w-full max-w-3xl mt-4 mx-auto flex">
|
||||
<div class="w-full max-w-lg mx-auto bg-white dark:bg-gray-800 shadow-md rounded px-8 py-6 mb-4 mt-8">
|
||||
<h2 class="text-xl font-black dark:text-gray-100">
|
||||
Setup Two-Factor Authentication
|
||||
</h2>
|
||||
|
||||
<div class="text-sm mt-2 text-gray-500 dark:text-gray-200 leading-tight">
|
||||
<%= form_for @conn.params, Routes.auth_path(@conn, :verify_2fa_setup), [
|
||||
id: "verify-2fa-form",
|
||||
onsubmit: "document.getElementById('verify-button').disabled = true"
|
||||
], fn f -> %>
|
||||
Enter the code from your authenticator application before it expires or wait for a new one.
|
||||
<PlausibleWeb.Components.TwoFactor.verify_2fa_input form={f} field={:code} class="mt-6" />
|
||||
<% end %>
|
||||
|
||||
<div class="mt-6 flex flex-col">
|
||||
<p class="text-sm">
|
||||
Changed your mind?
|
||||
<a
|
||||
href={Routes.auth_path(@conn, :user_settings) <> "#setup-2fa"}
|
||||
class="underline text-indigo-600"
|
||||
>
|
||||
Go back to Settings
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p class="text-sm">
|
||||
<%= form_for @conn.params, Routes.auth_path(@conn, :initiate_2fa_setup), [id: "start-over-form"], fn _f -> %>
|
||||
Having trouble?
|
||||
<button class="underline text-indigo-600">
|
||||
Start over
|
||||
</button>
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -1 +1 @@
|
||||
Two-factor authentication is now disabled on your account.
|
||||
Two-Factor Authentication is now disabled on your account.
|
||||
|
||||
@ -1 +1 @@
|
||||
Two-factor authentication is now enabled on your account.
|
||||
Two-Factor Authentication is now enabled on your account.
|
||||
|
||||
@ -0,0 +1,96 @@
|
||||
defmodule PlausibleWeb.TwoFactor.Session do
|
||||
@moduledoc """
|
||||
Functions for managing session data related to Two-Factor
|
||||
Authentication.
|
||||
"""
|
||||
|
||||
import Plug.Conn
|
||||
|
||||
alias Plausible.Auth
|
||||
|
||||
@remember_2fa_cookie "remember_2fa"
|
||||
@remember_2fa_days 30
|
||||
@remember_2fa_seconds @remember_2fa_days * 24 * 60 * 60
|
||||
|
||||
@session_2fa_cookie "session_2fa"
|
||||
@session_2fa_seconds 5 * 60
|
||||
|
||||
@spec set_2fa_user(Plug.Conn.t(), Auth.User.t()) :: Plug.Conn.t()
|
||||
def set_2fa_user(conn, %Auth.User{} = user) do
|
||||
put_resp_cookie(conn, @session_2fa_cookie, %{current_2fa_user_id: user.id},
|
||||
domain: domain(),
|
||||
secure: secure_cookie?(),
|
||||
encrypt: true,
|
||||
max_age: @session_2fa_seconds,
|
||||
same_site: "Lax"
|
||||
)
|
||||
end
|
||||
|
||||
@spec get_2fa_user(Plug.Conn.t()) :: {:ok, Auth.User.t()} | {:error, :not_found}
|
||||
def get_2fa_user(conn) do
|
||||
conn = fetch_cookies(conn, encrypted: [@session_2fa_cookie])
|
||||
session_2fa = conn.cookies[@session_2fa_cookie]
|
||||
|
||||
with id when is_integer(id) <- session_2fa[:current_2fa_user_id],
|
||||
%Auth.User{} = user <- Plausible.Users.with_subscription(id) do
|
||||
{:ok, user}
|
||||
else
|
||||
_ -> {:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
@spec clear_2fa_user(Plug.Conn.t()) :: Plug.Conn.t()
|
||||
def clear_2fa_user(conn) do
|
||||
delete_resp_cookie(conn, @session_2fa_cookie,
|
||||
domain: domain(),
|
||||
secure: secure_cookie?(),
|
||||
encrypt: true,
|
||||
max_age: @session_2fa_seconds,
|
||||
same_site: "Lax"
|
||||
)
|
||||
end
|
||||
|
||||
@spec remember_2fa_days() :: non_neg_integer()
|
||||
def remember_2fa_days(), do: @remember_2fa_days
|
||||
|
||||
@spec remember_2fa?(Plug.Conn.t(), Auth.User.t()) :: boolean()
|
||||
def remember_2fa?(conn, user) do
|
||||
conn = fetch_cookies(conn, encrypted: [@remember_2fa_cookie])
|
||||
|
||||
not is_nil(user.totp_token) and conn.cookies[@remember_2fa_cookie] == user.totp_token
|
||||
end
|
||||
|
||||
@spec maybe_set_remember_2fa(Plug.Conn.t(), Auth.User.t(), String.t() | nil) :: Plug.Conn.t()
|
||||
def maybe_set_remember_2fa(conn, user, "true") do
|
||||
put_resp_cookie(conn, @remember_2fa_cookie, user.totp_token,
|
||||
domain: domain(),
|
||||
secure: secure_cookie?(),
|
||||
encrypt: true,
|
||||
max_age: @remember_2fa_seconds,
|
||||
same_site: "Lax"
|
||||
)
|
||||
end
|
||||
|
||||
def maybe_set_remember_2fa(conn, _, _) do
|
||||
clear_remember_2fa(conn)
|
||||
end
|
||||
|
||||
@spec clear_remember_2fa(Plug.Conn.t()) :: Plug.Conn.t()
|
||||
def clear_remember_2fa(conn) do
|
||||
delete_resp_cookie(conn, @remember_2fa_cookie,
|
||||
domain: domain(),
|
||||
secure: secure_cookie?(),
|
||||
encrypt: true,
|
||||
max_age: @remember_2fa_seconds,
|
||||
same_site: "Lax"
|
||||
)
|
||||
end
|
||||
|
||||
defp domain(), do: PlausibleWeb.Endpoint.host()
|
||||
|
||||
defp secure_cookie?() do
|
||||
:plausible
|
||||
|> Application.fetch_env!(PlausibleWeb.Endpoint)
|
||||
|> Keyword.fetch!(:secure_cookie)
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue