mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-05 05:05:17 +02:00
Update visit count and password hashing
This commit is contained in:
parent
549840128f
commit
70e23b8878
3 changed files with 22 additions and 3 deletions
|
@ -20,8 +20,6 @@ export async function GET(event: RequestEvent): Promise<Response> {
|
||||||
.where(eq(userVisitedAdventures.userId,event.locals.user.id))
|
.where(eq(userVisitedAdventures.userId,event.locals.user.id))
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
console.log(result[0].count);
|
|
||||||
|
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
visitCount: result[0].count,
|
visitCount: result[0].count,
|
||||||
|
|
|
@ -3,6 +3,7 @@ import type { PageServerLoad } from "./$types";
|
||||||
import { db } from "$lib/db/db.server";
|
import { db } from "$lib/db/db.server";
|
||||||
import { userTable } from "$lib/db/schema";
|
import { userTable } from "$lib/db/schema";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
|
import { Argon2id } from "oslo/password";
|
||||||
|
|
||||||
export const load: PageServerLoad = async (event) => {
|
export const load: PageServerLoad = async (event) => {
|
||||||
if (event.locals.user)
|
if (event.locals.user)
|
||||||
|
@ -20,6 +21,8 @@ export const actions: Actions = {
|
||||||
let firstName = formData.get("first_name");
|
let firstName = formData.get("first_name");
|
||||||
let lastName = formData.get("last_name");
|
let lastName = formData.get("last_name");
|
||||||
|
|
||||||
|
let password = formData.get("password");
|
||||||
|
|
||||||
if (!userId) {
|
if (!userId) {
|
||||||
return {
|
return {
|
||||||
status: 400,
|
status: 400,
|
||||||
|
@ -29,6 +32,16 @@ export const actions: Actions = {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (password) {
|
||||||
|
let hashedPassword = await new Argon2id().hash(password);
|
||||||
|
console.log(hashedPassword)
|
||||||
|
await db.update(userTable)
|
||||||
|
.set({
|
||||||
|
hashed_password: hashedPassword
|
||||||
|
})
|
||||||
|
.where(eq(userTable.id, userId));
|
||||||
|
}
|
||||||
|
|
||||||
await db.update(userTable)
|
await db.update(userTable)
|
||||||
.set({
|
.set({
|
||||||
username: username,
|
username: username,
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
id="username"
|
id="username"
|
||||||
class="block mb-2 input input-bordered w-full max-w-xs"
|
class="block mb-2 input input-bordered w-full max-w-xs"
|
||||||
/><br />
|
/><br />
|
||||||
<label for="password">First Name</label>
|
<label for="first_name">First Name</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
bind:value={first_name}
|
bind:value={first_name}
|
||||||
|
@ -29,6 +29,7 @@
|
||||||
id="first_name"
|
id="first_name"
|
||||||
class="block mb-2 input input-bordered w-full max-w-xs"
|
class="block mb-2 input input-bordered w-full max-w-xs"
|
||||||
/><br />
|
/><br />
|
||||||
|
<label for="last_name">Last Name</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
bind:value={last_name}
|
bind:value={last_name}
|
||||||
|
@ -36,6 +37,13 @@
|
||||||
id="last_name"
|
id="last_name"
|
||||||
class="block mb-2 input input-bordered w-full max-w-xs"
|
class="block mb-2 input input-bordered w-full max-w-xs"
|
||||||
/><br />
|
/><br />
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
name="password"
|
||||||
|
id="password"
|
||||||
|
class="block mb-2 input input-bordered w-full max-w-xs"
|
||||||
|
/><br />
|
||||||
<!-- make hidden input where the user id is -->
|
<!-- make hidden input where the user id is -->
|
||||||
<input
|
<input
|
||||||
type="hidden"
|
type="hidden"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue