1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-23 10:52:30 +01:00

🐛 fix login + register

This commit is contained in:
Flam3rboy 2021-03-04 22:00:17 +01:00
parent b5722fd3fd
commit 65eeb4d80a
2 changed files with 11 additions and 5 deletions

View File

@ -21,11 +21,14 @@ router.post(
}),
async (req: Request, res: Response) => {
const { login, password } = req.body;
const email = adjustEmail(login);
const query: any[] = [{ phone: login }];
if (email) query.push({ email });
// * MongoDB Specific query for user with same email or phone number
const user = await UserModel.findOne(
{
$or: [{ email: adjustEmail(login) }, { phone: login }],
$or: query,
},
`hash id user_settings.locale user_settings.theme`
).exec();

View File

@ -37,10 +37,10 @@ router.post(
} = req.body;
// TODO: automatically join invite
// TODO: gift_code_sku_id?
// TODO: check passwort strength
// TODO: check password strength
// adjusted_email will be slightly modified version of the user supplied email -> e.g. protection against GMail Trick
let adjusted_email: string = email;
let adjusted_email: string | undefined = adjustEmail(email);
// adjusted_password will be the hash of the password
let adjusted_password: string = "";
@ -77,7 +77,7 @@ router.post(
if (email) {
// replace all dots and chars after +, if its a gmail.com email
adjusted_email = adjustEmail(email);
if (!adjusted_email) throw FieldErrors({ email: { code: "INVALID_EMAIL", message: "Invalid Email format" } });
// check if there is already an account with this email
const exists = await UserModel.findOne({ email: adjusted_email }).exec();
@ -203,6 +203,7 @@ router.post(
enable_tts_command: true,
explicit_content_filter: 0,
friend_source_flags: { all: true },
gateway_connected: false,
gif_auto_play: true,
guild_folders: [],
guild_positions: [],
@ -230,9 +231,11 @@ router.post(
}
);
export function adjustEmail(email: string) {
export function adjustEmail(email: string): string | undefined {
// body parser already checked if it is a valid email
const parts = <RegExpMatchArray>email.match(EMAIL_REGEX);
// @ts-ignore
if (!parts || parts.length < 5) return undefined;
const domain = parts[5];
const user = parts[1];