merging
This commit is contained in:
@@ -7,6 +7,7 @@ import { ConfigModule } from '@nestjs/config';
|
||||
import { FriendshipsModule } from './friendship/friendships.module';
|
||||
import { AuthenticationModule } from './auth/42/authentication.module';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
import { GameModule } from './game/game/game.module';
|
||||
|
||||
@Module({
|
||||
imports: [UsersModule,
|
||||
@@ -26,6 +27,7 @@ import { PassportModule } from '@nestjs/passport';
|
||||
//avec une classe pour le module
|
||||
synchronize: true,
|
||||
}),
|
||||
GameModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
|
||||
@@ -4,6 +4,7 @@ import { AuthenticationService } from './authentication.service';
|
||||
import { Response } from 'express';
|
||||
import { TwoFaDto } from './dto/2fa.dto';
|
||||
import { UsersService } from 'src/users/users.service';
|
||||
import { User } from 'src/users/entities/user.entity';
|
||||
|
||||
@Controller('auth')
|
||||
export class AuthenticationController {
|
||||
@@ -33,7 +34,8 @@ export class AuthenticationController {
|
||||
async redirect(@Res() response : Response, @Req() request) {
|
||||
console.log('ON EST DANS REDIRECT AUTH CONTROLLER');
|
||||
console.log('On redirige');
|
||||
if (request.user.isEnabledTwoFactorAuth === false)
|
||||
const user : User = request.user
|
||||
if (user.isEnabledTwoFactorAuth === false || user.isTwoFactorAuthenticated === true)
|
||||
return response.status(200).redirect('http://transcendance:8080/#/profile');
|
||||
return response.status(200).redirect('http://transcendance:8080/#/2fa');
|
||||
}
|
||||
@@ -58,25 +60,33 @@ export class AuthenticationController {
|
||||
@Post('2fa/generate')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
async register(@Req() request, @Res() response){
|
||||
console.log('ON EST DANS REGISTER POUR 2FA AUTH CONTROLLER')
|
||||
const { otpauth } = await this.authService.generate2FaSecret(request.user);
|
||||
return this.authService.pipeQrCodeStream(response, otpauth);
|
||||
const user : User = request.user;
|
||||
if (user.isEnabledTwoFactorAuth === true)
|
||||
{
|
||||
console.log('ON EST DANS REGISTER POUR 2FA AUTH CONTROLLER')
|
||||
const { otpauth } = await this.authService.generate2FaSecret(request.user);
|
||||
return this.authService.pipeQrCodeStream(response, otpauth);
|
||||
}
|
||||
}
|
||||
|
||||
@Post('2fa/turn-on')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
async verify(@Req() request, @Body() {twoFaCode} : TwoFaDto, @Res() response){
|
||||
console.log('ON EST DANS VERIFY POUR 2FA AUTH CONTROLLER')
|
||||
const isCodeIsValid = await this.authService.verify2FaCode(request.user, twoFaCode);
|
||||
if (isCodeIsValid === false)
|
||||
const user : User = request.user;
|
||||
if (user.isEnabledTwoFactorAuth === true)
|
||||
{
|
||||
throw new UnauthorizedException('Wrong Code.');
|
||||
console.log('ON EST DANS VERIFY POUR 2FA AUTH CONTROLLER')
|
||||
const isCodeIsValid = await this.authService.verify2FaCode(request.user, twoFaCode);
|
||||
if (isCodeIsValid === false)
|
||||
{
|
||||
throw new UnauthorizedException('Wrong Code.');
|
||||
}
|
||||
await this.userService.enableTwoFactorAuth(request.user.id);
|
||||
console.log('ON REDIRIGE');
|
||||
// return response.status(200);
|
||||
// return 200;
|
||||
// needs to be looked at by Cherif
|
||||
}
|
||||
await this.userService.enableTwoFactorAuth(request.user.id);
|
||||
console.log('ON REDIRIGE');
|
||||
// return response.status(200);
|
||||
// return 200;
|
||||
// needs to be looked at by Cherif
|
||||
return response.status(200).redirect('http://transcendance:8080/');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { GameController } from './game.controller';
|
||||
|
||||
describe('GameController', () => {
|
||||
let controller: GameController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [GameController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<GameController>(GameController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
import { Controller } from '@nestjs/common';
|
||||
|
||||
@Controller('game')
|
||||
export class GameController {}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { GameController } from './game.controller';
|
||||
import { GameService } from './game.service';
|
||||
|
||||
@Module({
|
||||
controllers: [GameController],
|
||||
providers: [GameService]
|
||||
})
|
||||
export class GameModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { GameService } from './game.service';
|
||||
|
||||
describe('GameService', () => {
|
||||
let service: GameService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [GameService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<GameService>(GameService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class GameService {}
|
||||
@@ -63,9 +63,12 @@ export class UsersController {
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Patch()
|
||||
update(@Req() req, @Body(new ValidationPipe()) usersUpdateDto: UpdateUsersDto) {
|
||||
update(@Req() req, @Body(new ValidationPipe()) usersUpdateDto: UpdateUsersDto, @Res() response) {
|
||||
console.log("DANS PATCH USERS");
|
||||
return this.usersService.update(req.user.id, usersUpdateDto);
|
||||
this.usersService.update(req.user.id, usersUpdateDto);
|
||||
const user : User = req.user;
|
||||
if (user.isEnabledTwoFactorAuth === true && user.isTwoFactorAuthenticated === false)
|
||||
return response.status.redirect("http://transcendance:8080/#/2fa");
|
||||
}
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
|
||||
Reference in New Issue
Block a user