diff --git a/Makefile b/Makefile index e4d9e0b..52915d4 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ USER = gavaniwast all: clean dev dev: - NODE_ENV="development" docker-compose up --build + NODE_ENV="development" docker compose up --build check: NODE_ENV="check" docker-compose run back --build diff --git a/back/volume/src/auth/auth.controller.ts b/back/volume/src/auth/auth.controller.ts index 318ac34..0033445 100644 --- a/back/volume/src/auth/auth.controller.ts +++ b/back/volume/src/auth/auth.controller.ts @@ -17,6 +17,8 @@ import { Profile42 } from './42.decorator' import { AuthService } from './auth.service' import { UsersService } from 'src/users/users.service' +import { EmailDto } from 'src/chat/dto/updateUser.dto' +import User from 'src/users/entity/user.entity' const frontHost = process.env.HOST !== undefined && process.env.HOST !== '' @@ -28,12 +30,25 @@ const frontPort = : '80' @Controller('log') -export class AuthController { +export class AuthController { constructor ( private readonly authService: AuthService, private readonly usersService: UsersService ) {} + @Post('/email') + @UseGuards(AuthenticatedGuard) + async setEmail ( + @Profile42() profile: Profile, + @Body() body: EmailDto + ): Promise { + console.log('in') + const email = body.email + const user = (await this.usersService.findUser(+profile.id)) as User + user.email = email + await this.usersService.save(user) + } + @Get('in') @UseGuards(FtOauthGuard) ftAuth (): void {} diff --git a/back/volume/src/auth/mails/confirm.hbs b/back/volume/src/auth/mails/confirm.hbs index 461a90c..fbcb9c5 100644 --- a/back/volume/src/auth/mails/confirm.hbs +++ b/back/volume/src/auth/mails/confirm.hbs @@ -8,7 +8,7 @@

Hello {{username}}!

Once you clicked on the next verify button, you will have access to the app

-
+
diff --git a/back/volume/src/chat/dto/updateUser.dto.ts b/back/volume/src/chat/dto/updateUser.dto.ts index d857de0..ca11d95 100644 --- a/back/volume/src/chat/dto/updateUser.dto.ts +++ b/back/volume/src/chat/dto/updateUser.dto.ts @@ -1,4 +1,4 @@ -import { IsNumber, IsString } from 'class-validator' +import { IsEmail, IsNumber, IsString } from 'class-validator' export class IdDto { @IsNumber() @@ -13,3 +13,8 @@ export class PasswordDto { export class MuteDto { data: number[] } + +export class EmailDto { + @IsEmail() + email: string +} diff --git a/.gitattributes b/front/volume/.gitattributes similarity index 100% rename from .gitattributes rename to front/volume/.gitattributes diff --git a/front/volume/src/App.svelte b/front/volume/src/App.svelte index 2d7a36a..b8fa765 100644 --- a/front/volume/src/App.svelte +++ b/front/volume/src/App.svelte @@ -167,9 +167,12 @@ > {:else if $store.twoFA === true && $store.isVerified === false} -

+
+ +
{:else} - { @@ -30,15 +30,37 @@ export function login() { window.location.replace(API_URL + "/log/in"); } -export function verify() { - fetch(API_URL + "/log/verify", { - method: "get", +export async function verify() { + let email : string; + await show_popup("Enter your preferred email adress:\n(defaults to 42 email)") + email = get(content); + if (email == '') + return ; + if (email != 'ok') { + const response = await fetch(API_URL + "/log/email", { + method: "POST", + mode: "cors", + headers: {"Content-Type": "application/json",}, + credentials: "include", + body: JSON.stringify({email: email}) + }) + if (response.ok) {await show_popup("Email set",false)} + else {await show_popup("Couldn't set Email",false); return } + console.log(response.ok) +} + console.log(API_URL) + const response = await fetch(API_URL + "/log/verify", { + method: "GET", mode: "cors", credentials: "include", }); - show_popup( - "We have sent you an email to verify your account. Check the mailbox which is linked to your 42's profile." - , false); + console.log(response.ok) + if (response.ok) { + console.log("here") + await show_popup("We have sent you an email to verify your account. Check your mailbox!.", false); + } else { await show_popup("Email doensn't seem valid", false);} + + } export function logout() { diff --git a/front/volume/src/components/Alert/content.ts b/front/volume/src/components/Alert/content.ts index 3a61ec4..2813a6c 100644 --- a/front/volume/src/components/Alert/content.ts +++ b/front/volume/src/components/Alert/content.ts @@ -18,11 +18,9 @@ export async function waitForCondition() { const unsub = popup.subscribe((value) => {val = value}) async function checkFlag() { if (val == null) { - console.log("finished",val) unsub() - return new Promise(resolve => setTimeout(resolve, 100)); + await new Promise(resolve => setTimeout(resolve, 100)); } else { - console.log("waiting") await new Promise(resolve => setTimeout(resolve, 1000)); return await checkFlag(); } diff --git a/front/volume/src/components/Chat.svelte b/front/volume/src/components/Chat.svelte index d7b4f34..58dcbad 100644 --- a/front/volume/src/components/Chat.svelte +++ b/front/volume/src/components/Chat.svelte @@ -217,7 +217,7 @@ headers: { "Content-Type": "application/json", }, - body: JSON.stringify({ data: [target.ftId, duration] }), + body: JSON.stringify({ data: target.ftId, duration }), }); if (response.ok) { await show_popup(`User banned for: ${duration} seconds`, false); @@ -225,7 +225,8 @@ } else { const error = await response.json(); await show_popup(error.message, false); - } + } + socket.emit("kickUser", channel.id, $store.ftId, target.ftId); } };