add wordlistdb cleanup on user delete

This commit is contained in:
lingdocs 2021-08-22 12:55:49 +04:00
parent 3fea41977f
commit 06659090da
3 changed files with 9 additions and 2 deletions

View File

@ -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<void> {
const name = getWordlistDbName(uuid);
await nano.db.destroy(name);
}
function generateWordlistDbPassword(): T.UserDbPassword {
function makeChunk(): string {
return Math.random().toString(36).slice(2)

View File

@ -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",

View File

@ -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);