-
Notifications
You must be signed in to change notification settings - Fork 257
2FA: require password when disabling #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adrum
wants to merge
3
commits into
laravel:feature/2fa
Choose a base branch
from
adrum:feature/confirm-password
base: feature/2fa
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'; | ||
import { cn } from '@/lib/utils'; | ||
import axios from 'axios'; | ||
import { Lock } from 'lucide-react'; | ||
import { PropsWithChildren, useRef, useState } from 'react'; | ||
import InputError from './input-error'; | ||
import { Button } from './ui/button'; | ||
import { Input } from './ui/input'; | ||
|
||
interface Props { | ||
title?: string; | ||
content?: string; | ||
button?: string; | ||
onConfirm(): void; | ||
} | ||
|
||
export function ConfirmsPassword({ | ||
adrum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
title = 'Confirm Password', | ||
content = 'For your security, please confirm your password to continue.', | ||
button = 'Confirm', | ||
onConfirm, | ||
children, | ||
}: PropsWithChildren<Props>) { | ||
const [confirmingPassword, setConfirmingPassword] = useState(false); | ||
const [form, setForm] = useState({ | ||
adrum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
password: '', | ||
error: '', | ||
processing: false, | ||
}); | ||
const passwordRef = useRef<HTMLInputElement>(null); | ||
|
||
function startConfirmingPassword() { | ||
axios.get(route('password.confirmation')).then((response) => { | ||
if (response.data.confirmed) { | ||
onConfirm(); | ||
} else { | ||
setConfirmingPassword(true); | ||
|
||
setTimeout(() => passwordRef.current?.focus(), 250); | ||
} | ||
}); | ||
} | ||
|
||
function confirmPassword() { | ||
setForm({ ...form, processing: true }); | ||
|
||
axios | ||
.post(route('password.confirm'), { | ||
password: form.password, | ||
}) | ||
.then(() => { | ||
closeModal(); | ||
setTimeout(() => onConfirm(), 250); | ||
}) | ||
.catch((error) => { | ||
setForm({ | ||
...form, | ||
processing: false, | ||
error: error.response.data.errors.password[0], | ||
}); | ||
passwordRef.current?.focus(); | ||
}); | ||
} | ||
|
||
function closeModal() { | ||
setConfirmingPassword(false); | ||
setForm({ processing: false, password: '', error: '' }); | ||
} | ||
|
||
return ( | ||
<> | ||
<Dialog open={confirmingPassword} onOpenChange={setConfirmingPassword}> | ||
<DialogTrigger asChild> | ||
<span onClick={startConfirmingPassword}>{children}</span> | ||
</DialogTrigger> | ||
<DialogContent className="sm:max-w-md"> | ||
<DialogHeader className="flex items-center justify-center"> | ||
<div className="mb-3 w-auto rounded-full border border-stone-100 bg-white p-0.5 shadow-sm dark:border-stone-600 dark:bg-stone-800"> | ||
<div className="relative overflow-hidden rounded-full border border-stone-200 bg-stone-100 p-2.5 dark:border-stone-600 dark:bg-stone-200"> | ||
<Lock className="relative z-20 size-5 dark:text-black" /> | ||
</div> | ||
</div> | ||
<DialogTitle>{title}</DialogTitle> | ||
<DialogDescription className="text-center">{content}</DialogDescription> | ||
</DialogHeader> | ||
|
||
<div className="relative mb-6 flex w-full flex-col items-center justify-center space-y-5"> | ||
<div className="mt-4"> | ||
<Input | ||
ref={passwordRef} | ||
type="password" | ||
className="mt-1 block w-full" | ||
placeholder="Password" | ||
value={form.password} | ||
onChange={(e) => setForm({ ...form, password: e.currentTarget.value })} | ||
/> | ||
<InputError message={form.error} className="mt-2" /> | ||
</div> | ||
</div> | ||
<DialogFooter> | ||
<Button variant="outline" onClick={closeModal}> | ||
Cancel | ||
</Button> | ||
|
||
<Button className={cn('ml-2', { 'opacity-25': form.processing })} onClick={confirmPassword} disabled={form.processing}> | ||
{button} | ||
</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
</> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.