2020-07-23 11:57:44 +03:00
|
|
|
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-08-07 02:28:54 +03:00
|
|
|
|
2020-08-07 02:36:03 +03:00
|
|
|
// TODO(jim): Regex should cover some of this.
|
|
|
|
const REJECT_LIST = [
|
2020-08-07 02:28:54 +03:00
|
|
|
"..",
|
2020-08-07 02:06:54 +03:00
|
|
|
"_",
|
2020-08-07 02:36:03 +03:00
|
|
|
"_next",
|
|
|
|
"next",
|
|
|
|
"webpack",
|
2020-08-07 02:06:54 +03:00
|
|
|
"root",
|
|
|
|
"www",
|
|
|
|
"website",
|
|
|
|
"index",
|
|
|
|
"api",
|
|
|
|
"public",
|
|
|
|
"static",
|
|
|
|
"admin",
|
|
|
|
"administrator",
|
|
|
|
"webmaster",
|
|
|
|
"403",
|
|
|
|
"404",
|
|
|
|
"500",
|
|
|
|
"login",
|
2020-08-07 02:28:54 +03:00
|
|
|
"authenticate",
|
2020-08-07 02:06:54 +03:00
|
|
|
"sign-in",
|
2020-08-07 02:28:54 +03:00
|
|
|
"sign_in",
|
2020-08-07 02:06:54 +03:00
|
|
|
"signin",
|
|
|
|
"log-in",
|
2020-08-07 02:28:54 +03:00
|
|
|
"log_in",
|
2020-08-07 02:06:54 +03:00
|
|
|
"logout",
|
|
|
|
];
|
2020-07-23 11:57:44 +03:00
|
|
|
|
2020-08-07 02:36:03 +03:00
|
|
|
export const userRoute = (text) => {
|
|
|
|
if (!USERNAME_REGEX.test(text)) {
|
2020-07-23 11:57:44 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-08-07 02:36:03 +03:00
|
|
|
if (REJECT_LIST.includes(text)) {
|
2020-07-23 11:57:44 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-08-07 02:36:03 +03:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const username = (text) => {
|
|
|
|
if (Strings.isEmpty(text)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!userRoute(text)) {
|
2020-08-07 02:06:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-23 11:57:44 +03:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const password = (text) => {
|
|
|
|
if (Strings.isEmpty(text)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text.length < MIN_PASSWORD_LENGTH) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
2020-08-02 09:00:04 +03:00
|
|
|
|
|
|
|
export const isFileTypeAllowed = (type = "") => {
|
|
|
|
if (type.startsWith("application/pdf")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-08-10 13:10:44 +03:00
|
|
|
if (type.startsWith("application/epub")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-08-04 06:15:24 +03:00
|
|
|
if (type.startsWith("audio/")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-08-02 09:00:04 +03:00
|
|
|
if (type.startsWith("image/")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-08-02 10:29:24 +03:00
|
|
|
if (type.startsWith("video/")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-08-02 09:00:04 +03:00
|
|
|
return false;
|
|
|
|
};
|