|
@@ -2,6 +2,7 @@ import { body, param } from "express-validator";
|
|
|
import { isAfter, subDays, subHours } from "date-fns";
|
|
import { isAfter, subDays, subHours } from "date-fns";
|
|
|
import urlRegex from "url-regex";
|
|
import urlRegex from "url-regex";
|
|
|
import { promisify } from "util";
|
|
import { promisify } from "util";
|
|
|
|
|
+import bcrypt from "bcryptjs";
|
|
|
import axios from "axios";
|
|
import axios from "axios";
|
|
|
import dns from "dns";
|
|
import dns from "dns";
|
|
|
import URL from "url";
|
|
import URL from "url";
|
|
@@ -94,7 +95,7 @@ export const createLink = [
|
|
|
});
|
|
});
|
|
|
req.body.domain = domain || null;
|
|
req.body.domain = domain || null;
|
|
|
|
|
|
|
|
- return !!domain;
|
|
|
|
|
|
|
+ if (!domain) return Promise.reject();
|
|
|
})
|
|
})
|
|
|
.withMessage("You can't use this domain.")
|
|
.withMessage("You can't use this domain.")
|
|
|
];
|
|
];
|
|
@@ -125,12 +126,12 @@ export const addDomain = [
|
|
|
.withMessage("You can't use the default domain.")
|
|
.withMessage("You can't use the default domain.")
|
|
|
.custom(async (value, { req }) => {
|
|
.custom(async (value, { req }) => {
|
|
|
const domains = await query.domain.get({ user_id: req.user.id });
|
|
const domains = await query.domain.get({ user_id: req.user.id });
|
|
|
- return domains.length === 0;
|
|
|
|
|
|
|
+ if (domains.length !== 0) return Promise.reject();
|
|
|
})
|
|
})
|
|
|
.withMessage("You already own a domain. Contact support if you need more.")
|
|
.withMessage("You already own a domain. Contact support if you need more.")
|
|
|
.custom(async value => {
|
|
.custom(async value => {
|
|
|
const domain = await query.domain.find({ address: value });
|
|
const domain = await query.domain.find({ address: value });
|
|
|
- return !domain || !domain.user_id || !domain.banned;
|
|
|
|
|
|
|
+ if (domain?.user_id || domain?.banned) return Promise.reject();
|
|
|
})
|
|
})
|
|
|
.withMessage("You can't add this domain."),
|
|
.withMessage("You can't add this domain."),
|
|
|
body("homepage")
|
|
body("homepage")
|
|
@@ -225,7 +226,7 @@ export const signup = [
|
|
|
req.user = user;
|
|
req.user = user;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return !user || !user.verified;
|
|
|
|
|
|
|
+ if (user?.verified) return Promise.reject();
|
|
|
})
|
|
})
|
|
|
.withMessage("You can't use this email address.")
|
|
.withMessage("You can't use this email address.")
|
|
|
];
|
|
];
|
|
@@ -259,6 +260,16 @@ export const resetPasswordRequest = [
|
|
|
.withMessage("Email length must be max 255.")
|
|
.withMessage("Email length must be max 255.")
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
|
|
+export const deleteUser = [
|
|
|
|
|
+ body("password", "Password is not valid.")
|
|
|
|
|
+ .exists({ checkFalsy: true, checkNull: true })
|
|
|
|
|
+ .isLength({ min: 8, max: 64 })
|
|
|
|
|
+ .custom(async (password, { req }) => {
|
|
|
|
|
+ const isMatch = await bcrypt.compare(password, req.user.password);
|
|
|
|
|
+ if (!isMatch) return Promise.reject();
|
|
|
|
|
+ })
|
|
|
|
|
+];
|
|
|
|
|
+
|
|
|
export const cooldown = (user: User) => {
|
|
export const cooldown = (user: User) => {
|
|
|
if (!env.GOOGLE_SAFE_BROWSING_KEY || !user || !user.cooldowns) return;
|
|
if (!env.GOOGLE_SAFE_BROWSING_KEY || !user || !user.cooldowns) return;
|
|
|
|
|
|