-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Database.TS moved to lib/server for security - Added a footer - Used +layout to ensure cookies are set - Finished /admin/events, and /admin/events/create - Fixed broken Favicon
- Loading branch information
Showing
16 changed files
with
301 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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
Empty file.
This file contains 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 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,9 @@ | ||
<script lang="ts"> | ||
import Cspp from "$lib/assets/cspp-thumb.png"; | ||
</script> | ||
|
||
<slot></slot> | ||
|
||
<footer> | ||
Created with ❤️ (and Svelte) by <img class="footerimg" src={Cspp} alt="The CS++ Logo"> | ||
</footer> |
This file contains 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,18 @@ | ||
import { redirect } from '@sveltejs/kit'; | ||
import type { LayoutServerLoad } from './$types'; | ||
|
||
export const load: LayoutServerLoad = async ({ request, cookies }) => { | ||
let rawURL = request.url; | ||
let url = new URL(rawURL); | ||
let path = url.pathname; | ||
|
||
// Check if admin cookie is set | ||
if (cookies.get('admin') !== 'true' && path !== "/admin") { | ||
throw redirect(301, "/admin") | ||
} | ||
else{ | ||
return{ | ||
loggedIn: true | ||
} | ||
} | ||
} |
This file contains 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 @@ | ||
<slot></slot> |
This file contains 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 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 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,24 @@ | ||
import type { PageServerLoad } from './$types'; | ||
import pg from 'pg'; | ||
const { Pool } = pg; | ||
|
||
// Read in info from .env file | ||
import { config } from 'dotenv'; | ||
config(); | ||
|
||
const pool = new Pool({ | ||
connectionString: process.env.DATABASE_URL | ||
}); | ||
|
||
export const load = (async () => { | ||
// Get a list of all events | ||
const events = await pool.query(` | ||
SELECT * | ||
FROM events | ||
`); | ||
|
||
return { | ||
status: 200, | ||
events: events.rows | ||
}; | ||
}) satisfies PageServerLoad; |
This file contains 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,83 @@ | ||
<script lang="ts"> | ||
import type { PageData } from './$types'; | ||
export let data: PageData; | ||
export let eventView = (id: string) => { | ||
window.location.href = "/admin/events/" + id; | ||
}, | ||
eventRemove = (id: string) => { | ||
let confirmation = confirm("Are you sure you want to delete this event?"); | ||
if(confirmation){ | ||
window.location.href = "/admin/events/remove/" + id; | ||
} | ||
} | ||
</script> | ||
|
||
<head> | ||
<title>BitHunt [🛡️] - Events</title> | ||
</head> | ||
|
||
<h1 class="title large">Events</h1> | ||
|
||
<div class="buttons"> | ||
<button class="cspp" on:click={() => window.location.href = "/admin"}> | ||
<i class="fa fa-arrow-left"></i> | ||
Go Back | ||
</button> | ||
<button class="cspp" on:click={() => window.location.href = "/admin/events/create"}> | ||
<i class="fa fa-calendar-plus-o"></i> | ||
Add New | ||
</button> | ||
</div> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Date</th> | ||
<th>Location</th> | ||
<th>Description</th> | ||
<th>Prize</th> | ||
<th>Prize Count</th> | ||
<th>Status</th> | ||
<th>Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{#each data.events as event} | ||
<tr> | ||
<td>{event.name}</td> | ||
<td>{event.date}</td> | ||
<td>{event.location}</td> | ||
<td>{event.description}</td> | ||
<td>{event.prize}</td> | ||
<td>{event.prizecount}</td> | ||
<td>{event.status}</td> | ||
<td> | ||
<div class="actions"> | ||
<button class="action " on:click={() => eventView(event.id)}> | ||
<i class="fa fa-eye"></i> | ||
</button> | ||
<button class="action" on:click={() => eventRemove(event.id)}> | ||
<i class="fa fa-trash"></i> | ||
</button> | ||
</div> | ||
</td> | ||
</tr> | ||
{/each} | ||
|
||
{#if data.events.length == 0} | ||
<tr> | ||
<td colspan="8">No events found.</td> | ||
</tr> | ||
{/if} | ||
</tbody> | ||
</table> |
This file contains 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,42 @@ | ||
import { redirect } from '@sveltejs/kit'; | ||
import type { Actions } from './$types'; | ||
import pg from 'pg'; | ||
const { Pool } = pg; | ||
|
||
// Read in info from .env file | ||
import { config } from 'dotenv'; | ||
config(); | ||
|
||
const pool = new Pool({ | ||
connectionString: process.env.DATABASE_URL | ||
}); | ||
|
||
export const actions = { | ||
default: async ({cookies, request}) => { | ||
let reqData = await request.formData(); | ||
// Returns as format: | ||
// FormData { | ||
// 'name' => "string", | ||
// 'date' => "string", | ||
// 'location' => "string", | ||
// 'description' => "string", | ||
// 'prize' => "string", | ||
// 'prizeCount' => "number", | ||
// 'status' => "string", | ||
|
||
// Change Status to boolean | ||
let status = reqData.get('status') === "true" ? true : false; | ||
|
||
// Add to database | ||
await pool.query( | ||
'INSERT INTO events (name, date, location, description, prize, prizeCount, active) VALUES ($1, $2, $3, $4, $5, $6, $7)', | ||
[reqData.get('name'), reqData.get('date'), reqData.get('location'), reqData.get('description'), reqData.get('prize'), reqData.get('prizeCount'), status] | ||
); | ||
|
||
return{ | ||
status: 200, | ||
message: reqData.get('name') + " created successfully" | ||
} | ||
|
||
} | ||
} satisfies Actions; |
This file contains 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,86 @@ | ||
<script lang="ts"> | ||
import type { ActionData } from './$types'; | ||
import Toasts from "$lib/toasts/Toasts.svelte"; | ||
import { addToast } from "$lib/toasts/store.js"; | ||
export let form: ActionData; | ||
let date = new Date().toISOString().slice(0, 10); | ||
// Create toast | ||
if(form?.status == 200){ | ||
addToast({ | ||
type: "success", | ||
message: form?.message, | ||
dismissible: true, | ||
timeout: 5000 | ||
}) | ||
} | ||
</script> | ||
|
||
<head> | ||
<title>BitHunt [🛡️] - Create Event</title> | ||
</head> | ||
|
||
<Toasts /> | ||
|
||
<h1 class="title large">Create an Event</h1> | ||
|
||
<button class="cspp form-element" on:click={() => window.location.href = "/admin/events"}> | ||
<i class="fa fa-arrow-left"></i> | ||
Back | ||
</button> | ||
|
||
<form method="post"> | ||
<label for="name"> | ||
Name | ||
<span class="required">*</span> | ||
</label> | ||
<input type="text" name="name" id="name" placeholder="Event Name" required> | ||
|
||
<label for="date"> | ||
Date | ||
<span class="required">*</span> | ||
</label> | ||
<input type="date" name="date" id="date" bind:value={date} required> | ||
|
||
<label for="location"> | ||
Location | ||
<span class="required">*</span> | ||
</label> | ||
<input type="text" name="location" id="location" placeholder="Event Location" required> | ||
|
||
<label for="description"> | ||
Description | ||
<span class="required">*</span> | ||
</label> | ||
<textarea name="description" id="description" placeholder="Event Description" required></textarea> | ||
|
||
<label for="prize"> | ||
Prize | ||
<span class="required">*</span> | ||
</label> | ||
<input type="text" name="prize" id="prize" placeholder="Event Prize" required> | ||
|
||
<label for="prizeCount"> | ||
Prize Count | ||
<span class="required">*</span> | ||
</label> | ||
<input type="number" name="prizeCount" id="prizeCount" placeholder="Event Prize Count" required> | ||
|
||
<label for="status"> | ||
Status | ||
<span class="required">*</span> | ||
</label> | ||
<select name="status" id="status" required> | ||
<option value="false">Inactive</option> | ||
<option value="true">Active</option> | ||
</select> | ||
|
||
<button type="submit" class="cspp form-element primary"> | ||
<i class="fa fa-calendar-plus-o"></i> | ||
Create Event | ||
</button> | ||
|
||
</form> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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