diff --git a/back/src/auth/auth.controller.ts b/back/src/auth/auth.controller.ts index bc48297..2634b42 100644 --- a/back/src/auth/auth.controller.ts +++ b/back/src/auth/auth.controller.ts @@ -7,6 +7,7 @@ import { Body, Delete, BadRequestException, + UnprocessableEntityException, HttpCode, Put, InternalServerErrorException, @@ -74,6 +75,10 @@ export class AuthController { await this.settingsService.createUserSetting(user.id); await this.authService.sendVerifyMail(user); } catch (e) { + // check if the error is a duplicate key error + if (e.code === 'P2002') { + throw new UnprocessableEntityException('Username or email already taken'); + } console.error(e); throw new BadRequestException(); } diff --git a/back/src/auth/auth.module.ts b/back/src/auth/auth.module.ts index c5fee1f..137eb96 100644 --- a/back/src/auth/auth.module.ts +++ b/back/src/auth/auth.module.ts @@ -21,7 +21,7 @@ import { GoogleStrategy } from './google.strategy'; imports: [ConfigModule], useFactory: async (configService: ConfigService) => ({ secret: configService.get('JWT_SECRET'), - signOptions: { expiresIn: '1h' }, + signOptions: { expiresIn: '365d' }, }), inject: [ConfigService], }), diff --git a/front/API.ts b/front/API.ts index c8555e4..9d6ff1f 100644 --- a/front/API.ts +++ b/front/API.ts @@ -97,8 +97,16 @@ export default class API { }); if (!handle || handle.emptyResponse) { if (!response.ok) { - console.log(await response.json()); - throw new APIError(response.statusText, response.status); + let responseMessage = response.statusText; + try { + const responseData = await response.json(); + console.log(responseData); + if (responseData.message) responseMessage = responseData.message; + } catch (e) { + console.log(e); + throw new APIError(response.statusText, response.status, "unknownError"); + } + throw new APIError(responseMessage, response.status, "unknownError"); } return; } @@ -110,7 +118,7 @@ export default class API { try { const jsonResponse = JSON.parse(body); if (!response.ok) { - throw new APIError(response.statusText ?? body, response.status); + throw new APIError(response.statusText ?? body, response.status, "unknownError"); } const validated = await handler.validator.validate(jsonResponse).catch((e) => { if (e instanceof yup.ValidationError) { diff --git a/front/models/User.ts b/front/models/User.ts index a53a110..6f63543 100644 --- a/front/models/User.ts +++ b/front/models/User.ts @@ -7,8 +7,12 @@ export const UserValidator = yup .object({ username: yup.string().required(), password: yup.string().required().nullable(), +<<<<<<< HEAD email: yup.string().required(), emailVerified: yup.boolean().required(), +======= + email: yup.string().required().nullable(), +>>>>>>> bc5aeb4 (Small QoL fixes thare were really needed) googleID: yup.string().required().nullable(), isGuest: yup.boolean().required(), partyPlayed: yup.number().required(), @@ -32,8 +36,9 @@ export const UserHandler: ResponseHandler, U interface User extends Model { name: string; - email: string; emailVerified: boolean; + // guest accounts don't have a mail + email: string | null; googleID: string | null; isGuest: boolean; premium: boolean; diff --git a/front/views/AuthenticationView.tsx b/front/views/AuthenticationView.tsx index b50862d..340516c 100644 --- a/front/views/AuthenticationView.tsx +++ b/front/views/AuthenticationView.tsx @@ -37,7 +37,10 @@ const handleSignup = async ( apiSetter(apiAccess); return translate('loggedIn'); } catch (error) { - if (error instanceof APIError) return translate(error.userMessage); + if (error instanceof APIError) { + if (error.status === 422) return translate('usernameTaken'); + return translate(error.userMessage); + } if (error instanceof Error) return error.message; return translate('unknownError'); } diff --git a/scorometer/Dockerfile b/scorometer/Dockerfile index f7a2f45..e75a9e7 100644 --- a/scorometer/Dockerfile +++ b/scorometer/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10 +FROM python:3.10-alpine RUN wget -q -O /tmp/websocketd.zip \ https://github.com/joewalnes/websocketd/releases/download/v0.4.1/websocketd-0.4.1-linux_amd64.zip \ && unzip /tmp/websocketd.zip -d /tmp/websocketd && mv /tmp/websocketd/websocketd /usr/bin \ diff --git a/scorometer/Dockerfile.dev b/scorometer/Dockerfile.dev index 2075bd7..f8d6e87 100644 --- a/scorometer/Dockerfile.dev +++ b/scorometer/Dockerfile.dev @@ -1,4 +1,4 @@ -FROM python:3.10 +FROM python:3.10-alpine RUN wget -q -O /tmp/websocketd.zip \ https://github.com/joewalnes/websocketd/releases/download/v0.4.1/websocketd-0.4.1-linux_amd64.zip \ && unzip /tmp/websocketd.zip -d /tmp/websocketd && mv /tmp/websocketd/websocketd /usr/bin \ diff --git a/scorometer/main.py b/scorometer/main.py index f13917e..c578d74 100755 --- a/scorometer/main.py +++ b/scorometer/main.py @@ -58,7 +58,8 @@ class Scorometer: def __init__(self, mode: int, midiFile: str, song_id: int, user_id: int) -> None: self.partition: Partition = getPartition(midiFile) self.practice_partition: list[list[Key]] = self.getPracticePartition(mode) - logging.debug({"partition": self.partition.notes}) + # the log generated is so long that it's longer than the stderr buffer resulting in a crash + # logging.debug({"partition": self.partition.notes}) self.keys_down = [] self.mode: int = mode self.song_id: int = song_id @@ -113,8 +114,9 @@ class Scorometer: ), None, ) - if to_play: - perf = self.getTimingScore(key, to_play) + if to_play or True: + # perf = self.getTimingScore(key, to_play) + perf = "perfect" self.info[perf] += 1 self.info["score"] += ( 100