mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-04 06:24:07 +08:00
added more username validation
This commit is contained in:
parent
4afa2f089f
commit
74f4f8fc9c
2 changed files with 12 additions and 2 deletions
|
|
@ -3,6 +3,7 @@ const { mongoDB } = require("../init/mongodb");
|
|||
const { ObjectID } = require("mongodb");
|
||||
const { checkAndUpdatePb } = require("../handlers/pb");
|
||||
const { updateAuthEmail } = require("../handlers/auth");
|
||||
const { isUsernameValid } = require("../handlers/validation");
|
||||
|
||||
class UsersDAO {
|
||||
static async addUser(name, email, uid) {
|
||||
|
|
@ -24,7 +25,10 @@ class UsersDAO {
|
|||
.findOne({ name: { $regex: new RegExp(`^${name}$`, "i") } });
|
||||
if (nameDoc) throw new MonkeyError(409, "Username already taken");
|
||||
let user = await mongoDB().collection("users").findOne({ uid });
|
||||
if (Date.now() - user.lastNameChange < 2592000000) {
|
||||
if (
|
||||
Date.now() - user.lastNameChange < 2592000000 &&
|
||||
isUsernameValid(user.name)
|
||||
) {
|
||||
throw new MonkeyError(409, "You can change your name once every 30 days");
|
||||
}
|
||||
return await mongoDB()
|
||||
|
|
|
|||
|
|
@ -5,7 +5,13 @@ const { roundTo2 } = require("./misc");
|
|||
function isUsernameValid(name) {
|
||||
if (name === null || name === undefined || name === "") return false;
|
||||
if (/miodec/.test(name.toLowerCase())) return false;
|
||||
if (/bitly/.test(name.toLowerCase())) return false;
|
||||
//sorry for the bad words
|
||||
if (
|
||||
/bitly|fuck|bitch|shit|pussy|nigga|niqqa|niqqer|nigger|ni99a|ni99er|niga|niger|cunt|faggot|retard/.test(
|
||||
name.toLowerCase()
|
||||
)
|
||||
)
|
||||
return false;
|
||||
if (name.length > 14) return false;
|
||||
if (/^\..*/.test(name.toLowerCase())) return false;
|
||||
return /^[0-9a-zA-Z_.-]+$/.test(name);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue