[web] Generate team passwords

This commit is contained in:
orosmatthew 2023-05-08 15:11:06 -04:00
parent f8c81206d8
commit 1582e7a480
5 changed files with 21 additions and 4 deletions

View File

@ -1 +0,0 @@
export const csr = false;

View File

@ -27,7 +27,7 @@ export const load = (async ({ params }) => {
'expected', 'expected',
'actual', 'actual',
problem.realOutput, problem.realOutput,
submission.actualOutput submission.actualOutput!
); );
} }

View File

@ -1,5 +1,6 @@
import { db } from '$lib/server/prisma'; import { db } from '$lib/server/prisma';
import type { Actions, PageServerLoad } from './$types'; import type { Actions, PageServerLoad } from './$types';
import { genPassword } from './util';
export const load = (async () => { export const load = (async () => {
const teams = await db.team.findMany(); const teams = await db.team.findMany();
@ -18,7 +19,7 @@ export const actions = {
return { success: false }; return { success: false };
} }
try { try {
await db.team.create({ data: { name: name.toString(), password: "thing" } }); await db.team.create({ data: { name: name.toString(), password: genPassword() } });
} catch { } catch {
return { success: false }; return { success: false };
} }

View File

@ -1,5 +1,6 @@
<script lang="ts"> <script lang="ts">
import { enhance } from '$app/forms'; import { enhance } from '$app/forms';
import { genPassword } from '../util';
import type { Actions, PageData } from './$types'; import type { Actions, PageData } from './$types';
export let data: PageData; export let data: PageData;
@ -10,6 +11,11 @@
$: if (form && form.success) { $: if (form && form.success) {
changingPassword = false; changingPassword = false;
} }
function onGenPassword() {
const passEntry = document.getElementById('pass_entry') as HTMLInputElement;
passEntry.value = genPassword();
}
</script> </script>
<svelte:head> <svelte:head>
@ -72,7 +78,7 @@
{:else} {:else}
<form method="POST" action="?/password" use:enhance> <form method="POST" action="?/password" use:enhance>
<h4>Change Password</h4> <h4>Change Password</h4>
<input name="password" class="form-control" /> <input id="pass_entry" name="password" class="form-control" />
<div class="mt-2 row"> <div class="mt-2 row">
<div class="text-end"> <div class="text-end">
<button <button
@ -82,6 +88,9 @@
type="button" type="button"
class="btn btn-outline-secondary">Cancel</button class="btn btn-outline-secondary">Cancel</button
> >
<button on:click={onGenPassword} type="button" class="btn btn-outline-primary"
>Generate</button
>
<button type="submit" class="btn btn-success">Change</button> <button type="submit" class="btn btn-success">Change</button>
</div> </div>
</div> </div>

View File

@ -0,0 +1,8 @@
export function genPassword(): string {
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
let password = '';
for (let i = 0; i < 8; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}