kaze 2.1.1 → 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 +46 -1
- data/README.md +13 -1
- 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/two_factor_challenge.html.erb +21 -0
- data/stubs/hotwire/app/views/layouts/_settings.html.erb +1 -0
- 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/TwoFactorChallenge.tsx +71 -0
- 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/TwoFactorChallenge.vue +60 -0
- data/stubs/inertia-vue-ts/app/javascript/Pages/Settings/TwoFactor.vue +147 -0
- metadata +27 -1
|
@@ -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(),
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { Head, useForm } from '@inertiajs/react'
|
|
2
|
+
import { FormEventHandler } from 'react'
|
|
3
|
+
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
|
|
4
|
+
import SettingsLayout from '@/Layouts/SettingsLayout'
|
|
5
|
+
import Heading from '@/Components/Heading'
|
|
6
|
+
import InputError from '@/Components/InputError'
|
|
7
|
+
import { Button } from '@/Components/ui/button'
|
|
8
|
+
import { Input } from '@/Components/ui/input'
|
|
9
|
+
import { Label } from '@/Components/ui/label'
|
|
10
|
+
import {
|
|
11
|
+
two_factor_destroy_path,
|
|
12
|
+
two_factor_edit_path,
|
|
13
|
+
two_factor_recovery_codes_path,
|
|
14
|
+
two_factor_store_path,
|
|
15
|
+
two_factor_update_path,
|
|
16
|
+
} from '@/routes'
|
|
17
|
+
import { BreadcrumbItem } from '@/types'
|
|
18
|
+
|
|
19
|
+
const breadcrumbs: BreadcrumbItem[] = [
|
|
20
|
+
{
|
|
21
|
+
title: 'Two factor settings',
|
|
22
|
+
href: two_factor_edit_path(),
|
|
23
|
+
},
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
type Props = {
|
|
27
|
+
enabled: boolean
|
|
28
|
+
pending: boolean
|
|
29
|
+
qrCode: string | null
|
|
30
|
+
secret: string | null
|
|
31
|
+
recoveryCodes: string[]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default function TwoFactor({ enabled, pending, qrCode, secret, recoveryCodes }: Props) {
|
|
35
|
+
return (
|
|
36
|
+
<AuthenticatedLayout breadcrumbs={breadcrumbs}>
|
|
37
|
+
<Head title="Two factor settings" />
|
|
38
|
+
|
|
39
|
+
<SettingsLayout>
|
|
40
|
+
<div className="space-y-6">
|
|
41
|
+
<Heading
|
|
42
|
+
variant="small"
|
|
43
|
+
title="Two factor authentication"
|
|
44
|
+
description="Add a second step to signing in, using an authenticator app"
|
|
45
|
+
/>
|
|
46
|
+
|
|
47
|
+
{enabled ? (
|
|
48
|
+
<Enabled recoveryCodes={recoveryCodes} />
|
|
49
|
+
) : pending ? (
|
|
50
|
+
<Confirming qrCode={qrCode} secret={secret} />
|
|
51
|
+
) : (
|
|
52
|
+
<Disabled />
|
|
53
|
+
)}
|
|
54
|
+
</div>
|
|
55
|
+
</SettingsLayout>
|
|
56
|
+
</AuthenticatedLayout>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function Disabled() {
|
|
61
|
+
const { post, processing } = useForm({})
|
|
62
|
+
|
|
63
|
+
const submit: FormEventHandler = (e) => {
|
|
64
|
+
e.preventDefault()
|
|
65
|
+
|
|
66
|
+
post(two_factor_store_path())
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<>
|
|
71
|
+
<p className="text-sm text-muted-foreground">
|
|
72
|
+
Two factor authentication is off. Turn it on and you will be asked for a code from your authenticator app each
|
|
73
|
+
time you sign in.
|
|
74
|
+
</p>
|
|
75
|
+
|
|
76
|
+
<form onSubmit={submit}>
|
|
77
|
+
<Button disabled={processing}>Turn on two factor authentication</Button>
|
|
78
|
+
</form>
|
|
79
|
+
</>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function Confirming({ qrCode, secret }: { qrCode: string | null; secret: string | null }) {
|
|
84
|
+
const { data, setData, patch, processing, errors } = useForm({ code: '' })
|
|
85
|
+
|
|
86
|
+
const submit: FormEventHandler = (e) => {
|
|
87
|
+
e.preventDefault()
|
|
88
|
+
|
|
89
|
+
patch(two_factor_update_path())
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<>
|
|
94
|
+
<p className="text-sm text-muted-foreground">
|
|
95
|
+
Scan this with your authenticator app, then enter the code it shows to finish turning it on.
|
|
96
|
+
</p>
|
|
97
|
+
|
|
98
|
+
{qrCode && (
|
|
99
|
+
<div
|
|
100
|
+
className="w-44 rounded-lg border border-sidebar-border/70 bg-white p-2 dark:border-sidebar-border"
|
|
101
|
+
dangerouslySetInnerHTML={{ __html: qrCode }}
|
|
102
|
+
/>
|
|
103
|
+
)}
|
|
104
|
+
|
|
105
|
+
<p className="text-sm text-muted-foreground">
|
|
106
|
+
Cannot scan it? Enter this key instead:{' '}
|
|
107
|
+
<code className="rounded bg-muted px-1.5 py-0.5 font-mono text-xs text-foreground">{secret}</code>
|
|
108
|
+
</p>
|
|
109
|
+
|
|
110
|
+
<form onSubmit={submit} className="space-y-6">
|
|
111
|
+
<div>
|
|
112
|
+
<Label htmlFor="code">Code</Label>
|
|
113
|
+
|
|
114
|
+
<Input
|
|
115
|
+
id="code"
|
|
116
|
+
name="code"
|
|
117
|
+
value={data.code}
|
|
118
|
+
className="mt-1 block w-full max-w-xs"
|
|
119
|
+
inputMode="numeric"
|
|
120
|
+
autoComplete="one-time-code"
|
|
121
|
+
autoFocus
|
|
122
|
+
onChange={(e) => setData('code', e.target.value)}
|
|
123
|
+
/>
|
|
124
|
+
|
|
125
|
+
<InputError message={errors.code} className="mt-2" />
|
|
126
|
+
</div>
|
|
127
|
+
|
|
128
|
+
<Button disabled={processing}>Confirm</Button>
|
|
129
|
+
</form>
|
|
130
|
+
</>
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function Enabled({ recoveryCodes }: { recoveryCodes: string[] }) {
|
|
135
|
+
const regenerate = useForm({})
|
|
136
|
+
const disable = useForm({ password: '' })
|
|
137
|
+
|
|
138
|
+
const submitRegenerate: FormEventHandler = (e) => {
|
|
139
|
+
e.preventDefault()
|
|
140
|
+
|
|
141
|
+
regenerate.post(two_factor_recovery_codes_path())
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const submitDisable: FormEventHandler = (e) => {
|
|
145
|
+
e.preventDefault()
|
|
146
|
+
|
|
147
|
+
disable.delete(two_factor_destroy_path())
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<>
|
|
152
|
+
<p className="text-sm text-muted-foreground">
|
|
153
|
+
Two factor authentication is on. You will be asked for a code each time you sign in.
|
|
154
|
+
</p>
|
|
155
|
+
|
|
156
|
+
<div className="space-y-3 rounded-xl border border-sidebar-border/70 p-4 dark:border-sidebar-border">
|
|
157
|
+
<div className="text-sm font-medium">Recovery codes</div>
|
|
158
|
+
|
|
159
|
+
<p className="text-sm text-muted-foreground">
|
|
160
|
+
Keep these somewhere safe. Each one can be used once to sign in if you cannot reach your authenticator app.
|
|
161
|
+
</p>
|
|
162
|
+
|
|
163
|
+
<ul className="grid grid-cols-2 gap-1 font-mono text-xs">
|
|
164
|
+
{recoveryCodes.map((recoveryCode) => (
|
|
165
|
+
<li key={recoveryCode}>{recoveryCode}</li>
|
|
166
|
+
))}
|
|
167
|
+
</ul>
|
|
168
|
+
|
|
169
|
+
<form onSubmit={submitRegenerate}>
|
|
170
|
+
<Button variant="outline" disabled={regenerate.processing}>
|
|
171
|
+
Generate new codes
|
|
172
|
+
</Button>
|
|
173
|
+
</form>
|
|
174
|
+
</div>
|
|
175
|
+
|
|
176
|
+
<form onSubmit={submitDisable} className="space-y-6">
|
|
177
|
+
<div>
|
|
178
|
+
<Label htmlFor="password">Current password</Label>
|
|
179
|
+
|
|
180
|
+
<Input
|
|
181
|
+
id="password"
|
|
182
|
+
type="password"
|
|
183
|
+
name="password"
|
|
184
|
+
value={disable.data.password}
|
|
185
|
+
className="mt-1 block w-full max-w-xs"
|
|
186
|
+
autoComplete="current-password"
|
|
187
|
+
onChange={(e) => disable.setData('password', e.target.value)}
|
|
188
|
+
/>
|
|
189
|
+
|
|
190
|
+
<InputError message={disable.errors.password} className="mt-2" />
|
|
191
|
+
</div>
|
|
192
|
+
|
|
193
|
+
<Button variant="destructive" disabled={disable.processing}>
|
|
194
|
+
Turn off two factor authentication
|
|
195
|
+
</Button>
|
|
196
|
+
</form>
|
|
197
|
+
</>
|
|
198
|
+
)
|
|
199
|
+
}
|
|
@@ -4,7 +4,7 @@ import Heading from '@/Components/Heading.vue'
|
|
|
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(),
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import GuestLayout from '@/Layouts/GuestLayout.vue'
|
|
3
|
+
import { Button } from '@/Components/ui/button'
|
|
4
|
+
import { Input } from '@/Components/ui/input'
|
|
5
|
+
import { Label } from '@/Components/ui/label'
|
|
6
|
+
import InputError from '@/Components/InputError.vue'
|
|
7
|
+
import { Head, useForm } from '@inertiajs/vue3'
|
|
8
|
+
import { two_factor_challenge_store_path } from '@/routes'
|
|
9
|
+
|
|
10
|
+
const form = useForm({
|
|
11
|
+
code: '',
|
|
12
|
+
recovery_code: '',
|
|
13
|
+
})
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<GuestLayout>
|
|
18
|
+
<Head title="Two factor authentication" />
|
|
19
|
+
|
|
20
|
+
<div class="mb-4 text-sm text-muted-foreground">
|
|
21
|
+
Enter the code from your authenticator app to finish signing in.
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
<form @submit.prevent="form.post(two_factor_challenge_store_path())">
|
|
25
|
+
<div>
|
|
26
|
+
<Label for="code">Code</Label>
|
|
27
|
+
|
|
28
|
+
<Input
|
|
29
|
+
id="code"
|
|
30
|
+
v-model="form.code"
|
|
31
|
+
name="code"
|
|
32
|
+
class="mt-1 block w-full"
|
|
33
|
+
inputmode="numeric"
|
|
34
|
+
autocomplete="one-time-code"
|
|
35
|
+
autofocus
|
|
36
|
+
/>
|
|
37
|
+
|
|
38
|
+
<InputError :message="form.errors.code" class="mt-2" />
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<div class="mt-4">
|
|
42
|
+
<Label for="recovery_code">Or a recovery code</Label>
|
|
43
|
+
|
|
44
|
+
<Input
|
|
45
|
+
id="recovery_code"
|
|
46
|
+
v-model="form.recovery_code"
|
|
47
|
+
name="recovery_code"
|
|
48
|
+
class="mt-1 block w-full"
|
|
49
|
+
autocomplete="one-time-code"
|
|
50
|
+
/>
|
|
51
|
+
|
|
52
|
+
<InputError :message="form.errors.recovery_code" class="mt-2" />
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
<div class="flex items-center justify-end mt-4">
|
|
56
|
+
<Button class="ms-4" :class="{ 'opacity-25': form.processing }" :disabled="form.processing"> Continue </Button>
|
|
57
|
+
</div>
|
|
58
|
+
</form>
|
|
59
|
+
</GuestLayout>
|
|
60
|
+
</template>
|