mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-21 21:36:26 -08:00
adminopts
This commit is contained in:
parent
38dd9e9c57
commit
abedda18e3
|
@ -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 )
|
||||
|
||||
})
|
40
src/svelte/elem/prompts/admin.js
Normal file
40
src/svelte/elem/prompts/admin.js
Normal 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}`,[])
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue