adminopts

This commit is contained in:
split / May 2023-06-28 21:57:13 -07:00
parent 38dd9e9c57
commit abedda18e3
3 changed files with 68 additions and 1 deletions

View file

@ -34,3 +34,29 @@ adminRoutes.post("/manage", parser, (req,res) => {
if (!acc.admin) return
})
adminRoutes.post("/reset", parser, (req,res) => {
if (!auth.validate(req.cookies.auth)) {
ServeError(res, 401, "not logged in")
return
}
let acc = Accounts.getFromToken(req.cookies.auth) as Accounts.Account
if (!acc) return
if (!acc.admin) return
if (typeof req.body.target !== "string" || typeof req.body.password !== "string" || !req.body.password) {
res.status(404)
return
}
let targetAccount = Accounts.getFromUsername(req.body.target)
if (!targetAccount) {
res.status(404)
return
}
Accounts.password.set ( targetAccount.id, req.body.password )
})

View file

@ -0,0 +1,40 @@
import { fetchAccountData, fetchFilePointers, account } from "../stores.mjs"
import { get } from "svelte/store";
export function pwdReset(optPicker) {
optPicker.picker("Reset password",[
{
name: "Target user",
icon: "/static/assets/icons/person.svg",
id: "target",
inputSettings: {}
},
{
name: "New password",
icon: "/static/assets/icons/change_password.svg",
id: "password",
inputSettings: {
password: true
}
},
{
name: "Update password",
icon: "/static/assets/icons/update.svg",
description: "This will log the target user out of all sessions",
id: true
}
]).then((exp) => {
if (exp && exp.selected) {
fetch(`/admin/reset`,{method:"POST", body:JSON.stringify({
target: exp.target,
password:exp.password
})}).then((response) => {
if (response.status != 200) {
optPicker.picker(`${response.status} ${response.statusText}`,[])
}
})
}
})
}

View file

@ -7,6 +7,7 @@
import OptionPicker from "../prompts/OptionPicker.svelte";
import * as accOpts from "../prompts/account";
import * as uplOpts from "../prompts/uploads";
import * as admOpts from "../prompts/admin";
let targetAction
let inProgress
@ -185,7 +186,7 @@
<p>Delete user account</p>
</button>
<button>
<button on:click={() => admOpts.pwdReset(optPicker)}>
<img src="/static/assets/icons/change_password.svg" alt="change password">
<p>Change user password</p>
</button>