From 62bb9531c0475060342ef393b98aa5ed786e4749 Mon Sep 17 00:00:00 2001 From: Kakious Date: Thu, 8 Aug 2024 17:47:42 -0400 Subject: [PATCH] chore: began implementing more pages --- src/auth/controllers/auth.controller.ts | 41 ++++++++++++++++++++----- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/auth/controllers/auth.controller.ts b/src/auth/controllers/auth.controller.ts index 8053071..b7d2ddb 100644 --- a/src/auth/controllers/auth.controller.ts +++ b/src/auth/controllers/auth.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Get, Post, Render, Res, UseGuards } from '@nestjs/common'; +import { Body, Controller, Get, Post, Query, Render, Res, UseGuards } from '@nestjs/common'; import { ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger'; import { AuthService } from '../services/auth.service'; @@ -9,20 +9,19 @@ import { Response } from 'express'; import { User } from '../decorators/user.decorator'; import { LoginGuard } from '../guard/login.guard'; +// TODO: Implement RateLimit @Controller('auth') @ApiTags('Authentication') export class AuthController { constructor(private readonly authService: AuthService) {} @Post('login') - // TODO: Implement RateLimit public async postLogin( @Body() body: LoginUserDto, @Res({ passthrough: true }) res: Response, ): Promise { const sessionData = await this.authService.login(body.username, body.password); - // process the sessionData.cookies and set it in the response sessionData.cookiesForms.forEach((cookie) => { res.cookie(cookie.name, cookie.value, cookie.options); }); @@ -30,19 +29,18 @@ export class AuthController { return sessionData.sessionId; } - // TODO: Implement RateLimit @Post('register') public async postRegister(@Body() body: CreateUserDto): Promise { return await this.authService.register(body.username, body.email, body.password); } - // TODO: Implement RateLimit @Post('reset-password') public async postForgotPassword(@Body() body: ForgotPasswordDto): Promise { return await this.authService.forgotPassword(body.email); } - // Render pages + // ==== Render pages ==== // + @Get('login') @UseGuards(LoginGuard) @Render('auth/login') @@ -55,6 +53,17 @@ export class AuthController { }; } + @Get('login/totp') + @UseGuards(LoginGuard) + @Render('auth/login-totp') + @ApiExcludeEndpoint() + public async getLoginTotp(): Promise { + return { + login: 'login', + methods: ['authenticator', 'email'], + }; + } + @Get('register') @UseGuards(LoginGuard) @Render('auth/register') @@ -75,9 +84,25 @@ export class AuthController { }; } - @Get('auth-test') + @Get('verify-email') + @UseGuards(LoginGuard) + @Render('auth/verify-email') @ApiExcludeEndpoint() - public async getAuthTest(@User() user: any): Promise { + public async getVerifyEmail(@Query('code') code?: string): Promise { + if (!code) { + //TODO: Write error page. + } + + return { + login: 'login', + }; + } + + //TODO: Work on interaction view. + @Get('interaction/:id') + @ApiExcludeEndpoint() + public async getInteraction(@User() user: any): Promise { + // TODO: If user is not logged in. Set a cookie to redirect to this page after login. return user; } }