From 06659090daea8f95b407738c1a9472be54baf46c Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Sun, 22 Aug 2021 12:55:49 +0400 Subject: [PATCH] add wordlistdb cleanup on user delete --- account/src/lib/couch-db.ts | 5 +++++ account/src/routers/api-router.ts | 3 ++- account/src/routers/auth-router.ts | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/account/src/lib/couch-db.ts b/account/src/lib/couch-db.ts index 02bfb79..7b18f4f 100644 --- a/account/src/lib/couch-db.ts +++ b/account/src/lib/couch-db.ts @@ -123,6 +123,11 @@ export async function createWordlistDatabase(uuid: T.UUID): Promise<{ name: T.Wo return { password, name }; } +export async function deleteWordlistDatabase(uuid: T.UUID): Promise { + const name = getWordlistDbName(uuid); + await nano.db.destroy(name); +} + function generateWordlistDbPassword(): T.UserDbPassword { function makeChunk(): string { return Math.random().toString(36).slice(2) diff --git a/account/src/routers/api-router.ts b/account/src/routers/api-router.ts index 8cfa0f6..b3257b2 100644 --- a/account/src/routers/api-router.ts +++ b/account/src/routers/api-router.ts @@ -106,7 +106,8 @@ apiRouter.put("/user/upgrade", async (req, res, next) => { } const { userId } = req.user; const user = await getLingdocsUser("userId", userId); - if (user) { + if (!user) throw new Error("user lost"); + if (user.level !== "basic") { const alreadyUpgraded: T.UpgradeUserResponse = { ok: true, message: "user already upgraded", diff --git a/account/src/routers/auth-router.ts b/account/src/routers/auth-router.ts index d1ce8a4..71de81b 100644 --- a/account/src/routers/auth-router.ts +++ b/account/src/routers/auth-router.ts @@ -128,8 +128,9 @@ const authRouter = (passport: PassportStatic) => { router.post("/register", async (req, res, next) => { try { const { email, password, name } = req.body; + console.log(email, password, name); const existingUser = await getLingdocsUser("email", email); - if (existingUser) return res.send("Tser Already Exists"); + if (existingUser) return res.send("User Already Exists"); const user = await createNewUser({ strategy: "local", email, passwordPlainText: password, name }); req.logIn(user, (err) => { if (err) return next(err);