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"""
<%= 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" ) %> Verify → Verifying...
""" 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""" """ end end