nitro_kit 2.0.0.beta.3 → 2.0.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +37 -0
- data/LICENSE +21 -28
- data/README.md +10 -9
- data/app/assets/stylesheets/nitro_kit.css +1660 -1401
- data/app/components/nitro_kit/accordion.rb +1 -13
- data/app/components/nitro_kit/app_navigation.rb +0 -12
- data/app/components/nitro_kit/app_shell.rb +5 -11
- data/app/components/nitro_kit/appearance_picker.rb +1 -7
- data/app/components/nitro_kit/combobox.rb +366 -21
- data/app/components/nitro_kit/command_palette.rb +7 -20
- data/app/components/nitro_kit/details_table.rb +5 -11
- data/app/components/nitro_kit/dropzone.rb +3 -15
- data/app/components/nitro_kit/field.rb +20 -2
- data/app/components/nitro_kit/pagination.rb +2 -8
- data/app/components/nitro_kit/settings_layout.rb +3 -9
- data/app/javascript/controllers/nk/app_shell_controller.js +2 -2
- data/app/javascript/controllers/nk/combobox_controller.js +308 -22
- data/app/javascript/controllers/nk/combobox_remote.js +70 -0
- data/app/javascript/controllers/nk/dropzone_controller.js +2 -2
- data/app/javascript/controllers/nk/tabs_controller.js +2 -2
- data/config/locales/en.yml +3 -0
- data/docs/agent_guide.md +43 -13
- data/docs/component_contracts.md +90 -61
- data/docs/customization.md +173 -35
- data/docs/initialization_prompt.md +4 -5
- data/docs/migration_1_to_2.md +10 -8
- data/docs/patterns/application_foundation.md +5 -0
- data/docs/patterns/composition.md +61 -0
- data/docs/patterns/crud_resource.md +5 -0
- data/docs/patterns/inset_workspace.md +21 -22
- data/docs/patterns/resource_form.md +65 -0
- data/docs/rails_integration.md +214 -2
- data/lib/generators/nitro_kit/install_generator.rb +5 -4
- data/lib/nitro_kit/installation.rb +327 -68
- data/lib/nitro_kit/migration_inventory.rb +18 -3
- data/lib/nitro_kit/version.rb +1 -1
- data/lib/rails/commands/nitro_kit/nitro_kit_command.rb +2 -2
- data/patterns/README.md +21 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/account_deletion.rb +72 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/base.rb +44 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/page.rb +57 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/preferences.rb +68 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/profile.rb +86 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/security.rb +69 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/sessions.rb +86 -0
- data/patterns/account-settings/files/app/controllers/settings/account_deletions_controller.rb +35 -0
- data/patterns/account-settings/files/app/controllers/settings/base_controller.rb +12 -0
- data/patterns/account-settings/files/app/controllers/settings/other_sessions_controller.rb +8 -0
- data/patterns/account-settings/files/app/controllers/settings/preferences_controller.rb +27 -0
- data/patterns/account-settings/files/app/controllers/settings/profiles_controller.rb +20 -0
- data/patterns/account-settings/files/app/controllers/settings/securities_controller.rb +37 -0
- data/patterns/account-settings/files/app/controllers/settings/sessions_controller.rb +31 -0
- data/patterns/account-settings/files/app/models/account_settings/account_closure.rb +33 -0
- data/patterns/account-settings/files/app/models/account_settings/password_change.rb +42 -0
- data/patterns/account-settings/files/app/models/account_settings/session_summary.rb +45 -0
- data/patterns/account-settings/files/app/models/concerns/user/account_configurable.rb +18 -0
- data/patterns/account-settings/files/config/routes/account_settings.rb +10 -0
- data/patterns/account-settings/files/db/migrate/20260731020000_add_account_settings.rb +27 -0
- data/patterns/account-settings/files/test/controllers/settings/account_settings_flow_test.rb +84 -0
- data/patterns/account-settings/files/test/models/account_settings/password_change_test.rb +40 -0
- data/patterns/account-settings/files/test/system/account_settings_test.rb +52 -0
- data/patterns/account-settings/item.yml +4 -0
- data/patterns/account-settings/pattern.md +44 -0
- data/patterns/application-shell/files/app/assets/stylesheets/ui/application_shell.css +267 -0
- data/patterns/application-shell/files/app/components/ui/application_shell.rb +184 -0
- data/patterns/application-shell/item.yml +4 -0
- data/patterns/application-shell/pattern.md +110 -0
- data/patterns/authentication/files/app/components/ui/authentication/base.rb +11 -0
- data/patterns/authentication/files/app/components/ui/authentication/page.rb +53 -0
- data/patterns/authentication/files/app/components/ui/email_verifications/show.rb +62 -0
- data/patterns/authentication/files/app/components/ui/password_resets/new.rb +65 -0
- data/patterns/authentication/files/app/components/ui/passwords/edit.rb +72 -0
- data/patterns/authentication/files/app/components/ui/sessions/new.rb +58 -0
- data/patterns/authentication/files/app/components/ui/verification_emails/new.rb +59 -0
- data/patterns/authentication/files/app/controllers/concerns/authentication.rb +66 -0
- data/patterns/authentication/files/app/controllers/concerns/safe_return_navigation.rb +37 -0
- data/patterns/authentication/files/app/controllers/email_verifications_controller.rb +39 -0
- data/patterns/authentication/files/app/controllers/password_resets_controller.rb +33 -0
- data/patterns/authentication/files/app/controllers/passwords_controller.rb +51 -0
- data/patterns/authentication/files/app/controllers/sessions_controller.rb +42 -0
- data/patterns/authentication/files/app/controllers/verification_emails_controller.rb +33 -0
- data/patterns/authentication/files/app/jobs/authentication_delivery_job.rb +17 -0
- data/patterns/authentication/files/app/mailers/authentication_mailer.rb +15 -0
- data/patterns/authentication/files/app/models/authentication/credentials.rb +16 -0
- data/patterns/authentication/files/app/models/authentication/email_request.rb +17 -0
- data/patterns/authentication/files/app/models/concerns/user/email_verifiable.rb +40 -0
- data/patterns/authentication/files/app/models/session.rb +5 -0
- data/patterns/authentication/files/app/views/authentication_mailer/email_verification.html.erb +3 -0
- data/patterns/authentication/files/app/views/authentication_mailer/email_verification.text.erb +5 -0
- data/patterns/authentication/files/app/views/authentication_mailer/password_reset.html.erb +3 -0
- data/patterns/authentication/files/app/views/authentication_mailer/password_reset.text.erb +5 -0
- data/patterns/authentication/files/config/routes/authentication.rb +11 -0
- data/patterns/authentication/files/db/migrate/20260731000000_add_authentication_and_recovery.rb +13 -0
- data/patterns/authentication/files/test/controllers/authentication_flow_test.rb +103 -0
- data/patterns/authentication/files/test/controllers/safe_return_navigation_test.rb +18 -0
- data/patterns/authentication/files/test/mailers/authentication_mailer_test.rb +21 -0
- data/patterns/authentication/files/test/models/user_email_verifiable_test.rb +36 -0
- data/patterns/authentication/files/test/system/authentication_flow_test.rb +23 -0
- data/patterns/authentication/item.yml +12 -0
- data/patterns/authentication/pattern.md +54 -0
- data/patterns/crud-resource/files/app/assets/stylesheets/ui/projects.css +4 -0
- data/patterns/crud-resource/files/app/components/ui/projects/form.rb +89 -0
- data/patterns/crud-resource/files/app/components/ui/projects/index.rb +161 -0
- data/patterns/crud-resource/files/app/components/ui/projects/show.rb +84 -0
- data/patterns/crud-resource/files/app/controllers/projects/archivals_controller.rb +23 -0
- data/patterns/crud-resource/files/app/controllers/projects_controller.rb +70 -0
- data/patterns/crud-resource/files/app/models/project/archival.rb +8 -0
- data/patterns/crud-resource/files/app/models/project/event.rb +12 -0
- data/patterns/crud-resource/files/app/models/project/filter.rb +41 -0
- data/patterns/crud-resource/files/app/models/project.rb +41 -0
- data/patterns/crud-resource/files/app/views/projects/edit.html.erb +19 -0
- data/patterns/crud-resource/files/app/views/projects/index.html.erb +18 -0
- data/patterns/crud-resource/files/app/views/projects/new.html.erb +16 -0
- data/patterns/crud-resource/files/app/views/projects/show.html.erb +28 -0
- data/patterns/crud-resource/files/config/routes/crud_resource.rb +7 -0
- data/patterns/crud-resource/files/db/migrate/20260720000000_create_crud_resource.rb +37 -0
- data/patterns/crud-resource/files/test/controllers/projects_controller_test.rb +64 -0
- data/patterns/crud-resource/files/test/models/project_test.rb +34 -0
- data/patterns/crud-resource/files/test/support/crud_resource_test_helpers.rb +25 -0
- data/patterns/crud-resource/files/test/system/projects_crud_test.rb +87 -0
- data/patterns/crud-resource/item.yml +6 -0
- data/patterns/crud-resource/pattern.md +48 -0
- data/patterns/file-uploads/files/app/assets/stylesheets/ui/uploads.css +133 -0
- data/patterns/file-uploads/files/app/components/ui/uploads/base.rb +30 -0
- data/patterns/file-uploads/files/app/components/ui/uploads/index.rb +188 -0
- data/patterns/file-uploads/files/app/components/ui/uploads/page.rb +33 -0
- data/patterns/file-uploads/files/app/controllers/uploads/base_controller.rb +29 -0
- data/patterns/file-uploads/files/app/controllers/uploads/direct_uploads_controller.rb +55 -0
- data/patterns/file-uploads/files/app/controllers/uploads/retries_controller.rb +14 -0
- data/patterns/file-uploads/files/app/controllers/uploads_controller.rb +40 -0
- data/patterns/file-uploads/files/app/jobs/upload_blob_cleanup_job.rb +9 -0
- data/patterns/file-uploads/files/app/jobs/upload_processing_job.rb +10 -0
- data/patterns/file-uploads/files/app/jobs/upload_repair_job.rb +17 -0
- data/patterns/file-uploads/files/app/models/concerns/team/uploadable.rb +9 -0
- data/patterns/file-uploads/files/app/models/upload.rb +295 -0
- data/patterns/file-uploads/files/config/recurring/uploads.yml +7 -0
- data/patterns/file-uploads/files/config/routes/uploads.rb +5 -0
- data/patterns/file-uploads/files/db/migrate/20260802000000_add_file_uploads.rb +30 -0
- data/patterns/file-uploads/files/test/controllers/uploads_flow_test.rb +77 -0
- data/patterns/file-uploads/files/test/fixtures/files/workspace.png.base64 +1 -0
- data/patterns/file-uploads/files/test/fixtures/uploads.yml +17 -0
- data/patterns/file-uploads/files/test/models/upload_test.rb +55 -0
- data/patterns/file-uploads/files/test/system/file_uploads_test.rb +30 -0
- data/patterns/file-uploads/item.yml +4 -0
- data/patterns/file-uploads/pattern.md +71 -0
- data/patterns/nitro-kit-1-upgrade/files/docs/nitro_kit_1_upgrade.md +57 -0
- data/patterns/nitro-kit-1-upgrade/item.yml +4 -0
- data/patterns/nitro-kit-1-upgrade/pattern.md +30 -0
- data/patterns/onboarding/files/app/assets/stylesheets/ui/onboarding.css +55 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/base.rb +11 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/branch_form.rb +36 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/details_form.rb +67 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/invitation_plan_form.rb +48 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/page.rb +75 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/review.rb +51 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/show.rb +32 -0
- data/patterns/onboarding/files/app/controllers/concerns/requires_finished_onboarding.rb +14 -0
- data/patterns/onboarding/files/app/controllers/onboarding/base_controller.rb +30 -0
- data/patterns/onboarding/files/app/controllers/onboarding/branches_controller.rb +16 -0
- data/patterns/onboarding/files/app/controllers/onboarding/completions_controller.rb +13 -0
- data/patterns/onboarding/files/app/controllers/onboarding/details_controller.rb +16 -0
- data/patterns/onboarding/files/app/controllers/onboarding/invitation_plans_controller.rb +20 -0
- data/patterns/onboarding/files/app/controllers/onboardings_controller.rb +7 -0
- data/patterns/onboarding/files/app/jobs/onboarding_invitation_delivery_job.rb +15 -0
- data/patterns/onboarding/files/app/models/concerns/team/onboardable.rb +23 -0
- data/patterns/onboarding/files/app/models/onboarding/completion.rb +17 -0
- data/patterns/onboarding/files/app/models/onboarding/invitation_delivery.rb +14 -0
- data/patterns/onboarding/files/app/models/onboarding.rb +174 -0
- data/patterns/onboarding/files/config/routes/onboarding.rb +11 -0
- data/patterns/onboarding/files/db/migrate/20260731010000_create_onboarding.rb +60 -0
- data/patterns/onboarding/files/test/controllers/onboarding_flow_test.rb +62 -0
- data/patterns/onboarding/files/test/fixtures/onboarding_completions.yml +3 -0
- data/patterns/onboarding/files/test/fixtures/onboardings.yml +25 -0
- data/patterns/onboarding/files/test/jobs/onboarding_invitation_delivery_job_test.rb +18 -0
- data/patterns/onboarding/files/test/models/onboarding_test.rb +60 -0
- data/patterns/onboarding/files/test/system/onboarding_flow_test.rb +39 -0
- data/patterns/onboarding/item.yml +4 -0
- data/patterns/onboarding/pattern.md +53 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/base.rb +39 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/checkout_result.rb +64 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/page.rb +33 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/show.rb +149 -0
- data/patterns/subscription-billing/files/app/controllers/billing/base_controller.rb +16 -0
- data/patterns/subscription-billing/files/app/controllers/billing/checkouts_controller.rb +65 -0
- data/patterns/subscription-billing/files/app/controllers/billing/portals_controller.rb +18 -0
- data/patterns/subscription-billing/files/app/controllers/billing_controller.rb +17 -0
- data/patterns/subscription-billing/files/app/controllers/webhooks/stripe_events_controller.rb +21 -0
- data/patterns/subscription-billing/files/app/jobs/billing/stripe_event_job.rb +16 -0
- data/patterns/subscription-billing/files/app/jobs/billing/subscription_reconciliation_job.rb +16 -0
- data/patterns/subscription-billing/files/app/jobs/billing/subscription_reconciliation_sweep_job.rb +9 -0
- data/patterns/subscription-billing/files/app/models/billing/checkout.rb +58 -0
- data/patterns/subscription-billing/files/app/models/billing/plan.rb +19 -0
- data/patterns/subscription-billing/files/app/models/billing/stripe_event.rb +73 -0
- data/patterns/subscription-billing/files/app/models/billing/subscription.rb +106 -0
- data/patterns/subscription-billing/files/app/models/concerns/team/billable.rb +36 -0
- data/patterns/subscription-billing/files/config/initializers/stripe.rb +29 -0
- data/patterns/subscription-billing/files/config/routes/subscription_billing.rb +10 -0
- data/patterns/subscription-billing/files/db/migrate/20260801000000_add_subscription_billing.rb +61 -0
- data/patterns/subscription-billing/files/test/controllers/billing_flow_test.rb +60 -0
- data/patterns/subscription-billing/files/test/models/billing/subscription_test.rb +40 -0
- data/patterns/subscription-billing/files/test/system/subscription_billing_test.rb +28 -0
- data/patterns/subscription-billing/item.yml +4 -0
- data/patterns/subscription-billing/pattern.md +59 -0
- data/patterns/team-management/files/app/components/ui/invitations/acceptance.rb +33 -0
- data/patterns/team-management/files/app/components/ui/teams/index.rb +87 -0
- data/patterns/team-management/files/app/components/ui/teams/invitation_form.rb +51 -0
- data/patterns/team-management/files/app/components/ui/teams/member_form.rb +78 -0
- data/patterns/team-management/files/app/components/ui/teams/members.rb +125 -0
- data/patterns/team-management/files/app/controllers/invitations/acceptances_controller.rb +29 -0
- data/patterns/team-management/files/app/controllers/teams/base_controller.rb +18 -0
- data/patterns/team-management/files/app/controllers/teams/invitations_controller.rb +42 -0
- data/patterns/team-management/files/app/controllers/teams/memberships_controller.rb +53 -0
- data/patterns/team-management/files/app/controllers/teams_controller.rb +30 -0
- data/patterns/team-management/files/app/mailers/team_invitation_mailer.rb +10 -0
- data/patterns/team-management/files/app/models/concerns/current_team.rb +13 -0
- data/patterns/team-management/files/app/models/concerns/user_teams.rb +37 -0
- data/patterns/team-management/files/app/models/invitation.rb +41 -0
- data/patterns/team-management/files/app/models/membership.rb +45 -0
- data/patterns/team-management/files/app/models/team.rb +25 -0
- data/patterns/team-management/files/app/views/invitations/acceptances/show.html.erb +1 -0
- data/patterns/team-management/files/app/views/team_invitation_mailer/invite.html.erb +10 -0
- data/patterns/team-management/files/app/views/team_invitation_mailer/invite.text.erb +7 -0
- data/patterns/team-management/files/app/views/teams/index.html.erb +15 -0
- data/patterns/team-management/files/app/views/teams/invitations/new.html.erb +22 -0
- data/patterns/team-management/files/app/views/teams/memberships/edit.html.erb +22 -0
- data/patterns/team-management/files/app/views/teams/memberships/index.html.erb +20 -0
- data/patterns/team-management/files/config/routes/team_management.rb +11 -0
- data/patterns/team-management/files/db/migrate/20260717000000_create_team_management.rb +31 -0
- data/patterns/team-management/files/test/models/invitation_test.rb +28 -0
- data/patterns/team-management/files/test/models/membership_test.rb +29 -0
- data/patterns/team-management/files/test/models/team_test.rb +31 -0
- data/patterns/team-management/files/test/support/team_management_test_helpers.rb +22 -0
- data/patterns/team-management/item.yml +4 -0
- data/patterns/team-management/pattern.md +47 -0
- data/patterns/webhook-deliveries/files/app/assets/stylesheets/ui/webhooks.css +179 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/base.rb +38 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/delivery.rb +160 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/endpoint.rb +149 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/form.rb +75 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/index.rb +142 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/page.rb +33 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/secret.rb +38 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_deliveries/replays_controller.rb +13 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_deliveries_controller.rb +7 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_endpoints/secrets_controller.rb +41 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_endpoints_controller.rb +67 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhooks/base_controller.rb +15 -0
- data/patterns/webhook-deliveries/files/app/jobs/webhook_delivery_job.rb +9 -0
- data/patterns/webhook-deliveries/files/app/jobs/webhook_delivery_repair_job.rb +11 -0
- data/patterns/webhook-deliveries/files/app/models/concerns/team/webhookable.rb +11 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/attempt.rb +30 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/delivery.rb +268 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/endpoint.rb +58 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/event.rb +98 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/secret_reveal.rb +53 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/signature.rb +22 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/transport.rb +176 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_deliveries/show.html.erb +5 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/edit.html.erb +1 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/index.html.erb +6 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/new.html.erb +1 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/secrets/new.html.erb +1 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/show.html.erb +7 -0
- data/patterns/webhook-deliveries/files/config/recurring/webhooks.yml +4 -0
- data/patterns/webhook-deliveries/files/config/routes/webhook_deliveries.rb +10 -0
- data/patterns/webhook-deliveries/files/db/migrate/20260803000000_add_webhook_deliveries.rb +126 -0
- data/patterns/webhook-deliveries/files/test/controllers/webhook_endpoints_flow_test.rb +48 -0
- data/patterns/webhook-deliveries/files/test/models/webhook/delivery_test.rb +70 -0
- data/patterns/webhook-deliveries/files/test/system/webhook_deliveries_test.rb +29 -0
- data/patterns/webhook-deliveries/item.yml +4 -0
- data/patterns/webhook-deliveries/pattern.md +120 -0
- data/plugins/nitro-kit/.codex-plugin/plugin.json +4 -4
- data/plugins/nitro-kit/skills/nitro-kit-hotwire/SKILL.md +7 -9
- data/plugins/nitro-kit/skills/nitro-kit-hotwire/agents/openai.yaml +1 -1
- data/plugins/nitro-kit/skills/nitro-kit-rails/SKILL.md +10 -9
- data/plugins/nitro-kit/skills/nitro-kit-rails/agents/openai.yaml +1 -1
- data/plugins/nitro-kit/skills/nitro-kit-ui/SKILL.md +27 -16
- data/plugins/nitro-kit/skills/nitro-kit-ui/agents/openai.yaml +1 -1
- data/src/stylesheets/nitro_kit/components/accordion.css +40 -40
- data/src/stylesheets/nitro_kit/components/alert.css +7 -6
- data/src/stylesheets/nitro_kit/components/app_navigation.css +50 -41
- data/src/stylesheets/nitro_kit/components/app_shell.css +371 -280
- data/src/stylesheets/nitro_kit/components/appearance_picker.css +38 -38
- data/src/stylesheets/nitro_kit/components/avatar.css +3 -3
- data/src/stylesheets/nitro_kit/components/avatar_stack.css +18 -18
- data/src/stylesheets/nitro_kit/components/badge.css +5 -2
- data/src/stylesheets/nitro_kit/components/button.css +57 -49
- data/src/stylesheets/nitro_kit/components/button_group.css +14 -14
- data/src/stylesheets/nitro_kit/components/checkbox.css +24 -24
- data/src/stylesheets/nitro_kit/components/checkbox_group.css +13 -13
- data/src/stylesheets/nitro_kit/components/combobox.css +152 -25
- data/src/stylesheets/nitro_kit/components/command_palette.css +59 -59
- data/src/stylesheets/nitro_kit/components/control_group.css +71 -54
- data/src/stylesheets/nitro_kit/components/details_table.css +9 -9
- data/src/stylesheets/nitro_kit/components/dialog.css +8 -12
- data/src/stylesheets/nitro_kit/components/dropdown.css +22 -26
- data/src/stylesheets/nitro_kit/components/dropzone.css +97 -100
- data/src/stylesheets/nitro_kit/components/empty_state.css +1 -0
- data/src/stylesheets/nitro_kit/components/field.css +26 -30
- data/src/stylesheets/nitro_kit/components/fieldset.css +2 -2
- data/src/stylesheets/nitro_kit/components/input.css +6 -14
- data/src/stylesheets/nitro_kit/components/layout.css +165 -165
- data/src/stylesheets/nitro_kit/components/page_header.css +3 -3
- data/src/stylesheets/nitro_kit/components/pagination.css +66 -49
- data/src/stylesheets/nitro_kit/components/pagination_bar.css +6 -6
- data/src/stylesheets/nitro_kit/components/palette.css +24 -22
- data/src/stylesheets/nitro_kit/components/progressive_image.css +38 -41
- data/src/stylesheets/nitro_kit/components/radio_button.css +19 -19
- data/src/stylesheets/nitro_kit/components/radio_button_group.css +43 -43
- data/src/stylesheets/nitro_kit/components/rich_text_area.css +4 -4
- data/src/stylesheets/nitro_kit/components/select.css +2 -2
- data/src/stylesheets/nitro_kit/components/settings_layout.css +17 -18
- data/src/stylesheets/nitro_kit/components/settings_section.css +12 -12
- data/src/stylesheets/nitro_kit/components/sheet.css +10 -10
- data/src/stylesheets/nitro_kit/components/stat_grid.css +9 -9
- data/src/stylesheets/nitro_kit/components/switch.css +23 -23
- data/src/stylesheets/nitro_kit/components/table.css +27 -27
- data/src/stylesheets/nitro_kit/components/tabs.css +32 -34
- data/src/stylesheets/nitro_kit/components/toolbar.css +6 -6
- data/src/stylesheets/nitro_kit/components/tooltip.css +26 -28
- data/src/stylesheets/nitro_kit/layers.css +2 -1
- data/src/stylesheets/nitro_kit/reset.css +9 -9
- data/src/stylesheets/nitro_kit/tailwind.css +6 -2
- data/src/stylesheets/nitro_kit/tokens.css +18 -9
- metadata +238 -2
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Authentication
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
include SafeReturnNavigation
|
|
6
|
+
|
|
7
|
+
included do
|
|
8
|
+
before_action :require_authentication
|
|
9
|
+
helper_method :authenticated?
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class_methods do
|
|
13
|
+
def allow_unauthenticated_access(**options)
|
|
14
|
+
skip_before_action :require_authentication, **options
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
def authenticated?
|
|
20
|
+
resume_session.present?
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def require_authentication
|
|
24
|
+
resume_session || request_authentication
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def resume_session
|
|
28
|
+
Current.session ||= Session.find_by(id: cookies.signed[:session_id])
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def request_authentication
|
|
32
|
+
remember_return_destination
|
|
33
|
+
redirect_to new_session_path, alert: "Sign in to continue."
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def start_new_session_for(user)
|
|
37
|
+
destination = session.delete(:return_to_after_authenticating)
|
|
38
|
+
reset_session
|
|
39
|
+
session[:return_to_after_authenticating] = destination if destination
|
|
40
|
+
|
|
41
|
+
user.sessions.create!(user_agent: request.user_agent, ip_address: request.remote_ip).tap do |record|
|
|
42
|
+
Current.session = record
|
|
43
|
+
cookies.signed.permanent[:session_id] = {
|
|
44
|
+
value: record.id,
|
|
45
|
+
httponly: true,
|
|
46
|
+
same_site: :lax,
|
|
47
|
+
secure: request.ssl?
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def terminate_session
|
|
53
|
+
Current.session&.destroy!
|
|
54
|
+
Current.session = nil
|
|
55
|
+
cookies.delete(:session_id)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def revoke_sessions_for(user)
|
|
59
|
+
current_user = Current.session&.user == user
|
|
60
|
+
user.sessions.destroy_all
|
|
61
|
+
if current_user
|
|
62
|
+
Current.session = nil
|
|
63
|
+
cookies.delete(:session_id)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SafeReturnNavigation
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
private
|
|
7
|
+
def remember_return_destination
|
|
8
|
+
return unless request.get? && request.format.html?
|
|
9
|
+
|
|
10
|
+
session[:return_to_after_authenticating] = request.fullpath
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def after_authentication_url
|
|
14
|
+
destination = session.delete(:return_to_after_authenticating)
|
|
15
|
+
safe_destination(destination) || default_authenticated_path
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def safe_destination(destination)
|
|
19
|
+
return if destination.blank?
|
|
20
|
+
|
|
21
|
+
destination = url_from(destination)
|
|
22
|
+
destination unless authentication_destination?(destination)
|
|
23
|
+
rescue URI::InvalidURIError
|
|
24
|
+
nil
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def authentication_destination?(destination)
|
|
28
|
+
return true if destination.blank?
|
|
29
|
+
|
|
30
|
+
path = URI.parse(destination).path
|
|
31
|
+
[ new_session_path, new_password_reset_path, new_verification_email_path ].include?(path)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def default_authenticated_path
|
|
35
|
+
root_path
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class EmailVerificationsController < ApplicationController
|
|
4
|
+
allow_unauthenticated_access
|
|
5
|
+
before_action :set_user_by_token
|
|
6
|
+
before_action :protect_token_response
|
|
7
|
+
|
|
8
|
+
def show
|
|
9
|
+
render_verification
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def update
|
|
13
|
+
if @token_unavailable
|
|
14
|
+
render_verification status: :unprocessable_entity
|
|
15
|
+
else
|
|
16
|
+
@user.verify_email!
|
|
17
|
+
redirect_to new_session_path, status: :see_other, notice: "Email verified. You can sign in."
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
def set_user_by_token
|
|
23
|
+
@user = User.find_by_email_verification_token(params[:token])
|
|
24
|
+
@token_unavailable = @user.nil?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def render_verification(status: :ok)
|
|
28
|
+
render UI::EmailVerifications::Show.new(
|
|
29
|
+
user: @user,
|
|
30
|
+
token: params[:token],
|
|
31
|
+
token_unavailable: @token_unavailable
|
|
32
|
+
), status:
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def protect_token_response
|
|
36
|
+
response.headers["Cache-Control"] = "no-store"
|
|
37
|
+
response.headers["Referrer-Policy"] = "no-referrer"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class PasswordResetsController < ApplicationController
|
|
4
|
+
allow_unauthenticated_access
|
|
5
|
+
rate_limit to: 10, within: 15.minutes, only: :create,
|
|
6
|
+
with: -> { redirect_to new_password_reset_path, alert: "Try again later." }
|
|
7
|
+
|
|
8
|
+
def new
|
|
9
|
+
render UI::PasswordResets::New.new(
|
|
10
|
+
Authentication::EmailRequest.new,
|
|
11
|
+
sent: params[:sent].present?
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def create
|
|
16
|
+
request = Authentication::EmailRequest.new(email_request_params)
|
|
17
|
+
|
|
18
|
+
if request.valid?
|
|
19
|
+
AuthenticationDeliveryJob.perform_later(
|
|
20
|
+
purpose: :password_reset,
|
|
21
|
+
email_address: request.email_address
|
|
22
|
+
)
|
|
23
|
+
redirect_to new_password_reset_path(sent: true), status: :see_other
|
|
24
|
+
else
|
|
25
|
+
render UI::PasswordResets::New.new(request), status: :unprocessable_entity
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
def email_request_params
|
|
31
|
+
params.fetch(:authentication_email_request, {}).permit(:email_address)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class PasswordsController < ApplicationController
|
|
4
|
+
allow_unauthenticated_access
|
|
5
|
+
before_action :set_user_by_token
|
|
6
|
+
before_action :protect_token_response
|
|
7
|
+
|
|
8
|
+
def edit
|
|
9
|
+
render_password
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def update
|
|
13
|
+
if @token_unavailable
|
|
14
|
+
render_password status: :unprocessable_entity
|
|
15
|
+
elsif reset_password
|
|
16
|
+
revoke_sessions_for(@user)
|
|
17
|
+
redirect_to new_session_path, status: :see_other, notice: "Password updated. Sign in again."
|
|
18
|
+
else
|
|
19
|
+
render_password status: :unprocessable_entity
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
def set_user_by_token
|
|
25
|
+
@user = User.find_by_password_reset_token(params[:token])
|
|
26
|
+
@token_unavailable = @user.nil?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def render_password(status: :ok)
|
|
30
|
+
render UI::Passwords::Edit.new(
|
|
31
|
+
user: @user,
|
|
32
|
+
token: params[:token],
|
|
33
|
+
token_unavailable: @token_unavailable
|
|
34
|
+
), status:
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def reset_password
|
|
38
|
+
attributes = params.fetch(:user, {}).permit(:password, :password_confirmation)
|
|
39
|
+
@user.password = attributes[:password].to_s
|
|
40
|
+
@user.password_confirmation = attributes[:password_confirmation].to_s
|
|
41
|
+
@user.errors.add(:password, :blank) if @user.password.blank?
|
|
42
|
+
@user.errors.add(:password_confirmation, :blank) if @user.password_confirmation.blank?
|
|
43
|
+
|
|
44
|
+
@user.errors.empty? && @user.save
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def protect_token_response
|
|
48
|
+
response.headers["Cache-Control"] = "no-store"
|
|
49
|
+
response.headers["Referrer-Policy"] = "no-referrer"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class SessionsController < ApplicationController
|
|
4
|
+
allow_unauthenticated_access only: %i[new create]
|
|
5
|
+
rate_limit to: 10, within: 3.minutes, only: :create,
|
|
6
|
+
with: -> { redirect_to new_session_path, alert: "Try again later." }
|
|
7
|
+
|
|
8
|
+
def new
|
|
9
|
+
redirect_to(default_authenticated_path) if authenticated?
|
|
10
|
+
render UI::Sessions::New.new(Authentication::Credentials.new) unless performed?
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def create
|
|
14
|
+
credentials = Authentication::Credentials.new(credentials_params)
|
|
15
|
+
user = User.authenticate_by(
|
|
16
|
+
email_address: credentials.email_address,
|
|
17
|
+
password: credentials.password
|
|
18
|
+
) if credentials.valid?
|
|
19
|
+
|
|
20
|
+
if user&.email_verified?
|
|
21
|
+
start_new_session_for(user)
|
|
22
|
+
redirect_to after_authentication_url, status: :see_other
|
|
23
|
+
elsif user
|
|
24
|
+
session[:verification_email_address] = user.email_address
|
|
25
|
+
redirect_to new_verification_email_path, status: :see_other,
|
|
26
|
+
notice: "Verify your email before signing in."
|
|
27
|
+
else
|
|
28
|
+
credentials.errors.add(:base, "The email address or password is incorrect.")
|
|
29
|
+
render UI::Sessions::New.new(credentials), status: :unprocessable_entity
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def destroy
|
|
34
|
+
terminate_session
|
|
35
|
+
redirect_to new_session_path, status: :see_other, notice: "You have signed out."
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
def credentials_params
|
|
40
|
+
params.fetch(:authentication_credentials, {}).permit(:email_address, :password)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class VerificationEmailsController < ApplicationController
|
|
4
|
+
allow_unauthenticated_access
|
|
5
|
+
rate_limit to: 10, within: 15.minutes, only: :create,
|
|
6
|
+
with: -> { redirect_to new_verification_email_path, alert: "Try again later." }
|
|
7
|
+
|
|
8
|
+
def new
|
|
9
|
+
request = Authentication::EmailRequest.new(
|
|
10
|
+
email_address: session.delete(:verification_email_address)
|
|
11
|
+
)
|
|
12
|
+
render UI::VerificationEmails::New.new(request, sent: params[:sent].present?)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def create
|
|
16
|
+
request = Authentication::EmailRequest.new(email_request_params)
|
|
17
|
+
|
|
18
|
+
if request.valid?
|
|
19
|
+
AuthenticationDeliveryJob.perform_later(
|
|
20
|
+
purpose: :email_verification,
|
|
21
|
+
email_address: request.email_address
|
|
22
|
+
)
|
|
23
|
+
redirect_to new_verification_email_path(sent: true), status: :see_other
|
|
24
|
+
else
|
|
25
|
+
render UI::VerificationEmails::New.new(request), status: :unprocessable_entity
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
def email_request_params
|
|
31
|
+
params.fetch(:authentication_email_request, {}).permit(:email_address)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class AuthenticationDeliveryJob < ApplicationJob
|
|
4
|
+
def perform(purpose:, email_address:)
|
|
5
|
+
user = User.find_by(email_address:)
|
|
6
|
+
return unless user
|
|
7
|
+
|
|
8
|
+
case purpose.to_sym
|
|
9
|
+
when :password_reset
|
|
10
|
+
AuthenticationMailer.password_reset(user).deliver_now
|
|
11
|
+
when :email_verification
|
|
12
|
+
AuthenticationMailer.email_verification(user).deliver_now unless user.email_verified?
|
|
13
|
+
else
|
|
14
|
+
raise ArgumentError, "Unknown authentication delivery purpose: #{purpose.inspect}"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class AuthenticationMailer < ApplicationMailer
|
|
4
|
+
def password_reset(user)
|
|
5
|
+
@user = user
|
|
6
|
+
@token = user.password_reset_token
|
|
7
|
+
mail(to: user.email_address, subject: "Reset your password")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def email_verification(user)
|
|
11
|
+
@user = user
|
|
12
|
+
@token = user.email_verification_token
|
|
13
|
+
mail(to: user.email_address, subject: "Verify your email")
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Authentication
|
|
4
|
+
class Credentials
|
|
5
|
+
include ActiveModel::Model
|
|
6
|
+
|
|
7
|
+
attr_reader :email_address
|
|
8
|
+
attr_accessor :password
|
|
9
|
+
|
|
10
|
+
validates :email_address, :password, presence: true
|
|
11
|
+
|
|
12
|
+
def email_address=(value)
|
|
13
|
+
@email_address = value.to_s.strip.downcase
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Authentication
|
|
4
|
+
class EmailRequest
|
|
5
|
+
include ActiveModel::Model
|
|
6
|
+
|
|
7
|
+
attr_reader :email_address
|
|
8
|
+
|
|
9
|
+
validates :email_address,
|
|
10
|
+
presence: true,
|
|
11
|
+
format: { with: URI::MailTo::EMAIL_REGEXP }
|
|
12
|
+
|
|
13
|
+
def email_address=(value)
|
|
14
|
+
@email_address = value.to_s.strip.downcase
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module User::EmailVerifiable
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
before_update :clear_email_verification, if: :will_save_change_to_email_address?
|
|
8
|
+
|
|
9
|
+
generates_token_for :email_verification, expires_in: 2.days do
|
|
10
|
+
[ email_address, email_verified_at ]
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class_methods do
|
|
15
|
+
def find_by_email_verification_token(token)
|
|
16
|
+
find_by_token_for(:email_verification, token)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def find_by_email_verification_token!(token)
|
|
20
|
+
find_by_token_for!(:email_verification, token)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def email_verification_token
|
|
25
|
+
generate_token_for(:email_verification)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def email_verified?
|
|
29
|
+
email_verified_at.present?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def verify_email!
|
|
33
|
+
update!(email_verified_at: Time.current)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
def clear_email_verification
|
|
38
|
+
self.email_verified_at = nil
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Draw this file from config/routes.rb with:
|
|
2
|
+
# draw :authentication
|
|
3
|
+
#
|
|
4
|
+
# Also add :token, :password, :password_confirmation, and :email_address to
|
|
5
|
+
# config.filter_parameters.
|
|
6
|
+
|
|
7
|
+
resource :session, only: %i[new create destroy]
|
|
8
|
+
resource :password_reset, only: %i[new create]
|
|
9
|
+
resources :passwords, param: :token, only: %i[edit update]
|
|
10
|
+
resource :verification_email, only: %i[new create]
|
|
11
|
+
resources :email_verifications, param: :token, only: %i[show update]
|
data/patterns/authentication/files/db/migrate/20260731000000_add_authentication_and_recovery.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class AddAuthenticationAndRecovery < ActiveRecord::Migration[8.1]
|
|
2
|
+
def change
|
|
3
|
+
add_column :users, :password_digest, :string
|
|
4
|
+
add_column :users, :email_verified_at, :datetime
|
|
5
|
+
|
|
6
|
+
create_table :sessions do |t|
|
|
7
|
+
t.references :user, null: false, foreign_key: true
|
|
8
|
+
t.string :ip_address
|
|
9
|
+
t.string :user_agent
|
|
10
|
+
t.timestamps
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class AuthenticationControllerFlowTest < ActionDispatch::IntegrationTest
|
|
4
|
+
include ActiveJob::TestHelper
|
|
5
|
+
|
|
6
|
+
test "unknown and known recovery addresses have the same response" do
|
|
7
|
+
post password_reset_path, params: {
|
|
8
|
+
authentication_email_request: { email_address: users(:verified).email_address }
|
|
9
|
+
}
|
|
10
|
+
known_response = response
|
|
11
|
+
|
|
12
|
+
post password_reset_path, params: {
|
|
13
|
+
authentication_email_request: { email_address: "unknown@example.test" }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
assert_equal known_response.status, response.status
|
|
17
|
+
assert_equal URI.parse(known_response.location).path, URI.parse(response.location).path
|
|
18
|
+
assert_enqueued_jobs 2, only: AuthenticationDeliveryJob
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test "password token GET does not mutate and PATCH revokes sessions" do
|
|
22
|
+
user = users(:verified)
|
|
23
|
+
token = user.password_reset_token
|
|
24
|
+
|
|
25
|
+
assert_no_changes -> { user.reload.password_digest } do
|
|
26
|
+
get edit_password_path(token)
|
|
27
|
+
assert_response :success
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
assert_difference -> { user.sessions.count }, -user.sessions.count do
|
|
31
|
+
patch password_path(token), params: {
|
|
32
|
+
user: { password: "new secure password", password_confirmation: "new secure password" }
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
assert_redirected_to new_session_path
|
|
37
|
+
assert_raises(ActiveSupport::MessageVerifier::InvalidSignature) do
|
|
38
|
+
User.find_by_password_reset_token!(token)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test "blank or unconfirmed password does not revoke sessions or consume the token" do
|
|
43
|
+
user = users(:verified)
|
|
44
|
+
token = user.password_reset_token
|
|
45
|
+
digest = user.password_digest
|
|
46
|
+
|
|
47
|
+
assert_no_difference -> { user.sessions.count } do
|
|
48
|
+
patch password_path(token), params: {
|
|
49
|
+
user: { password: "", password_confirmation: "" }
|
|
50
|
+
}
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
assert_response :unprocessable_entity
|
|
54
|
+
assert_equal digest, user.reload.password_digest
|
|
55
|
+
assert_equal user, User.find_by_password_reset_token!(token)
|
|
56
|
+
|
|
57
|
+
patch password_path(token), params: {
|
|
58
|
+
user: { password: "new secure password" }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
assert_response :unprocessable_entity
|
|
62
|
+
assert_equal digest, user.reload.password_digest
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
test "verification GET does not mutate and PATCH verifies without signing in" do
|
|
66
|
+
user = users(:unverified)
|
|
67
|
+
token = user.email_verification_token
|
|
68
|
+
|
|
69
|
+
get email_verification_path(token)
|
|
70
|
+
assert_response :success
|
|
71
|
+
assert_not user.reload.email_verified?
|
|
72
|
+
|
|
73
|
+
assert_no_difference "Session.count" do
|
|
74
|
+
patch email_verification_path(token)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
assert user.reload.email_verified?
|
|
78
|
+
assert_redirected_to new_session_path
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
test "invalid tokens render recoverable states" do
|
|
82
|
+
get edit_password_path("tampered")
|
|
83
|
+
assert_response :success
|
|
84
|
+
assert_select "[data-nk='alert']", text: /invalid or expired/i
|
|
85
|
+
|
|
86
|
+
get email_verification_path("tampered")
|
|
87
|
+
assert_response :success
|
|
88
|
+
assert_select "[data-nk='alert']", text: /invalid or expired/i
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
test "tokens for deleted users render recoverable states" do
|
|
92
|
+
user = users(:unverified)
|
|
93
|
+
reset_token = user.password_reset_token
|
|
94
|
+
verification_token = user.email_verification_token
|
|
95
|
+
user.destroy!
|
|
96
|
+
|
|
97
|
+
get edit_password_path(reset_token)
|
|
98
|
+
assert_response :success
|
|
99
|
+
|
|
100
|
+
get email_verification_path(verification_token)
|
|
101
|
+
assert_response :success
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class SafeReturnNavigationTest < ActionController::TestCase
|
|
4
|
+
tests SessionsController
|
|
5
|
+
|
|
6
|
+
test "accepts local destinations and rejects external or looping destinations" do
|
|
7
|
+
assert_equal "/projects?state=active", safe_destination("/projects?state=active")
|
|
8
|
+
assert_nil safe_destination("https://attacker.example/projects")
|
|
9
|
+
assert_nil safe_destination("//attacker.example/projects")
|
|
10
|
+
assert_nil safe_destination(new_session_path)
|
|
11
|
+
assert_nil safe_destination(new_password_reset_path)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
def safe_destination(value)
|
|
16
|
+
@controller.send(:safe_destination, value)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class AuthenticationMailerTest < ActionMailer::TestCase
|
|
4
|
+
test "password recovery contains an absolute expiring reset link" do
|
|
5
|
+
mail = AuthenticationMailer.password_reset(users(:verified))
|
|
6
|
+
|
|
7
|
+
assert_equal [ users(:verified).email_address ], mail.to
|
|
8
|
+
assert_match "Reset your password", mail.subject
|
|
9
|
+
assert_match %r{https?://.+/passwords/.+/edit}, mail.html_part.body.decoded
|
|
10
|
+
assert_match "15 minutes", mail.text_part.body.decoded
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test "verification contains an absolute verification link" do
|
|
14
|
+
mail = AuthenticationMailer.email_verification(users(:unverified))
|
|
15
|
+
|
|
16
|
+
assert_equal [ users(:unverified).email_address ], mail.to
|
|
17
|
+
assert_match "Verify your email", mail.subject
|
|
18
|
+
assert_match %r{https?://.+/email_verifications/.+}, mail.html_part.body.decoded
|
|
19
|
+
assert_match "two days", mail.text_part.body.decoded
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class UserEmailVerifiableTest < ActiveSupport::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@user = users(:unverified)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
test "verification changes state and invalidates the link" do
|
|
9
|
+
token = @user.email_verification_token
|
|
10
|
+
|
|
11
|
+
@user.verify_email!
|
|
12
|
+
|
|
13
|
+
assert @user.email_verified?
|
|
14
|
+
assert_raises(ActiveSupport::MessageVerifier::InvalidSignature) do
|
|
15
|
+
User.find_by_email_verification_token!(token)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
test "changing the address invalidates the link" do
|
|
20
|
+
token = @user.email_verification_token
|
|
21
|
+
|
|
22
|
+
@user.update!(email_address: "new-address@example.test")
|
|
23
|
+
|
|
24
|
+
assert_raises(ActiveSupport::MessageVerifier::InvalidSignature) do
|
|
25
|
+
User.find_by_email_verification_token!(token)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test "changing a verified address requires verification again" do
|
|
30
|
+
@user.verify_email!
|
|
31
|
+
|
|
32
|
+
@user.update!(email_address: "new-address@example.test")
|
|
33
|
+
|
|
34
|
+
assert_not @user.email_verified?
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require "application_system_test_case"
|
|
2
|
+
|
|
3
|
+
class AuthenticationSystemFlowTest < ApplicationSystemTestCase
|
|
4
|
+
test "signs in and returns to the protected destination" do
|
|
5
|
+
visit projects_path
|
|
6
|
+
assert_current_path new_session_path
|
|
7
|
+
|
|
8
|
+
fill_in "Email address", with: users(:verified).email_address
|
|
9
|
+
fill_in "Password", with: "password"
|
|
10
|
+
click_on "Sign in"
|
|
11
|
+
|
|
12
|
+
assert_current_path projects_path
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
test "recovers from an unusable reset link" do
|
|
16
|
+
visit edit_password_path("tampered")
|
|
17
|
+
|
|
18
|
+
assert_text "This link is invalid or expired"
|
|
19
|
+
click_on "Request a new link"
|
|
20
|
+
|
|
21
|
+
assert_current_path new_password_reset_path
|
|
22
|
+
end
|
|
23
|
+
end
|