mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-11-10 17:04:49 +08:00
actually fixed name check
This commit is contained in:
parent
6f235a2479
commit
042d9dd9a2
1 changed files with 5 additions and 6 deletions
|
@ -20,11 +20,8 @@ class UsersDAO {
|
|||
}
|
||||
|
||||
static async updateName(uid, name) {
|
||||
const nameDoc = await db
|
||||
.collection("users")
|
||||
//todo dont use case insensitive regex
|
||||
.findOne({ name: `/^${escapeRegExp(name)}$/i` });
|
||||
if (nameDoc) throw new MonkeyError(409, "Username already taken", name);
|
||||
if (!this.isNameAvailable(name))
|
||||
throw new MonkeyError(409, "Username already taken", name);
|
||||
let user = await db.collection("users").findOne({ uid });
|
||||
if (
|
||||
Date.now() - user.lastNameChange < 2592000000 &&
|
||||
|
@ -44,7 +41,9 @@ class UsersDAO {
|
|||
}
|
||||
|
||||
static async isNameAvailable(name) {
|
||||
const nameDoc = await db.collection("users").findOne({ name });
|
||||
const nameDoc = await db
|
||||
.collection("users")
|
||||
.findOne({ name: new RegExp(`^${escapeRegExp(name)}$`, "i") });
|
||||
if (nameDoc) {
|
||||
return false;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue