kaze 2.1.0 → 2.2.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 +69 -1
- data/README.md +42 -2
- data/lib/kaze/commands/app/base_stack.rb +14 -0
- data/lib/kaze/commands/app/hotwire_stack.rb +4 -1
- data/lib/kaze/commands/app/inertia_react_stack.rb +3 -1
- data/lib/kaze/commands/app/inertia_vue_stack.rb +3 -1
- data/lib/kaze/version.rb +1 -1
- data/stubs/default/app/forms/auth/login_form.rb +6 -1
- data/stubs/default/app/forms/auth/two_factor_challenge_form.rb +24 -0
- data/stubs/default/app/forms/confirm_two_factor_form.rb +5 -0
- data/stubs/default/app/forms/disable_two_factor_form.rb +7 -0
- data/stubs/default/app/models/concerns/two_factor_authenticatable.rb +112 -0
- data/stubs/default/app/models/session_guard.rb +8 -1
- data/stubs/default/app/models/two_factor_challenge.rb +55 -0
- data/stubs/default/app/models/user.rb +1 -0
- data/stubs/default/config/initializers/active_record_encryption.rb +20 -0
- data/stubs/default/config/routes.rb +9 -0
- data/stubs/default/db/migrate/20240101000001_add_two_factor_to_users.rb +15 -0
- data/stubs/default/test/integration/auth/rate_limiting_test.rb +64 -0
- data/stubs/default/test/integration/auth/two_factor_challenge_test.rb +114 -0
- data/stubs/default/test/integration/settings/two_factor_test.rb +104 -0
- data/stubs/default/test/models/two_factor_authenticatable_test.rb +143 -0
- data/stubs/default/test/test_helper.rb +16 -0
- data/stubs/hotwire/app/controllers/auth/authenticated_session_controller.rb +32 -1
- data/stubs/hotwire/app/controllers/auth/two_factor_challenge_controller.rb +59 -0
- data/stubs/hotwire/app/controllers/concerns/set_two_factor_challenge.rb +8 -0
- data/stubs/hotwire/app/controllers/settings/two_factor_controller.rb +48 -0
- data/stubs/hotwire/app/views/auth/forgot_password.html.erb +1 -1
- data/stubs/hotwire/app/views/auth/login.html.erb +1 -1
- data/stubs/hotwire/app/views/auth/register.html.erb +2 -2
- data/stubs/hotwire/app/views/auth/reset_password.html.erb +3 -3
- data/stubs/hotwire/app/views/auth/two_factor_challenge.html.erb +21 -0
- data/stubs/hotwire/app/views/auth/verify_email.html.erb +2 -2
- data/stubs/hotwire/app/views/layouts/_settings.html.erb +1 -0
- data/stubs/hotwire/app/views/layouts/_sidebar_user.html.erb +1 -1
- data/stubs/hotwire/app/views/settings/password/_update_password_form.html.erb +6 -6
- data/stubs/hotwire/app/views/settings/profile/_confirm_user_deletion_modal.html.erb +1 -1
- data/stubs/hotwire/app/views/settings/profile/_delete_user_form.html.erb +1 -1
- data/stubs/hotwire/app/views/settings/two_factor/_confirming.html.erb +20 -0
- data/stubs/hotwire/app/views/settings/two_factor/_disabled.html.erb +8 -0
- data/stubs/hotwire/app/views/settings/two_factor/_enabled.html.erb +29 -0
- data/stubs/hotwire/app/views/settings/two_factor/edit.html.erb +16 -0
- data/stubs/inertia-common/app/controllers/auth/authenticated_session_controller.rb +30 -1
- data/stubs/inertia-common/app/controllers/auth/two_factor_challenge_controller.rb +53 -0
- data/stubs/inertia-common/app/controllers/concerns/set_two_factor_challenge.rb +8 -0
- data/stubs/inertia-common/app/controllers/settings/two_factor_controller.rb +60 -0
- data/stubs/inertia-react-ts/app/javascript/Layouts/SettingsLayout.tsx +5 -1
- data/stubs/inertia-react-ts/app/javascript/Pages/Auth/ForgotPassword.tsx +2 -2
- data/stubs/inertia-react-ts/app/javascript/Pages/Auth/Register.tsx +1 -1
- data/stubs/inertia-react-ts/app/javascript/Pages/Auth/ResetPassword.tsx +3 -3
- data/stubs/inertia-react-ts/app/javascript/Pages/Auth/TwoFactorChallenge.tsx +71 -0
- data/stubs/inertia-react-ts/app/javascript/Pages/Auth/VerifyEmail.tsx +3 -3
- data/stubs/inertia-react-ts/app/javascript/Pages/Settings/Partials/DeleteUserForm.tsx +2 -2
- data/stubs/inertia-react-ts/app/javascript/Pages/Settings/Partials/UpdatePasswordForm.tsx +3 -3
- data/stubs/inertia-react-ts/app/javascript/Pages/Settings/TwoFactor.tsx +199 -0
- data/stubs/inertia-vue-ts/app/javascript/Layouts/SettingsLayout.vue +5 -1
- data/stubs/inertia-vue-ts/app/javascript/Pages/Auth/ForgotPassword.vue +2 -2
- data/stubs/inertia-vue-ts/app/javascript/Pages/Auth/Register.vue +1 -1
- data/stubs/inertia-vue-ts/app/javascript/Pages/Auth/ResetPassword.vue +3 -3
- data/stubs/inertia-vue-ts/app/javascript/Pages/Auth/TwoFactorChallenge.vue +60 -0
- data/stubs/inertia-vue-ts/app/javascript/Pages/Auth/VerifyEmail.vue +3 -3
- data/stubs/inertia-vue-ts/app/javascript/Pages/Settings/Partials/DeleteUserForm.vue +2 -2
- data/stubs/inertia-vue-ts/app/javascript/Pages/Settings/Partials/UpdatePasswordForm.vue +3 -3
- data/stubs/inertia-vue-ts/app/javascript/Pages/Settings/TwoFactor.vue +147 -0
- metadata +41 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<% content_for(:title, 'Two factor authentication') %>
|
|
2
|
+
<div class="mb-4 text-sm text-muted-foreground">
|
|
3
|
+
Enter the code from your authenticator app to finish signing in.
|
|
4
|
+
</div>
|
|
5
|
+
<%= form_with model: @form, url: two_factor_challenge_store_path do |form| %>
|
|
6
|
+
<div>
|
|
7
|
+
<%= render(InputLabelComponent.new({ for: "code", value: "Code" })) %>
|
|
8
|
+
<%= render(TextInputComponent.new({ id: "code", class: "block mt-1 w-full", type: "text", name: "code", inputmode: "numeric", autocomplete: "one-time-code", autofocus: true })) %>
|
|
9
|
+
<%= render(InputErrorComponent.new({ class: "mt-2", message: @form.error_messages[:code] })) %>
|
|
10
|
+
</div>
|
|
11
|
+
<div class="mt-4">
|
|
12
|
+
<%= render(InputLabelComponent.new({ for: "recovery_code", value: "Or a recovery code" })) %>
|
|
13
|
+
<%= render(TextInputComponent.new({ id: "recovery_code", class: "block mt-1 w-full", type: "text", name: "recovery_code", autocomplete: "one-time-code" })) %>
|
|
14
|
+
<%= render(InputErrorComponent.new({ class: "mt-2", message: @form.error_messages[:recovery_code] })) %>
|
|
15
|
+
</div>
|
|
16
|
+
<div class="flex items-center justify-end mt-4">
|
|
17
|
+
<%= render(PrimaryButtonComponent.new({ class: "ms-4" })) do %>
|
|
18
|
+
Continue
|
|
19
|
+
<% end %>
|
|
20
|
+
</div>
|
|
21
|
+
<% end %>
|
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
<form method="POST" action="<%= verification_send_path %>">
|
|
11
11
|
<div>
|
|
12
12
|
<%= render(PrimaryButtonComponent.new) do %>
|
|
13
|
-
Resend
|
|
13
|
+
Resend verification email
|
|
14
14
|
<% end %>
|
|
15
15
|
</div>
|
|
16
16
|
</form>
|
|
17
17
|
<form method="POST" action="<%= logout_path %>">
|
|
18
18
|
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>">
|
|
19
19
|
<button type="submit" class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800">
|
|
20
|
-
Log
|
|
20
|
+
Log out
|
|
21
21
|
</button>
|
|
22
22
|
</form>
|
|
23
23
|
</div>
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
<% [
|
|
9
9
|
{ title: 'Profile', href: profile_edit_path },
|
|
10
10
|
{ title: 'Password', href: password_edit_path },
|
|
11
|
+
{ title: 'Two factor', href: two_factor_edit_path },
|
|
11
12
|
{ title: 'Appearance', href: appearance_edit_path }
|
|
12
13
|
].each do |item| %>
|
|
13
14
|
<a href="<%= item[:href] %>" class="inline-flex h-8 w-full items-center justify-start gap-2 rounded-md px-3 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground <%= 'bg-muted' if current_page?(item[:href]) %>">
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>">
|
|
29
29
|
<%= render(DropdownLinkComponent.new({ href: logout_path, onclick: "event.preventDefault();this.closest('form').submit()" })) do %>
|
|
30
30
|
<%= render(IconComponent.new('log-out')) %>
|
|
31
|
-
Log
|
|
31
|
+
Log out
|
|
32
32
|
<% end %>
|
|
33
33
|
</form>
|
|
34
34
|
<% end %>
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
<%= turbo_frame_tag 'update_password_form' do %>
|
|
2
2
|
<section>
|
|
3
3
|
<%= form_with model: @update_password_form, url: password_update_path, method: "put", class: "mt-6 space-y-6" do |update_password_form| %>
|
|
4
|
-
<!-- Current
|
|
4
|
+
<!-- Current password -->
|
|
5
5
|
<div>
|
|
6
|
-
<%= render(InputLabelComponent.new({ for: "update_password_current_password", value: "Current
|
|
6
|
+
<%= render(InputLabelComponent.new({ for: "update_password_current_password", value: "Current password" })) %>
|
|
7
7
|
<%= render(TextInputComponent.new({ id: "update_password_current_password", class: "block mt-1 w-full", type: "password", name: "current_password", autocomplete: "current-password" })) %>
|
|
8
8
|
<%= render(InputErrorComponent.new({ class: "mt-2", message: @update_password_form.error_messages[:current_password] })) %>
|
|
9
9
|
</div>
|
|
10
|
-
<!-- New
|
|
10
|
+
<!-- New password -->
|
|
11
11
|
<div>
|
|
12
|
-
<%= render(InputLabelComponent.new({ for: "update_password_password", value: "New
|
|
12
|
+
<%= render(InputLabelComponent.new({ for: "update_password_password", value: "New password" })) %>
|
|
13
13
|
<%= render(TextInputComponent.new({ id: "update_password_password", class: "block mt-1 w-full", type: "password", name: "password", autocomplete: "new-password" })) %>
|
|
14
14
|
<%= render(InputErrorComponent.new({ class: "mt-2", message: @update_password_form.error_messages[:password] })) %>
|
|
15
15
|
</div>
|
|
16
|
-
<!-- Confirm
|
|
16
|
+
<!-- Confirm password -->
|
|
17
17
|
<div class="mt-4">
|
|
18
|
-
<%= render(InputLabelComponent.new({ for: "update_password_password_confirmation", value: "Confirm
|
|
18
|
+
<%= render(InputLabelComponent.new({ for: "update_password_password_confirmation", value: "Confirm password" })) %>
|
|
19
19
|
<%= render(TextInputComponent.new({ id: "update_password_password_confirmation", class: "block mt-1 w-full", type: "password", name: "password_confirmation", autocomplete: "new-password" })) %>
|
|
20
20
|
<%= render(InputErrorComponent.new({ class: "mt-2", message: @update_password_form.error_messages[:password_confirmation] })) %>
|
|
21
21
|
</div>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<section class="space-y-6">
|
|
2
2
|
<%= render(DangerButtonComponent.new({"x-data": "", "x-on:click.prevent": "$dispatch('open-modal', 'confirm-user-deletion')"})) do %>
|
|
3
|
-
Delete
|
|
3
|
+
Delete account
|
|
4
4
|
<% end %>
|
|
5
5
|
</section>
|
|
6
6
|
<%= render 'settings/profile/confirm_user_deletion_modal' %>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<p class="text-sm text-muted-foreground">
|
|
2
|
+
Scan this with your authenticator app, then enter the code it shows to finish turning it on.
|
|
3
|
+
</p>
|
|
4
|
+
<div class="w-44 rounded-lg border border-sidebar-border/70 bg-white p-2 dark:border-sidebar-border">
|
|
5
|
+
<%= raw Current.auth.user.two_factor_qr_code_svg %>
|
|
6
|
+
</div>
|
|
7
|
+
<p class="text-sm text-muted-foreground">
|
|
8
|
+
Cannot scan it? Enter this key instead:
|
|
9
|
+
<code class="rounded bg-muted px-1.5 py-0.5 font-mono text-xs text-foreground"><%= Current.auth.user.two_factor_secret %></code>
|
|
10
|
+
</p>
|
|
11
|
+
<%= form_with model: @confirm_form, url: two_factor_update_path, method: :patch, class: "space-y-6" do %>
|
|
12
|
+
<div>
|
|
13
|
+
<%= render(InputLabelComponent.new({ for: "code", value: "Code" })) %>
|
|
14
|
+
<%= render(TextInputComponent.new({ id: "code", class: "mt-1 block w-full max-w-xs", type: "text", name: "code", inputmode: "numeric", autocomplete: "one-time-code", autofocus: true })) %>
|
|
15
|
+
<%= render(InputErrorComponent.new({ class: "mt-2", message: @confirm_form.error_messages[:code] })) %>
|
|
16
|
+
</div>
|
|
17
|
+
<%= render(PrimaryButtonComponent.new) do %>
|
|
18
|
+
Confirm
|
|
19
|
+
<% end %>
|
|
20
|
+
<% end %>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<p class="text-sm text-muted-foreground">
|
|
2
|
+
Two factor authentication is off. Turn it on and you will be asked for a code from your authenticator app each time you sign in.
|
|
3
|
+
</p>
|
|
4
|
+
<%= form_with url: two_factor_store_path, method: :post do %>
|
|
5
|
+
<%= render(PrimaryButtonComponent.new) do %>
|
|
6
|
+
Turn on two factor authentication
|
|
7
|
+
<% end %>
|
|
8
|
+
<% end %>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<p class="text-sm text-muted-foreground">
|
|
2
|
+
Two factor authentication is on. You will be asked for a code each time you sign in.
|
|
3
|
+
</p>
|
|
4
|
+
<div class="space-y-3 rounded-xl border border-sidebar-border/70 p-4 dark:border-sidebar-border">
|
|
5
|
+
<div class="text-sm font-medium">Recovery codes</div>
|
|
6
|
+
<p class="text-sm text-muted-foreground">
|
|
7
|
+
Keep these somewhere safe. Each one can be used once to sign in if you cannot reach your authenticator app.
|
|
8
|
+
</p>
|
|
9
|
+
<ul class="grid grid-cols-2 gap-1 font-mono text-xs">
|
|
10
|
+
<% Current.auth.user.two_factor_recovery_codes_list.each do |recovery_code| %>
|
|
11
|
+
<li><%= recovery_code %></li>
|
|
12
|
+
<% end %>
|
|
13
|
+
</ul>
|
|
14
|
+
<%= form_with url: two_factor_recovery_codes_path, method: :post do %>
|
|
15
|
+
<%= render(SecondaryButtonComponent.new({ type: "submit" })) do %>
|
|
16
|
+
Generate new codes
|
|
17
|
+
<% end %>
|
|
18
|
+
<% end %>
|
|
19
|
+
</div>
|
|
20
|
+
<%= form_with model: @disable_form, url: two_factor_destroy_path, method: :delete, class: "space-y-6" do %>
|
|
21
|
+
<div>
|
|
22
|
+
<%= render(InputLabelComponent.new({ for: "password", value: "Current password" })) %>
|
|
23
|
+
<%= render(TextInputComponent.new({ id: "password", class: "mt-1 block w-full max-w-xs", type: "password", name: "password", autocomplete: "current-password" })) %>
|
|
24
|
+
<%= render(InputErrorComponent.new({ class: "mt-2", message: @disable_form.error_messages[:password] })) %>
|
|
25
|
+
</div>
|
|
26
|
+
<%= render(DangerButtonComponent.new) do %>
|
|
27
|
+
Turn off two factor authentication
|
|
28
|
+
<% end %>
|
|
29
|
+
<% end %>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<% content_for(:title, 'Two factor settings') %>
|
|
2
|
+
<% content_for(:breadcrumbs) do %>
|
|
3
|
+
<%= render(BreadcrumbsComponent.new([ { title: 'Two factor settings', href: two_factor_edit_path } ])) %>
|
|
4
|
+
<% end %>
|
|
5
|
+
<%= render layout: 'layouts/settings' do %>
|
|
6
|
+
<div class="space-y-6">
|
|
7
|
+
<%= render(HeadingComponent.new(title: 'Two factor authentication', description: 'Add a second step to signing in, using an authenticator app', variant: 'small')) %>
|
|
8
|
+
<% if Current.auth.user.two_factor_enabled? %>
|
|
9
|
+
<%= render 'settings/two_factor/enabled' %>
|
|
10
|
+
<% elsif Current.auth.user.two_factor_pending? %>
|
|
11
|
+
<%= render 'settings/two_factor/confirming' %>
|
|
12
|
+
<% else %>
|
|
13
|
+
<%= render 'settings/two_factor/disabled' %>
|
|
14
|
+
<% end %>
|
|
15
|
+
</div>
|
|
16
|
+
<% end %>
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
class Auth::AuthenticatedSessionController < ApplicationController
|
|
2
2
|
include RedirectIfAuthenticated
|
|
3
|
+
include SetTwoFactorChallenge
|
|
3
4
|
|
|
4
5
|
skip_authenticate only: %i[new create]
|
|
5
6
|
skip_redirect_if_authenticated only: :destroy
|
|
6
7
|
skip_ensure_email_is_verified only: :destroy
|
|
7
8
|
|
|
9
|
+
# Passwords are stronger than a six digit code, but not so strong that
|
|
10
|
+
# unlimited guesses are safe. Keyed on the email being tried.
|
|
11
|
+
rate_limit to: 10,
|
|
12
|
+
within: 1.minute,
|
|
13
|
+
by: -> { params[:email].to_s.strip.downcase.presence || request.remote_ip },
|
|
14
|
+
with: -> { too_many_attempts },
|
|
15
|
+
only: :create
|
|
16
|
+
|
|
8
17
|
def new
|
|
9
18
|
render inertia: 'Auth/Login', props: {
|
|
10
19
|
status: flash[:status]
|
|
@@ -16,7 +25,11 @@ class Auth::AuthenticatedSessionController < ApplicationController
|
|
|
16
25
|
|
|
17
26
|
form.authenticate
|
|
18
27
|
|
|
19
|
-
return redirect_back_or_to login_path, inertia: { errors: form.error_messages } if
|
|
28
|
+
return redirect_back_or_to login_path, inertia: { errors: form.error_messages } if form.user.nil?
|
|
29
|
+
|
|
30
|
+
return redirect_to two_factor_challenge_path if start_two_factor_challenge(form)
|
|
31
|
+
|
|
32
|
+
Current.auth.login(form.user, form.remember)
|
|
20
33
|
|
|
21
34
|
redirect_to dashboard_path
|
|
22
35
|
end
|
|
@@ -28,4 +41,20 @@ class Auth::AuthenticatedSessionController < ApplicationController
|
|
|
28
41
|
|
|
29
42
|
redirect_to '/'
|
|
30
43
|
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def too_many_attempts
|
|
48
|
+
redirect_to login_path,
|
|
49
|
+
inertia: { errors: { email: 'Too many attempts. Try again in a minute.' } }
|
|
50
|
+
end
|
|
51
|
+
# A correct password is not a session when a second factor is owed. Hold the
|
|
52
|
+
# user in the challenge instead and let them prove the rest.
|
|
53
|
+
def start_two_factor_challenge(form)
|
|
54
|
+
return false unless form.user.two_factor_enabled?
|
|
55
|
+
|
|
56
|
+
two_factor_challenge.start(form.user, remember: form.remember.present?)
|
|
57
|
+
|
|
58
|
+
true
|
|
59
|
+
end
|
|
31
60
|
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
class Auth::TwoFactorChallengeController < ApplicationController
|
|
2
|
+
include RedirectIfAuthenticated
|
|
3
|
+
include SetTwoFactorChallenge
|
|
4
|
+
|
|
5
|
+
skip_authenticate
|
|
6
|
+
before_action :ensure_challenge_is_pending
|
|
7
|
+
|
|
8
|
+
# Six digits is small enough to guess given enough tries, so the attempts are
|
|
9
|
+
# capped. Keyed on the account being challenged rather than the address, so
|
|
10
|
+
# moving between addresses does not buy more attempts.
|
|
11
|
+
rate_limit to: 5,
|
|
12
|
+
within: 1.minute,
|
|
13
|
+
by: -> { two_factor_challenge.user&.id || request.remote_ip },
|
|
14
|
+
with: -> { too_many_attempts },
|
|
15
|
+
only: :create
|
|
16
|
+
|
|
17
|
+
def new
|
|
18
|
+
render inertia: 'Auth/TwoFactorChallenge'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def create
|
|
22
|
+
form = Auth::TwoFactorChallengeForm.new(params.permit(:code, :recovery_code))
|
|
23
|
+
|
|
24
|
+
form.authenticate(two_factor_challenge.user)
|
|
25
|
+
|
|
26
|
+
return redirect_to two_factor_challenge_path, inertia: { errors: form.error_messages } if form.errors.any?
|
|
27
|
+
|
|
28
|
+
complete_login
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def too_many_attempts
|
|
34
|
+
redirect_to two_factor_challenge_path,
|
|
35
|
+
inertia: { errors: { code: 'Too many attempts. Try again in a minute.' } }
|
|
36
|
+
end
|
|
37
|
+
def ensure_challenge_is_pending
|
|
38
|
+
redirect_to login_path unless two_factor_challenge.pending?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# The session id is rotated on the way in, so a session fixed before the
|
|
42
|
+
# password was given cannot survive the second factor.
|
|
43
|
+
def complete_login
|
|
44
|
+
user = two_factor_challenge.user
|
|
45
|
+
remember = two_factor_challenge.remember?
|
|
46
|
+
|
|
47
|
+
reset_session
|
|
48
|
+
|
|
49
|
+
Current.auth.login(user, remember)
|
|
50
|
+
|
|
51
|
+
redirect_to dashboard_path
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
class Settings::TwoFactorController < ApplicationController
|
|
2
|
+
skip_ensure_email_is_verified
|
|
3
|
+
|
|
4
|
+
def edit
|
|
5
|
+
render inertia: 'Settings/TwoFactor', props: two_factor_props
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Starts setup. The account is not protected until the code is confirmed, so
|
|
9
|
+
# this is safe to call again to start over.
|
|
10
|
+
def create
|
|
11
|
+
Current.auth.user.prepare_two_factor
|
|
12
|
+
|
|
13
|
+
redirect_to two_factor_edit_path
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def update
|
|
17
|
+
form = ConfirmTwoFactorForm.new(params.permit(:code))
|
|
18
|
+
|
|
19
|
+
unless form.valid? && Current.auth.user.confirm_two_factor(form.code)
|
|
20
|
+
form.errors.add(:code, message: 'That code is not valid.') if form.errors[:code].empty?
|
|
21
|
+
|
|
22
|
+
return redirect_to two_factor_edit_path, inertia: { errors: form.error_messages }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
redirect_to two_factor_edit_path, flash: { status: 'two-factor-enabled' }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def destroy
|
|
29
|
+
form = DisableTwoFactorForm.new(params.permit(:password))
|
|
30
|
+
|
|
31
|
+
return redirect_to two_factor_edit_path, inertia: { errors: form.error_messages } if form.invalid?
|
|
32
|
+
|
|
33
|
+
Current.auth.user.disable_two_factor
|
|
34
|
+
|
|
35
|
+
redirect_to two_factor_edit_path
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def recovery_codes
|
|
39
|
+
Current.auth.user.regenerate_two_factor_recovery_codes
|
|
40
|
+
|
|
41
|
+
redirect_to two_factor_edit_path, flash: { status: 'recovery-codes-generated' }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
# The QR code and the secret are only sent while setup is unfinished, and
|
|
46
|
+
# the recovery codes only once it is done -- neither needs to be on the
|
|
47
|
+
# wire at any other time.
|
|
48
|
+
def two_factor_props
|
|
49
|
+
user = Current.auth.user
|
|
50
|
+
|
|
51
|
+
{
|
|
52
|
+
enabled: user.two_factor_enabled?,
|
|
53
|
+
pending: user.two_factor_pending?,
|
|
54
|
+
qrCode: user.two_factor_pending? ? user.two_factor_qr_code_svg : nil,
|
|
55
|
+
secret: user.two_factor_pending? ? user.two_factor_secret : nil,
|
|
56
|
+
recoveryCodes: user.two_factor_enabled? ? user.two_factor_recovery_codes_list : [],
|
|
57
|
+
status: flash[:status]
|
|
58
|
+
}
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -4,7 +4,7 @@ import Heading from '@/Components/Heading'
|
|
|
4
4
|
import { Button } from '@/Components/ui/button'
|
|
5
5
|
import { Separator } from '@/Components/ui/separator'
|
|
6
6
|
import { cn } from '@/lib/utils'
|
|
7
|
-
import { appearance_edit_path, password_edit_path, profile_edit_path } from '@/routes'
|
|
7
|
+
import { appearance_edit_path, password_edit_path, profile_edit_path, two_factor_edit_path } from '@/routes'
|
|
8
8
|
import { NavItem } from '@/types'
|
|
9
9
|
|
|
10
10
|
const sidebarNavItems: NavItem[] = [
|
|
@@ -16,6 +16,10 @@ const sidebarNavItems: NavItem[] = [
|
|
|
16
16
|
title: 'Password',
|
|
17
17
|
href: password_edit_path(),
|
|
18
18
|
},
|
|
19
|
+
{
|
|
20
|
+
title: 'Two factor',
|
|
21
|
+
href: two_factor_edit_path(),
|
|
22
|
+
},
|
|
19
23
|
{
|
|
20
24
|
title: 'Appearance',
|
|
21
25
|
href: appearance_edit_path(),
|
|
@@ -19,7 +19,7 @@ export default function ForgotPassword({ status }: { status?: string }) {
|
|
|
19
19
|
|
|
20
20
|
return (
|
|
21
21
|
<GuestLayout>
|
|
22
|
-
<Head title="Forgot
|
|
22
|
+
<Head title="Forgot password" />
|
|
23
23
|
|
|
24
24
|
<div className="mb-4 text-sm text-gray-600 dark:text-gray-400">
|
|
25
25
|
Forgot your password? No problem. Just let us know your email address and we will email you a password reset
|
|
@@ -43,7 +43,7 @@ export default function ForgotPassword({ status }: { status?: string }) {
|
|
|
43
43
|
|
|
44
44
|
<div className="flex items-center justify-end mt-4">
|
|
45
45
|
<Button className="ms-4" disabled={processing}>
|
|
46
|
-
Email
|
|
46
|
+
Email password reset link
|
|
47
47
|
</Button>
|
|
48
48
|
</div>
|
|
49
49
|
</form>
|
|
@@ -24,7 +24,7 @@ export default function ResetPassword({ token }: { token: string }) {
|
|
|
24
24
|
|
|
25
25
|
return (
|
|
26
26
|
<GuestLayout>
|
|
27
|
-
<Head title="Reset
|
|
27
|
+
<Head title="Reset password" />
|
|
28
28
|
|
|
29
29
|
<form onSubmit={submit}>
|
|
30
30
|
<div>
|
|
@@ -45,7 +45,7 @@ export default function ResetPassword({ token }: { token: string }) {
|
|
|
45
45
|
</div>
|
|
46
46
|
|
|
47
47
|
<div className="mt-4">
|
|
48
|
-
<Label htmlFor="password_confirmation">Confirm
|
|
48
|
+
<Label htmlFor="password_confirmation">Confirm password</Label>
|
|
49
49
|
|
|
50
50
|
<Input
|
|
51
51
|
type="password"
|
|
@@ -61,7 +61,7 @@ export default function ResetPassword({ token }: { token: string }) {
|
|
|
61
61
|
|
|
62
62
|
<div className="flex items-center justify-end mt-4">
|
|
63
63
|
<Button className="ms-4" disabled={processing}>
|
|
64
|
-
Reset
|
|
64
|
+
Reset password
|
|
65
65
|
</Button>
|
|
66
66
|
</div>
|
|
67
67
|
</form>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import GuestLayout from '@/Layouts/GuestLayout'
|
|
2
|
+
import { Button } from '@/Components/ui/button'
|
|
3
|
+
import { Input } from '@/Components/ui/input'
|
|
4
|
+
import { Label } from '@/Components/ui/label'
|
|
5
|
+
import InputError from '@/Components/InputError'
|
|
6
|
+
import { Head, useForm } from '@inertiajs/react'
|
|
7
|
+
import { FormEventHandler } from 'react'
|
|
8
|
+
import { two_factor_challenge_store_path } from '@/routes'
|
|
9
|
+
|
|
10
|
+
export default function TwoFactorChallenge() {
|
|
11
|
+
const { data, setData, post, processing, errors } = useForm({
|
|
12
|
+
code: '',
|
|
13
|
+
recovery_code: '',
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const submit: FormEventHandler = (e) => {
|
|
17
|
+
e.preventDefault()
|
|
18
|
+
|
|
19
|
+
post(two_factor_challenge_store_path())
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<GuestLayout>
|
|
24
|
+
<Head title="Two factor authentication" />
|
|
25
|
+
|
|
26
|
+
<div className="mb-4 text-sm text-muted-foreground">
|
|
27
|
+
Enter the code from your authenticator app to finish signing in.
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
<form onSubmit={submit}>
|
|
31
|
+
<div>
|
|
32
|
+
<Label htmlFor="code">Code</Label>
|
|
33
|
+
|
|
34
|
+
<Input
|
|
35
|
+
id="code"
|
|
36
|
+
name="code"
|
|
37
|
+
value={data.code}
|
|
38
|
+
className="mt-1 block w-full"
|
|
39
|
+
inputMode="numeric"
|
|
40
|
+
autoComplete="one-time-code"
|
|
41
|
+
autoFocus
|
|
42
|
+
onChange={(e) => setData('code', e.target.value)}
|
|
43
|
+
/>
|
|
44
|
+
|
|
45
|
+
<InputError message={errors.code} className="mt-2" />
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
<div className="mt-4">
|
|
49
|
+
<Label htmlFor="recovery_code">Or a recovery code</Label>
|
|
50
|
+
|
|
51
|
+
<Input
|
|
52
|
+
id="recovery_code"
|
|
53
|
+
name="recovery_code"
|
|
54
|
+
value={data.recovery_code}
|
|
55
|
+
className="mt-1 block w-full"
|
|
56
|
+
autoComplete="one-time-code"
|
|
57
|
+
onChange={(e) => setData('recovery_code', e.target.value)}
|
|
58
|
+
/>
|
|
59
|
+
|
|
60
|
+
<InputError message={errors.recovery_code} className="mt-2" />
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
<div className="flex items-center justify-end mt-4">
|
|
64
|
+
<Button className="ms-4" disabled={processing}>
|
|
65
|
+
Continue
|
|
66
|
+
</Button>
|
|
67
|
+
</div>
|
|
68
|
+
</form>
|
|
69
|
+
</GuestLayout>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
@@ -15,7 +15,7 @@ export default function VerifyEmail({ status }: { status?: string }) {
|
|
|
15
15
|
|
|
16
16
|
return (
|
|
17
17
|
<GuestLayout>
|
|
18
|
-
<Head title="Email
|
|
18
|
+
<Head title="Email verification" />
|
|
19
19
|
|
|
20
20
|
<div className="mb-4 text-sm text-gray-600 dark:text-gray-400">
|
|
21
21
|
Thanks for signing up! Before getting started, could you verify your email address by clicking on the link we
|
|
@@ -30,7 +30,7 @@ export default function VerifyEmail({ status }: { status?: string }) {
|
|
|
30
30
|
|
|
31
31
|
<form onSubmit={submit}>
|
|
32
32
|
<div className="mt-4 flex items-center justify-between">
|
|
33
|
-
<Button disabled={processing}>Resend
|
|
33
|
+
<Button disabled={processing}>Resend verification email</Button>
|
|
34
34
|
|
|
35
35
|
<Link
|
|
36
36
|
href={logout_path()}
|
|
@@ -38,7 +38,7 @@ export default function VerifyEmail({ status }: { status?: string }) {
|
|
|
38
38
|
as="button"
|
|
39
39
|
className="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800"
|
|
40
40
|
>
|
|
41
|
-
Log
|
|
41
|
+
Log out
|
|
42
42
|
</Link>
|
|
43
43
|
</div>
|
|
44
44
|
</form>
|
|
@@ -55,7 +55,7 @@ export default function DeleteUserForm({ className = '' }: { className?: string
|
|
|
55
55
|
return (
|
|
56
56
|
<section className={`space-y-6 ${className}`}>
|
|
57
57
|
<Button variant="destructive" onClick={confirmUserDeletion}>
|
|
58
|
-
Delete
|
|
58
|
+
Delete account
|
|
59
59
|
</Button>
|
|
60
60
|
|
|
61
61
|
<Dialog open={confirmingUserDeletion} onOpenChange={(open) => !open && closeModal()}>
|
|
@@ -96,7 +96,7 @@ export default function DeleteUserForm({ className = '' }: { className?: string
|
|
|
96
96
|
</Button>
|
|
97
97
|
|
|
98
98
|
<Button variant="destructive" disabled={processing}>
|
|
99
|
-
Delete
|
|
99
|
+
Delete account
|
|
100
100
|
</Button>
|
|
101
101
|
</DialogFooter>
|
|
102
102
|
</form>
|
|
@@ -41,7 +41,7 @@ export default function UpdatePasswordForm({ className = '' }: { className?: str
|
|
|
41
41
|
<section className={className}>
|
|
42
42
|
<form onSubmit={updatePassword} className="space-y-6">
|
|
43
43
|
<div>
|
|
44
|
-
<Label htmlFor="current_password">Current
|
|
44
|
+
<Label htmlFor="current_password">Current password</Label>
|
|
45
45
|
|
|
46
46
|
<Input
|
|
47
47
|
id="current_password"
|
|
@@ -57,7 +57,7 @@ export default function UpdatePasswordForm({ className = '' }: { className?: str
|
|
|
57
57
|
</div>
|
|
58
58
|
|
|
59
59
|
<div>
|
|
60
|
-
<Label htmlFor="password">New
|
|
60
|
+
<Label htmlFor="password">New password</Label>
|
|
61
61
|
|
|
62
62
|
<Input
|
|
63
63
|
id="password"
|
|
@@ -73,7 +73,7 @@ export default function UpdatePasswordForm({ className = '' }: { className?: str
|
|
|
73
73
|
</div>
|
|
74
74
|
|
|
75
75
|
<div>
|
|
76
|
-
<Label htmlFor="password_confirmation">Confirm
|
|
76
|
+
<Label htmlFor="password_confirmation">Confirm password</Label>
|
|
77
77
|
|
|
78
78
|
<Input
|
|
79
79
|
id="password_confirmation"
|