slate/common/validations.js

141 lines
2.1 KiB
JavaScript
Raw Normal View History

import * as Strings from "~/common/strings";
const USERNAME_REGEX = new RegExp("^[a-zA-Z0-9_]{0,}[a-zA-Z]+[0-9]*$");
const MIN_PASSWORD_LENGTH = 8;
2020-09-17 02:26:15 +03:00
const EMAIL_REGEX = /^[\w-]+@[a-zA-Z0-9_]+?\.[a-zA-Z]{2,50}$/;
2020-08-07 02:28:54 +03:00
// TODO(jim): Regex should cover some of this.
const REJECT_LIST = [
2020-08-07 02:28:54 +03:00
"..",
"_",
"_next",
"next",
"webpack",
"system",
"experience",
"root",
"www",
"website",
"index",
"api",
"public",
"static",
"admin",
"administrator",
"webmaster",
2020-09-22 20:21:58 +03:00
"download",
"downloads",
"403",
"404",
"500",
2020-08-19 21:17:12 +03:00
"maintenance",
2020-09-21 22:39:36 +03:00
"guidelines",
2020-08-19 21:17:12 +03:00
"updates",
"login",
2020-08-07 02:28:54 +03:00
"authenticate",
"sign-in",
2020-08-07 02:28:54 +03:00
"sign_in",
"signin",
"log-in",
2020-08-07 02:28:54 +03:00
"log_in",
"logout",
"terms",
"terms-of-service",
"community",
"privacy",
"reset-password",
"reset",
"logout",
"dashboard",
"analytics",
"data",
2020-10-05 05:17:08 +03:00
"timeout",
"please-dont-use-timeout",
];
export const userRoute = (text) => {
if (!USERNAME_REGEX.test(text)) {
return false;
}
if (REJECT_LIST.includes(text)) {
return false;
}
return true;
};
2020-09-06 05:42:30 +03:00
export const slatename = (text) => {
if (Strings.isEmpty(text)) {
return false;
}
if (text.length > 48) {
return false;
}
return true;
};
export const username = (text) => {
if (Strings.isEmpty(text)) {
return false;
}
if (text.length > 48 || text.length < 1) {
2020-09-06 05:42:30 +03:00
return false;
}
if (!userRoute(text)) {
return false;
}
return true;
};
export const password = (text) => {
if (Strings.isEmpty(text)) {
return false;
}
if (text.length < MIN_PASSWORD_LENGTH) {
return false;
}
return true;
};
export const isFileTypeAllowed = (type = "") => {
2020-09-16 12:16:46 +03:00
console.log({ type });
2020-09-08 08:23:22 +03:00
if (type.startsWith("text/")) {
return true;
}
2020-09-16 12:16:46 +03:00
if (type.startsWith("model/")) {
2020-09-08 08:23:22 +03:00
return true;
}
2020-09-16 12:16:46 +03:00
if (type.startsWith("font/")) {
return true;
}
2020-09-16 12:16:46 +03:00
if (type.startsWith("application/")) {
2020-08-10 13:10:44 +03:00
return true;
}
if (type.startsWith("audio/")) {
return true;
}
if (type.startsWith("image/")) {
return true;
}
if (type.startsWith("video/")) {
return true;
}
return false;
};