diff options
| author | Adam Soltys <[email protected]> | 2024-02-23 21:03:54 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-02-23 21:03:54 -0800 |
| commit | d5d15b1a9f89e7cf621faf96d11e2fd139037a54 (patch) | |
| tree | d4e978decb423dcf3fa9b0985c8f5189e18adb7f | |
| parent | 0af4df3e3dea05063fe392a06772771ea79483a4 (diff) | |
| download | coinos-server-d5d15b1a9f89e7cf621faf96d11e2fd139037a54.tar.gz coinos-server-d5d15b1a9f89e7cf621faf96d11e2fd139037a54.zip | |
admin endpoints
| -rw-r--r-- | index.js | 5 | ||||
| -rw-r--r-- | lib/auth.js | 11 | ||||
| -rw-r--r-- | routes/users.js | 14 |
3 files changed, 29 insertions, 1 deletions
@@ -1,5 +1,5 @@ import app from "$lib/app"; -import { auth, optional } from "$lib/auth"; +import { auth, admin, optional } from "$lib/auth"; import { fillPool } from "$lib/nostr"; import { listenForLightning } from "$lib/lightning"; @@ -113,6 +113,9 @@ app.post("/requests/delete", auth, requests.destroy); app.post("/shopify/:id", shopify); +app.post("/hidepay", admin, users.hidepay); + app.post("/unlimit", admin, users.unlimit); + let host = process.env.HOST || "0.0.0.0"; let port = process.env.PORT || 3119; diff --git a/lib/auth.js b/lib/auth.js index 944cc3b2..0a8d43d3 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -4,6 +4,17 @@ import { fail, getUser } from "$lib/utils"; import config from "$config"; import jwt from "passport-jwt"; +export const admin = { + preValidation: fastifyPassport.authenticate( + "jwt", + { session: false }, + function (req, res, err, user, info) { + if (!user.admin) return res.code(401).send("unauthorized"); + req.user = user; + }, + ), +}; + export const optional = { preValidation: fastifyPassport.authenticate( "jwt", diff --git a/routes/users.js b/routes/users.js index 59de22b2..df16c75e 100644 --- a/routes/users.js +++ b/routes/users.js @@ -532,4 +532,18 @@ export default { let item = await g(`item:${id}`); return item; }, + + async hidepay({ body: { username } }, res) { + let u = await getUser(username); + u.hidepay = true; + await s(`user:${u.id}`, u); + res.send({}); + }, + + async unlimit({ body: { username } }, res) { + let u = await getUser(username); + u.unlimited = true; + await s(`user:${u.id}`, u); + res.send({}); + }, }; |
