Changing password name.

This commit is contained in:
Bradley Shellnut 2024-10-03 16:19:36 -07:00
parent 40c6d82e37
commit 7aa17d8c7d
6 changed files with 57 additions and 8 deletions

8
.run/BoredGame.run.xml Normal file
View file

@ -0,0 +1,8 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="BoredGame" type="NodeJSConfigurationType" path-to-js-file="node_modules/vite/bin/vite.js" typescript-loader="bundled" working-dir="$PROJECT_DIR$">
<envs>
<env name="NODE_ENV" value="development" />
</envs>
<method v="2" />
</configuration>
</component>

View file

@ -0,0 +1,37 @@
<script lang="ts">
import { Button } from '$lib/components/ui/button'
import { toastMessage } from '$lib/utils/superforms' // Adjust the path if necessary
const { codeContent, language }: { codeContent: string; language: string } = $props()
// Function to copy code to clipboard
const copyToClipboard = () => {
navigator.clipboard
.writeText(codeContent)
.then(() => {
toastMessage({ text: 'Copied to clipboard!', type: 'success' })
})
.catch((err) => {
console.error('Failed to copy: ', err)
})
}
</script>
{#if codeContent}
<div class="code-container">
<code data-language={language}>
<span>
{codeContent}
</span>
</code>
<Button class="copy-button" on:click={copyToClipboard}>Copy</Button>
</div>
{/if}
<style lang="postcss">
.code-container {
display: flex;
gap: var(--spacing-8);
margin-top: var(--spacing-24);
}
</style>

View file

@ -3,8 +3,8 @@ import { Button } from '$components/ui/button'
import { boredState } from '$lib/stores/boredState'
import { gameStore } from '$lib/stores/gameSearchStore'
import type { SearchSchema } from '$lib/zodValidation'
import type { SuperValidated } from 'sveltekit-superforms'
import { superForm } from 'sveltekit-superforms/client'
import type { SuperValidated } from 'sveltekit-superforms/index'
export let data: SuperValidated<SearchSchema>
const { enhance } = superForm(data, {

View file

@ -47,6 +47,6 @@ export class TotpService {
if (!credential) {
throw new Error('TOTP credential not found')
}
return await verifyTOTP(decodeHex(credential.secret_data), 30, 6, code)
return verifyTOTP(decodeHex(credential.secret_data), 30, 6, code)
}
}

View file

@ -70,7 +70,7 @@ export const load: PageServerLoad = async (event) => {
const totpUri = createTOTPKeyURI(issuer, accountName, decodedHexSecret, intervalInSeconds, digits)
addTwoFactorForm.data = {
current_password: '',
password: '',
two_factor_code: '',
}
return {
@ -109,7 +109,7 @@ export const actions: Actions = {
if (verifyPasswordError) {
console.log(verifyPasswordError)
return setError(addTwoFactorForm, 'current_password', 'Your password is incorrect')
return setError(addTwoFactorForm, 'password', 'Your password is incorrect')
}
if (addTwoFactorForm.data.two_factor_code === '') {
@ -151,7 +151,7 @@ export const actions: Actions = {
if (verifyPasswordError) {
console.log(verifyPasswordError)
return setError(removeTwoFactorForm, 'current_password', 'Your password is incorrect')
return setError(removeTwoFactorForm, 'password', 'Your password is incorrect')
}
const { error: deleteTotpError } = await locals.api.mfa.totp.$delete().then(locals.parseApiResponse)

View file

@ -1,4 +1,5 @@
<script lang="ts">
import CopyCodeBlock from '$components/CopyCodeBlock.svelte'
import PinInput from '$components/pin-input.svelte'
import * as Alert from '$components/ui/alert'
import * as Form from '$components/ui/form'
@ -39,7 +40,7 @@ const { form: removeTwoFactorFormData, enhance: removeTwoFactorEnhance } = remov
<h2>Currently you have two factor authentication <span class="text-green-500">enabled</span></h2>
<p>To disable two factor authentication, please enter your current password.</p>
<form method="POST" action="?/disableTotp" use:removeTwoFactorEnhance data-sveltekit-replacestate>
<Form.Field form={removeTwoFactorForm} name="current_password">
<Form.Field form={removeTwoFactorForm} name="password">
<Form.Control let:attrs>
<Form.Label for="password">Current Password</Form.Label>
<Input type="password" {...attrs} bind:value={$removeTwoFactorFormData.password} autocomplete="password" />
@ -61,7 +62,7 @@ const { form: removeTwoFactorFormData, enhance: removeTwoFactorEnhance } = remov
<Form.Description>This is the code from your authenticator app.</Form.Description>
<Form.FieldErrors />
</Form.Field>
<Form.Field form={addTwoFactorForm} name="current_password">
<Form.Field form={addTwoFactorForm} name="password">
<Form.Control let:attrs>
<Form.Label for="password">Enter Password</Form.Label>
<Input type="password" {...attrs} bind:value={$addTwoFactorFormData.password} autocomplete="password" />
@ -71,7 +72,10 @@ const { form: removeTwoFactorFormData, enhance: removeTwoFactorEnhance } = remov
</Form.Field>
<Form.Button>Submit</Form.Button>
</form>
<span>Secret: {secret}</span>
<div class="mt-4">
<p>Secret:</p>
<CopyCodeBlock codeContent={secret || ''} language="text" />
</div>
{/if}
</section>