chore: began implementing more pages

This commit is contained in:
Kakious 2024-08-08 17:47:42 -04:00
parent 72293167ad
commit 62bb9531c0

View file

@ -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 { ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
import { AuthService } from '../services/auth.service'; import { AuthService } from '../services/auth.service';
@ -9,20 +9,19 @@ import { Response } from 'express';
import { User } from '../decorators/user.decorator'; import { User } from '../decorators/user.decorator';
import { LoginGuard } from '../guard/login.guard'; import { LoginGuard } from '../guard/login.guard';
// TODO: Implement RateLimit
@Controller('auth') @Controller('auth')
@ApiTags('Authentication') @ApiTags('Authentication')
export class AuthController { export class AuthController {
constructor(private readonly authService: AuthService) {} constructor(private readonly authService: AuthService) {}
@Post('login') @Post('login')
// TODO: Implement RateLimit
public async postLogin( public async postLogin(
@Body() body: LoginUserDto, @Body() body: LoginUserDto,
@Res({ passthrough: true }) res: Response, @Res({ passthrough: true }) res: Response,
): Promise<any> { ): Promise<any> {
const sessionData = await this.authService.login(body.username, body.password); const sessionData = await this.authService.login(body.username, body.password);
// process the sessionData.cookies and set it in the response
sessionData.cookiesForms.forEach((cookie) => { sessionData.cookiesForms.forEach((cookie) => {
res.cookie(cookie.name, cookie.value, cookie.options); res.cookie(cookie.name, cookie.value, cookie.options);
}); });
@ -30,19 +29,18 @@ export class AuthController {
return sessionData.sessionId; return sessionData.sessionId;
} }
// TODO: Implement RateLimit
@Post('register') @Post('register')
public async postRegister(@Body() body: CreateUserDto): Promise<any> { public async postRegister(@Body() body: CreateUserDto): Promise<any> {
return await this.authService.register(body.username, body.email, body.password); return await this.authService.register(body.username, body.email, body.password);
} }
// TODO: Implement RateLimit
@Post('reset-password') @Post('reset-password')
public async postForgotPassword(@Body() body: ForgotPasswordDto): Promise<any> { public async postForgotPassword(@Body() body: ForgotPasswordDto): Promise<any> {
return await this.authService.forgotPassword(body.email); return await this.authService.forgotPassword(body.email);
} }
// Render pages // ==== Render pages ==== //
@Get('login') @Get('login')
@UseGuards(LoginGuard) @UseGuards(LoginGuard)
@Render('auth/login') @Render('auth/login')
@ -55,6 +53,17 @@ export class AuthController {
}; };
} }
@Get('login/totp')
@UseGuards(LoginGuard)
@Render('auth/login-totp')
@ApiExcludeEndpoint()
public async getLoginTotp(): Promise<any> {
return {
login: 'login',
methods: ['authenticator', 'email'],
};
}
@Get('register') @Get('register')
@UseGuards(LoginGuard) @UseGuards(LoginGuard)
@Render('auth/register') @Render('auth/register')
@ -75,9 +84,25 @@ export class AuthController {
}; };
} }
@Get('auth-test') @Get('verify-email')
@UseGuards(LoginGuard)
@Render('auth/verify-email')
@ApiExcludeEndpoint() @ApiExcludeEndpoint()
public async getAuthTest(@User() user: any): Promise<any> { public async getVerifyEmail(@Query('code') code?: string): Promise<any> {
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<any> {
// TODO: If user is not logged in. Set a cookie to redirect to this page after login.
return user; return user;
} }
} }