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 { 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<any> {
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<any> {
return await this.authService.register(body.username, body.email, body.password);
}
// TODO: Implement RateLimit
@Post('reset-password')
public async postForgotPassword(@Body() body: ForgotPasswordDto): Promise<any> {
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<any> {
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<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;
}
}