rodauth_phlex 0.1.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.standard.yml +3 -0
  4. data/CHANGELOG.md +5 -0
  5. data/CODE_OF_CONDUCT.md +132 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +90 -0
  8. data/Rakefile +10 -0
  9. data/lib/rodauth_phlex/component.rb +15 -0
  10. data/lib/rodauth_phlex/components/add_recovery_codes.rb +21 -0
  11. data/lib/rodauth_phlex/components/button.rb +33 -0
  12. data/lib/rodauth_phlex/components/change_login.rb +22 -0
  13. data/lib/rodauth_phlex/components/email_auth_request_form.rb +20 -0
  14. data/lib/rodauth_phlex/components/formatted_field_error.rb +23 -0
  15. data/lib/rodauth_phlex/components/global_logout_field.rb +20 -0
  16. data/lib/rodauth_phlex/components/input_field.rb +74 -0
  17. data/lib/rodauth_phlex/components/login_confirm_field.rb +18 -0
  18. data/lib/rodauth_phlex/components/login_display.rb +19 -0
  19. data/lib/rodauth_phlex/components/login_field.rb +18 -0
  20. data/lib/rodauth_phlex/components/login_form.rb +25 -0
  21. data/lib/rodauth_phlex/components/login_form_footer.rb +20 -0
  22. data/lib/rodauth_phlex/components/login_hidden_field.rb +16 -0
  23. data/lib/rodauth_phlex/components/otp_auth_code_field.rb +22 -0
  24. data/lib/rodauth_phlex/components/password_confirm_field.rb +18 -0
  25. data/lib/rodauth_phlex/components/password_field.rb +18 -0
  26. data/lib/rodauth_phlex/components/recovery_codes.rb +24 -0
  27. data/lib/rodauth_phlex/components/sms_code_field.rb +22 -0
  28. data/lib/rodauth_phlex/components/webauthn_autofill.rb +26 -0
  29. data/lib/rodauth_phlex/components.rb +27 -0
  30. data/lib/rodauth_phlex/email.rb +23 -0
  31. data/lib/rodauth_phlex/emails/email_auth_email.rb +21 -0
  32. data/lib/rodauth_phlex/emails/otp_disabled_email.rb +18 -0
  33. data/lib/rodauth_phlex/emails/otp_locked_out_email.rb +25 -0
  34. data/lib/rodauth_phlex/emails/otp_setup_email.rb +18 -0
  35. data/lib/rodauth_phlex/emails/otp_unlock_failed_email.rb +24 -0
  36. data/lib/rodauth_phlex/emails/otp_unlocked_email.rb +18 -0
  37. data/lib/rodauth_phlex/emails/password_changed_email.rb +18 -0
  38. data/lib/rodauth_phlex/emails/reset_password_email.rb +21 -0
  39. data/lib/rodauth_phlex/emails/reset_password_notify_email.rb +21 -0
  40. data/lib/rodauth_phlex/emails/unlock_account_email.rb +21 -0
  41. data/lib/rodauth_phlex/emails/verify_account_email.rb +20 -0
  42. data/lib/rodauth_phlex/emails/verify_login_change_email.rb +25 -0
  43. data/lib/rodauth_phlex/emails/webauthn_authenticator_added_email.rb +19 -0
  44. data/lib/rodauth_phlex/emails/webauthn_authenticator_removed_email.rb +19 -0
  45. data/lib/rodauth_phlex/emails.rb +22 -0
  46. data/lib/rodauth_phlex/feature.rb +71 -0
  47. data/lib/rodauth_phlex/version.rb +5 -0
  48. data/lib/rodauth_phlex/view.rb +17 -0
  49. data/lib/rodauth_phlex/views/change_password.rb +25 -0
  50. data/lib/rodauth_phlex/views/close_account.rb +20 -0
  51. data/lib/rodauth_phlex/views/confirm_password.rb +20 -0
  52. data/lib/rodauth_phlex/views/create_account.rb +23 -0
  53. data/lib/rodauth_phlex/views/email_auth.rb +19 -0
  54. data/lib/rodauth_phlex/views/login.rb +17 -0
  55. data/lib/rodauth_phlex/views/logout.rb +19 -0
  56. data/lib/rodauth_phlex/views/multi_phase_login.rb +17 -0
  57. data/lib/rodauth_phlex/views/otp_auth.rb +21 -0
  58. data/lib/rodauth_phlex/views/otp_disable.rb +20 -0
  59. data/lib/rodauth_phlex/views/otp_setup.rb +39 -0
  60. data/lib/rodauth_phlex/views/otp_unlock.rb +24 -0
  61. data/lib/rodauth_phlex/views/otp_unlock_not_available.rb +23 -0
  62. data/lib/rodauth_phlex/views/recovery_auth.rb +23 -0
  63. data/lib/rodauth_phlex/views/remember.rb +33 -0
  64. data/lib/rodauth_phlex/views/reset_password.rb +21 -0
  65. data/lib/rodauth_phlex/views/reset_password_request.rb +25 -0
  66. data/lib/rodauth_phlex/views/sms_auth.rb +20 -0
  67. data/lib/rodauth_phlex/views/sms_confirm.rb +20 -0
  68. data/lib/rodauth_phlex/views/sms_disable.rb +20 -0
  69. data/lib/rodauth_phlex/views/sms_request.rb +19 -0
  70. data/lib/rodauth_phlex/views/sms_setup.rb +30 -0
  71. data/lib/rodauth_phlex/views/two_factor_auth.rb +19 -0
  72. data/lib/rodauth_phlex/views/two_factor_disable.rb +20 -0
  73. data/lib/rodauth_phlex/views/two_factor_manage.rb +28 -0
  74. data/lib/rodauth_phlex/views/unlock_account.rb +21 -0
  75. data/lib/rodauth_phlex/views/unlock_account_request.rb +21 -0
  76. data/lib/rodauth_phlex/views/verify_account.rb +21 -0
  77. data/lib/rodauth_phlex/views/verify_account_resend.rb +25 -0
  78. data/lib/rodauth_phlex/views/verify_login_change.rb +19 -0
  79. data/lib/rodauth_phlex/views/webauthn_auth.rb +27 -0
  80. data/lib/rodauth_phlex/views/webauthn_remove.rb +33 -0
  81. data/lib/rodauth_phlex/views/webauthn_setup.rb +28 -0
  82. data/lib/rodauth_phlex/views.rb +39 -0
  83. data/lib/rodauth_phlex.rb +13 -0
  84. metadata +162 -0
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Components
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/password-confirm-field.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class PasswordConfirmField < RodauthPhlex::Component
11
+ def view_template
12
+ div(class: "form-group mb-3") do
13
+ label(for: "password-confirm", class: "form-label") { "#{rodauth.password_confirm_label}#{rodauth.input_field_label_suffix}" }
14
+ InputField(rodauth, rodauth.password_confirm_param, "password-confirm", type: "password", autocomplete: "new-password")
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Components
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/password-field.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class PasswordField < RodauthPhlex::Component
11
+ def view_template
12
+ div(class: "form-group mb-3") do
13
+ label(for: "password", class: "form-label") { "#{rodauth.password_label}#{rodauth.input_field_label_suffix}" }
14
+ InputField(rodauth, rodauth.password_param, "password", type: "password", autocomplete: rodauth.password_field_autocomplete_value)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Components
4
+ class RecoveryCodes < RodauthPhlex::Component
5
+ # This is a Phlex version of the Rodauth template:
6
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/recovery-codes.str
7
+ #
8
+ # Copyright (c) 2024 Robert Schulze
9
+ # Copyright (c) 2015-2023 Jeremy Evans
10
+ # MIT License
11
+ def view_template
12
+ form(method: "post", class: "rodauth", role: "form", id: "recovery-codes-form") do
13
+ safe_html rodauth.recovery_codes_additional_form_tags
14
+ safe_html rodauth.csrf_tag
15
+ PasswordField(rodauth) if rodauth.two_factor_modifications_require_password?
16
+ Button(
17
+ rodauth,
18
+ rodauth.recovery_codes_button || rodauth.view_recovery_codes_button,
19
+ name: (rodauth.add_recovery_codes_param if rodauth.recovery_codes_button)
20
+ )
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Components
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/sms-code-field.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class SmsCodeField < RodauthPhlex::Component
11
+ def view_template
12
+ div(class: "form-group mb-3") do
13
+ label(for: "sms-code", class: "form-label") { "#{rodauth.sms_code_label}#{rodauth.input_field_label_suffix}" }
14
+ div(class: "row") do
15
+ div(class: "col-sm-3") do
16
+ InputField(rodauth, rodauth.sms_code_param, "sms-code", value: "", autocomplete: "one-time-code", inputmode: "numeric")
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Components
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/webauthn-autofill.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class WebauthnAutofill < RodauthPhlex::Component
11
+ def view_template
12
+ cred = rodauth.webauthn_credential_options_for_get
13
+
14
+ form(method: "post", action: rodauth.webauthn_login_path, class: "rodauth", role: "form", id: "webauthn-login-form", "data-credential-options": cred.as_json.to_json) do
15
+ safe_html rodauth.webauthn_auth_additional_form_tags
16
+ safe_html rodauth.csrf_tag(rodauth.webauthn_login_path)
17
+ input(type: "hidden", name: rodauth.webauthn_auth_challenge_param, value: cred.challenge)
18
+ input(type: "hidden", name: rodauth.webauthn_auth_challenge_hmac_param, value: rodauth.compute_hmac(cred.challenge))
19
+ input(class: "rodauth_hidden d-none", "aria-hidden": "true", type: "text", name: rodauth.webauthn_auth_param, id: "webauthn-auth", value: "")
20
+ Button(rodauth, rodauth.webauthn_auth_button, class: "d-none")
21
+ end
22
+
23
+ script(src: "#{rodauth.webauthn_js_host}#{rodauth.webauthn_autofill_js_path}")
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ module RodauthPhlex
2
+ autoload :Component, "rodauth_phlex/component"
3
+
4
+ module Components
5
+ extend Phlex::Kit
6
+
7
+ autoload :AddRecoveryCodes, "rodauth_phlex/components/add_recovery_codes"
8
+ autoload :Button, "rodauth_phlex/components/button"
9
+ autoload :ChangeLogin, "rodauth_phlex/components/change_login"
10
+ autoload :EmailAuthRequestForm, "rodauth_phlex/components/email_auth_request_form"
11
+ autoload :FormattedFieldError, "rodauth_phlex/components/formatted_field_error"
12
+ autoload :GlobalLogoutField, "rodauth_phlex/components/global_logout_field"
13
+ autoload :InputField, "rodauth_phlex/components/input_field"
14
+ autoload :LoginConfirmField, "rodauth_phlex/components/login_confirm_field"
15
+ autoload :LoginDisplay, "rodauth_phlex/components/login_display"
16
+ autoload :LoginField, "rodauth_phlex/components/login_field"
17
+ autoload :LoginForm, "rodauth_phlex/components/login_form"
18
+ autoload :LoginFormFooter, "rodauth_phlex/components/login_form_footer"
19
+ autoload :LoginHiddenField, "rodauth_phlex/components/login_hidden_field"
20
+ autoload :OtpAuthCodeField, "rodauth_phlex/components/otp_auth_code_field"
21
+ autoload :PasswordConfirmField, "rodauth_phlex/components/password_confirm_field"
22
+ autoload :PasswordField, "rodauth_phlex/components/password_field"
23
+ autoload :RecoveryCodes, "rodauth_phlex/components/recovery_codes"
24
+ autoload :SmsCodeField, "rodauth_phlex/components/sms_code_field"
25
+ autoload :WebauthnAutofill, "rodauth_phlex/components/webauthn_autofill"
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex
4
+ class Email < Phlex::SGML # TODO: change to "Phlex::Plain" when available
5
+ include RodauthPhlex::Components
6
+
7
+ def initialize(rodauth)
8
+ @rodauth = rodauth
9
+ end
10
+ attr_reader :rodauth
11
+
12
+ LF = "\n"
13
+ CRLF = "\r\n"
14
+
15
+ def lines(*str, ending: LF)
16
+ raw(safe(str.join(ending)))
17
+ end
18
+
19
+ def line(*str, seperator: " ")
20
+ raw(safe(str.join(seperator)))
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Emails
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/email-auth-email.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class EmailAuthEmail < RodauthPhlex::Email
11
+ def body
12
+ lines(
13
+ "Someone has requested a login link for the account with this email",
14
+ "address. If you did not request a login link, please ignore this",
15
+ "message. If you requested a login link, please go to",
16
+ rodauth.email_auth_email_link,
17
+ "to login to this account."
18
+ )
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Emails
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/otp-disabled-email.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class OtpDisabledEmail < RodauthPhlex::Email
11
+ def body
12
+ lines(
13
+ "Someone (hopefully you) has disabled TOTP authentication for the account",
14
+ "associated to this email address."
15
+ )
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Emails
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/otp-locked-out-email.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class OtpLockedOutEmail < RodauthPhlex::Email
11
+ def view_template
12
+ lines(
13
+ "TOTP authentication has been locked out on your account due to too many",
14
+ "consecutive authentication failures. You can attempt to unlock TOTP",
15
+ "authentication for your account by consecutively authenticating via",
16
+ "TOTP multiple times.",
17
+ "",
18
+ "If you did not initiate the TOTP authentication failures that",
19
+ "caused TOTP authentication to be locked out, that means someone already",
20
+ "has partial access to your account, but is unable to use TOTP",
21
+ "authentication to fully authenticate themselves."
22
+ )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Emails
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/otp-setup-email.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class OtpSetupEmail < RodauthPhlex::Email
11
+ def view_template
12
+ lines(
13
+ "Someone (hopefully you) has setup TOTP authentication for the account",
14
+ "associated to this email address."
15
+ )
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Emails
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/otp-unlock-failed-email.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class OtpSetupEmail < RodauthPhlex::Email
11
+ def view_template
12
+ lines(
13
+ "Someone (hopefully you) attempted to unlock TOTP authentication for the",
14
+ "account associated to this email address, but failed as the",
15
+ "authentication code submitted was not correct.",
16
+ "",
17
+ "If you did not initiate the TOTP authentication failure that generated",
18
+ "this email, that means someone already has partial access to your",
19
+ "account, but is unable to use TOTP authentication to fully authenticate",
20
+ "themselves."
21
+ )
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Emails
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/otp-unlocked-email.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class OtpUnlockedEmail < RodauthPhlex::Email
11
+ def view_template
12
+ lines(
13
+ "Someone (hopefully you) has reset the password for the account",
14
+ "associated to this email address."
15
+ )
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Emails
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/password-changed-email.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class PasswordChangedEmail < RodauthPhlex::Email
11
+ def body
12
+ lines(
13
+ "Someone (hopefully you) has changed the password for the account",
14
+ "associated to this email address."
15
+ )
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Emails
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/reset-password-email.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class ResetPasswordEmail < RodauthPhlex::Email
11
+ def body
12
+ lines(
13
+ "Someone has requested a password reset for the account with this email",
14
+ "address. If you did not request a password reset, please ignore this",
15
+ "message. If you requested a password reset, please go to",
16
+ rodauth.reset_password_email_link,
17
+ "to reset the password for the account."
18
+ )
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Emails
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/reset-password-notify-email.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class ResetPasswordNotifyEmail < RodauthPhlex::Email
11
+ def view_template
12
+ lines(
13
+ "Someone has requested that the account with this email be unlocked.",
14
+ "If you did not request the unlocking of this account, please ignore this",
15
+ "message. If you requested the unlocking of this account, please go to",
16
+ rodauth.unlock_account_email_link,
17
+ "to unlock this account."
18
+ )
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Emails
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/unlock-account-email.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class UnlockAccountEmail < RodauthPhlex::Email
11
+ def view_template
12
+ lines(
13
+ "Someone has requested that the account with this email be unlocked.",
14
+ "If you did not request the unlocking of this account, please ignore this",
15
+ "message. If you requested the unlocking of this account, please go to",
16
+ rodauth.unlock_account_email_link,
17
+ "to unlock this account."
18
+ )
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Emails
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/verify-account-email.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class VerifyAccountEmail < RodauthPhlex::Email
11
+ def view_template
12
+ lines(
13
+ "Someone has created an account with this email address. If you did not create",
14
+ "this account, please ignore this message. If you created this account, please go to",
15
+ rodauth.verify_account_email_link,
16
+ "to verify the account."
17
+ )
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Emails
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/verify-login-change-email.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class VerifyLoginChangeEmail < RodauthPhlex::Email
11
+ def view_template
12
+ lines(
13
+ "Someone with an account has requested their login be changed to this email address:",
14
+ "",
15
+ "Old Login: #{rodauth.verify_login_change_old_login}",
16
+ "New Login: #{rodauth.verify_login_change_new_login}",
17
+ "",
18
+ "If you did not request this login change, please ignore this message. If you",
19
+ "requested this login change, please go to",
20
+ rodauth.verify_login_change_email_link,
21
+ "to verify the login change."
22
+ )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Emails
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/webauthn-authenticator-added-email.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class WebauthnAuthenticatorAddedEmail < RodauthPhlex::Email
11
+ def view_template
12
+ lines(
13
+ "Someone (hopefully you) has added a WebAuthn authenticator to the",
14
+ "account associated to this email address. There are now #{rodauth.account_webauthn_ids.length} WebAuthn",
15
+ "authenticator(s) with access to the account."
16
+ )
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Emails
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/webauthn-authenticator-removed-email.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class WebauthnAuthenticatorRemovedEmail < RodauthPhlex::Email
11
+ def view_template
12
+ lines(
13
+ "Someone (hopefully you) has removed a WebAuthn authenticator from the",
14
+ "account associated to this email address. There are now #{rodauth.account_webauthn_ids.length} WebAuthn",
15
+ "authenticator(s) with access to the account."
16
+ )
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex
4
+ autoload :Email, "rodauth_phlex/email"
5
+
6
+ module Emails
7
+ autoload :EmailAuthEmail, "rodauth_phlex/emails/email_auth_email"
8
+ autoload :OtpDisabledEmail, "rodauth_phlex/emails/otp_disabled_email"
9
+ autoload :OtpLockedOutEmail, "rodauth_phlex/emails/otp_locked_out_email"
10
+ autoload :OtpSetupEmail, "rodauth_phlex/emails/otp_setup_email"
11
+ autoload :OtpUnlockFailedEmail, "rodauth_phlex/emails/otp_unlock_failed_email"
12
+ autoload :OtpUnlockedEmail, "rodauth_phlex/emails/otp_unlocked_email"
13
+ autoload :PasswordChangedEmail, "rodauth_phlex/emails/password_changed_email"
14
+ autoload :ResetPasswordEmail, "rodauth_phlex/emails/reset_password_email"
15
+ autoload :ResetPasswordNotifyEmail, "rodauth_phlex/emails/reset_password_notify_email"
16
+ autoload :UnlockAccountEmail, "rodauth_phlex/emails/unlock_account_email"
17
+ autoload :VerifyAccountEmail, "rodauth_phlex/emails/verify_account_email"
18
+ autoload :VerifyLoginChangeEmail, "rodauth_phlex/emails/verify_login_change_email"
19
+ autoload :WebauthnAuthenticatorAddedEmail, "rodauth_phlex/emails/webauthn_authenticator_added_email"
20
+ autoload :WebauthnAuthenticatorRemovedEmail, "rodauth_phlex/emails/webauthn_authenticator_removed_email"
21
+ end
22
+ end
@@ -0,0 +1,71 @@
1
+ module Rodauth
2
+ Feature.define(:phlex, :RodauthPhlex) do
3
+ auth_value_method :phlex_views_namespace, "RodauthPhlex::Views"
4
+ auth_value_method :phlex_components_namespace, "RodauthPhlex::Components"
5
+ auth_value_method :phlex_emails_namespace, "RodauthPhlex::Emails"
6
+
7
+ auth_value_method :phlex_layout_class, RodauthPhlex::Undefined
8
+ auth_value_method :phlex_layout_title_key, :title
9
+ auth_methods(
10
+ :phlex_set_page_title,
11
+ :phlex_classify_page
12
+ )
13
+
14
+ # render a view
15
+ def view(page, title)
16
+ if (layout = phlex_layout_class) != RodauthPhlex::Undefined
17
+ scope.phlex_layout(layout)
18
+ end
19
+ scope.phlex_layout_opts(phlex_set_page_title(title, scope.phlex_layout_opts))
20
+ scope.phlex(phlex_view(page, :view))
21
+ end
22
+
23
+ # Render a component.
24
+ # Falls back to rendering a view if the component is not defined
25
+ def render(page)
26
+ scope.phlex_layout(false)
27
+
28
+ orig_error = nil
29
+ mode = :render
30
+ phlex_view =
31
+ begin
32
+ self.phlex_view(page, mode)
33
+ rescue NameError => e
34
+ raise orig_error if orig_error
35
+
36
+ orig_error = e
37
+ mode = :view
38
+ retry
39
+ end
40
+
41
+ warn "The page #{page} is not defined in the #{phlex_components_namespace} namespace. Using #{phlex_view} as fallback. Please create a component for it." if mode == :view
42
+ scope.phlex(phlex_view)
43
+ end
44
+
45
+ private def phlex_view(page, mode)
46
+ klass = phlex_classify_page(page, mode)
47
+ klass.new(scope.rodauth)
48
+ end
49
+
50
+ def phlex_set_page_title(title, opts)
51
+ key = phlex_layout_title_key
52
+
53
+ if opts
54
+ opts[key] = title if key
55
+ opts
56
+ else
57
+ key ? {key => title} : {}
58
+ end
59
+ end
60
+
61
+ def phlex_classify_page(page_name, mode)
62
+ klass_name = page_name.split(/(?:_|-)/).map(&:capitalize).join
63
+ mod_name = if page_name.end_with?("-email")
64
+ phlex_emails_namespace
65
+ else
66
+ (mode == :render) ? phlex_components_namespace : phlex_views_namespace
67
+ end
68
+ Object.const_get("#{mod_name}::#{klass_name}")
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex
4
+ VERSION = "0.1.0.pre1"
5
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex
4
+ class View < Phlex::HTML
5
+ include RodauthPhlex::Components
6
+
7
+ def initialize(rodauth)
8
+ @rodauth = rodauth
9
+ end
10
+ attr_reader :rodauth
11
+
12
+ # only to be used for rodauth html helper method output
13
+ def safe_html(str)
14
+ raw(safe(str)) if str
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Views
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/change-password.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class ChangePassword < RodauthPhlex::View
11
+ def view_template
12
+ form(method: "post", class: "rodauth", role: "form", id: "change-password-form") do
13
+ safe_html rodauth.change_password_additional_form_tags
14
+ safe_html rodauth.csrf_tag
15
+ PasswordField(rodauth) if rodauth.change_password_requires_password?
16
+ div(class: "form-group mb-3") do
17
+ label(for: "new-password", class: "form-label") { "#{rodauth.new_password_label}#{rodauth.input_field_label_suffix}" }
18
+ InputField(rodauth, rodauth.new_password_param, "new-password", type: "password", autocomplete: "new-password")
19
+ end
20
+ PasswordConfirmField(rodauth) if rodauth.require_password_confirmation?
21
+ Button(rodauth, rodauth.change_password_button)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RodauthPhlex::Views
4
+ # This is a Phlex version of the Rodauth template:
5
+ # https://github.com/jeremyevans/rodauth/blob/2.37.0/templates/close-account.str
6
+ #
7
+ # Copyright (c) 2024 Robert Schulze
8
+ # Copyright (c) 2015-2023 Jeremy Evans
9
+ # MIT License
10
+ class CloseAccount < RodauthPhlex::View
11
+ def view_template
12
+ form(method: "post", class: "rodauth", role: "form", id: "close-account-form") do
13
+ safe_html rodauth.close_account_additional_form_tags
14
+ safe_html rodauth.csrf_tag
15
+ PasswordField(rodauth) if rodauth.close_account_requires_password?
16
+ Button(rodauth, rodauth.close_account_button, class: "btn btn-danger")
17
+ end
18
+ end
19
+ end
20
+ end