Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"type": "module",
"scripts": {
"start": "tsx src/index.ts",
"dev": "sudo tsx watch --exclude './data/**/*' --clear-screen=false ./src/index.ts"
"dev": "sudo tsx watch --exclude './data/**/*' --clear-screen=false ./src/index.ts",
"dev-wsl": "npx tsx watch --exclude './data/**/*' --clear-screen=false ./src/index.ts"
},
"author": "Keukeiland, Fizitzfux",
"license": "MPL-2.0",
Expand Down
33 changes: 32 additions & 1 deletion src/extensions/admin/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
{% extends "extension.html" %}

{% block head %}
<link href="/admin/index.css" rel="stylesheet">
{% endblock %}


{% block body %}
<h3>This page is currently under development and will be available soon!</h3>
<table id="user_table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Registration Date</th>
<th>Is Admin</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for info in user_info %}
<tr>
<td>{{info.id}}</td>
<td>{{info.name}}</td>
<td>{{info.registration_date}}</td>
<td>{{"Yes" if info.is_admin else "No"}}</td>
<td class="actionCells">
<a href="/admin/toggle_admin?id={{info.id}}" class="button">{{"Remove Admin" if info.is_admin else "Make Admin"}}</a>
<a href="/admin/remove_account?id={{info.id}}" class="button">Remove Account</a>
</td>
</tr>
{% else %}
<p>No users</p>
{% endfor %}
</tbody>
</table>
{% endblock %}
55 changes: 52 additions & 3 deletions src/extensions/admin/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,60 @@
import { ExtensionBase } from "../../modules.ts"
import { ExtensionBase, Knex } from '../../modules.ts'
import { unpack } from '../../util.ts'

export default class extends ExtensionBase {
override name = 'admin'
override title = 'Admin'
override admin_only = true

override handle: Extension['handle'] = (ctx) => {
this.return_html(ctx, 'index')
user_info: {id: any, username: any, reg_date: any, admin: any}[] = []
sortingType = "id"

override handle: Extension['handle'] = async (ctx) => {
let [knex]: [Knex] = this.get_dependencies('Knex')
var location = ctx.path.shift()

switch (location) {
case '':
case undefined:{
var [user_list, err] = await knex
.query('user')
.select<User[]>('*')
.then(unpack<User[]>)

ctx.context.user_info = user_list
return this.return_html(ctx, 'index', err)
}
case 'toggle_admin':{
var id = ctx.args.get("id")

var [user, err] = await knex
.query('user')
.select<User>('*')
.where('id', id)
.first()
.then(unpack<User>)

await knex
.query('user')
.update('is_admin', !user?.is_admin)
.where('id', id)

return this.return(ctx, undefined, location='/admin')
}
case 'remove_account':{
var id = ctx.args.get("id")

await knex
.query('user')
.where('id', id)
.delete('*')

return this.return(ctx, undefined, location='/admin')
}
default: {
return this.return_file(ctx, location)
}
}

}
}
23 changes: 23 additions & 0 deletions src/extensions/admin/static/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#user_table{
border-collapse: collapse;
margin: 10px, 0;
}

#user_table thead tr{
text-align: center;
font-weight: bold;
}

#user_table tbody tr{
text-align: center;
border-bottom: 1px black;
}

#user_table tbody tr:nth-of-type(even){
background-color: rgb(192, 192, 192);
}

#user_table th,
#user_table td{
padding: 6px 8px;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please end all files with a newline.

Won't block merging on this though.

2 changes: 1 addition & 1 deletion src/extensions/root/user.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h1>Hello {{user.name}}!</h1>
<a href="/_/pfp" class="button">Edit</a>
<a href="/logout" class="button">Logout</a>
<a href="/~getting-started" class="button">Get started</a>
<p>You registered at {{user.regdate}}</p>
<p>You registered at {{user.registration_date}}</p>
</section>

{% endblock %}
2 changes: 1 addition & 1 deletion types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ declare type User = {
id: number,
name: string,
password: string,
regdate: Date,
registration_date: Date,
is_admin: boolean,
pfp_code: string
}
Expand Down