( req: MonkeyRequest<undefined, CreateUserRequest>, )
| 108 | } |
| 109 | |
| 110 | export async function createNewUser( |
| 111 | req: MonkeyRequest<undefined, CreateUserRequest>, |
| 112 | ): Promise<MonkeyResponse> { |
| 113 | const { name, captcha } = req.body; |
| 114 | const { email, uid } = req.ctx.decodedToken; |
| 115 | |
| 116 | try { |
| 117 | await verifyCaptcha(captcha); |
| 118 | |
| 119 | if (email.endsWith("@tidal.lol") || email.endsWith("@selfbot.cc")) { |
| 120 | throw new MonkeyError(400, "Invalid domain"); |
| 121 | } |
| 122 | |
| 123 | const available = await UserDAL.isNameAvailable(name, uid); |
| 124 | if (!available) { |
| 125 | throw new MonkeyError(409, "Username unavailable"); |
| 126 | } |
| 127 | |
| 128 | const blocklisted = await BlocklistDal.contains({ name, email }); |
| 129 | if (blocklisted) { |
| 130 | throw new MonkeyError(409, "Username or email blocked"); |
| 131 | } |
| 132 | |
| 133 | await UserDAL.addUser(name, email, uid); |
| 134 | void addImportantLog("user_created", `${name} ${email}`, uid); |
| 135 | |
| 136 | return new MonkeyResponse("User created", null); |
| 137 | } catch (e) { |
| 138 | //user was created in firebase from the frontend, remove it |
| 139 | await firebaseDeleteUserIgnoreError(uid); |
| 140 | throw e; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | export async function sendVerificationEmail( |
| 145 | req: MonkeyRequest, |
nothing calls this directly
no test coverage detected