Merge remote-tracking branch 'origin' into eric_front_and_back
This commit is contained in:
60
srcs/requirements/nestjs/api_back/package-lock.json
generated
60
srcs/requirements/nestjs/api_back/package-lock.json
generated
@@ -3886,9 +3886,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/dezalgo": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.3.tgz",
|
||||
"integrity": "sha512-K7i4zNfT2kgQz3GylDw40ot9GAE47sFZ9EXHFSPP6zONLgH6kWXE0KWJchkbQJLBkRazq4APwZ4OwiFFlT95OQ==",
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz",
|
||||
"integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"asap": "^2.0.0",
|
||||
@@ -4823,25 +4823,28 @@
|
||||
}
|
||||
},
|
||||
"node_modules/formidable": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/formidable/-/formidable-2.0.1.tgz",
|
||||
"integrity": "sha512-rjTMNbp2BpfQShhFbR3Ruk3qk2y9jKpvMW78nJgx8QKtxjDVrwbZG+wvDOmVbifHyOUOQJXxqEy6r0faRrPzTQ==",
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.1.tgz",
|
||||
"integrity": "sha512-0EcS9wCFEzLvfiks7omJ+SiYJAiD+TzK4Pcw1UlUoGnhUxDcMKjt0P7x8wEb0u6OHu8Nb98WG3nxtlF5C7bvUQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"dezalgo": "1.0.3",
|
||||
"hexoid": "1.0.0",
|
||||
"once": "1.4.0",
|
||||
"qs": "6.9.3"
|
||||
"dezalgo": "^1.0.4",
|
||||
"hexoid": "^1.0.0",
|
||||
"once": "^1.4.0",
|
||||
"qs": "^6.11.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://ko-fi.com/tunnckoCore/commissions"
|
||||
}
|
||||
},
|
||||
"node_modules/formidable/node_modules/qs": {
|
||||
"version": "6.9.3",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.9.3.tgz",
|
||||
"integrity": "sha512-EbZYNarm6138UKKq46tdx08Yo/q9ZhFoAXAI1meAFd2GtbRDhbZY2WQSICskT0c5q99aFzLG1D4nvTk9tqfXIw==",
|
||||
"version": "6.11.0",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
|
||||
"integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"side-channel": "^1.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.6"
|
||||
},
|
||||
@@ -12651,9 +12654,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"dezalgo": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.3.tgz",
|
||||
"integrity": "sha512-K7i4zNfT2kgQz3GylDw40ot9GAE47sFZ9EXHFSPP6zONLgH6kWXE0KWJchkbQJLBkRazq4APwZ4OwiFFlT95OQ==",
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz",
|
||||
"integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"asap": "^2.0.0",
|
||||
@@ -13380,22 +13383,25 @@
|
||||
}
|
||||
},
|
||||
"formidable": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/formidable/-/formidable-2.0.1.tgz",
|
||||
"integrity": "sha512-rjTMNbp2BpfQShhFbR3Ruk3qk2y9jKpvMW78nJgx8QKtxjDVrwbZG+wvDOmVbifHyOUOQJXxqEy6r0faRrPzTQ==",
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.1.tgz",
|
||||
"integrity": "sha512-0EcS9wCFEzLvfiks7omJ+SiYJAiD+TzK4Pcw1UlUoGnhUxDcMKjt0P7x8wEb0u6OHu8Nb98WG3nxtlF5C7bvUQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"dezalgo": "1.0.3",
|
||||
"hexoid": "1.0.0",
|
||||
"once": "1.4.0",
|
||||
"qs": "6.9.3"
|
||||
"dezalgo": "^1.0.4",
|
||||
"hexoid": "^1.0.0",
|
||||
"once": "^1.4.0",
|
||||
"qs": "^6.11.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"qs": {
|
||||
"version": "6.9.3",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.9.3.tgz",
|
||||
"integrity": "sha512-EbZYNarm6138UKKq46tdx08Yo/q9ZhFoAXAI1meAFd2GtbRDhbZY2WQSICskT0c5q99aFzLG1D4nvTk9tqfXIw==",
|
||||
"dev": true
|
||||
"version": "6.11.0",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
|
||||
"integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"side-channel": "^1.0.4"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -36,7 +36,8 @@ export class AuthenticationController {
|
||||
console.log('On redirige');
|
||||
const user : User = request.user
|
||||
if (user.isEnabledTwoFactorAuth === false || user.isTwoFactorAuthenticated === true)
|
||||
return response.status(200).redirect('http://transcendance:8080/#/profile');
|
||||
{console.log('ON VA VERS PROFILE');return response.status(200).redirect('http://transcendance:8080/#/profile');}
|
||||
console.log('ON VA VERS 2FA')
|
||||
return response.status(200).redirect('http://transcendance:8080/#/2fa');
|
||||
}
|
||||
|
||||
@@ -69,24 +70,17 @@ export class AuthenticationController {
|
||||
}
|
||||
}
|
||||
|
||||
@Post('2fa/turn-on')
|
||||
|
||||
@Post('2fa/check')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
async verify(@Req() request, @Body() {twoFaCode} : TwoFaDto, @Res() response){
|
||||
const user : User = request.user;
|
||||
if (user.isEnabledTwoFactorAuth === true)
|
||||
{
|
||||
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
|
||||
}
|
||||
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.authenticateUserWith2FA(request.user.id);
|
||||
console.log('ON REDIRIGE');
|
||||
return response.status(200).redirect('http://transcendance:8080/');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ export class AuthenticationService {
|
||||
}
|
||||
|
||||
async verify2FaCode(user : User, code : string) {
|
||||
console.log("User : " + user.username);
|
||||
return authenticator.verify({ token: code, secret: user.secretTwoFactorAuth });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { IsBoolean, IsEmail, IsOptional, IsString } from 'class-validator';
|
||||
import { IsBoolean, IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
||||
import { isSet } from 'util/types';
|
||||
|
||||
export class CreateUsersDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
readonly username: string;
|
||||
@IsString()
|
||||
readonly fortyTwoId: string;
|
||||
@IsEmail()
|
||||
readonly email: string;
|
||||
|
||||
@@ -10,6 +10,7 @@ import { UsersService } from './users.service';
|
||||
import { User } from './entities/user.entity';
|
||||
import { of } from 'rxjs';
|
||||
import { storageForAvatar } from 'src/common/constants/constants';
|
||||
import { use } from 'passport';
|
||||
|
||||
|
||||
@Controller('user')
|
||||
@@ -39,7 +40,6 @@ export class UsersController {
|
||||
@Get()
|
||||
findOne(@Req() req) {
|
||||
console.log("Backend Getting current user");
|
||||
// console.log(this.usersService.findOne(req.user.id));
|
||||
return this.usersService.findOne(req.user.id);
|
||||
}
|
||||
|
||||
@@ -63,12 +63,19 @@ export class UsersController {
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Patch()
|
||||
update(@Req() req, @Body(new ValidationPipe()) usersUpdateDto: UpdateUsersDto, @Res() response) {
|
||||
async update(@Req() req, @Body(new ValidationPipe()) usersUpdateDto: UpdateUsersDto, @Res() response) {
|
||||
console.log("DANS PATCH USERS");
|
||||
this.usersService.update(req.user.id, usersUpdateDto);
|
||||
const user : User = req.user;
|
||||
const user = await this.usersService.update(req.user.id, usersUpdateDto);
|
||||
// const user : User = req.user;
|
||||
if (user.isEnabledTwoFactorAuth === false && user.isTwoFactorAuthenticated === true)
|
||||
this.usersService.setIsTwoFactorAuthenticatedWhenLogout(user.id);
|
||||
console.log ("Enbale 2FA " + user.isEnabledTwoFactorAuth + " Is authenticated " + user.isTwoFactorAuthenticated);
|
||||
if (user.isEnabledTwoFactorAuth === true && user.isTwoFactorAuthenticated === false)
|
||||
return response.status.redirect("http://transcendance:8080/#/2fa");
|
||||
{
|
||||
console.log("On est dans la boucle de redirection 2FA / Au niveau de l'update du user")
|
||||
return response.status(200).redirect("http://transcendance:8080/#/2fa");
|
||||
}
|
||||
return response.status(200).redirect("http://transcendance:8080/#/profile")
|
||||
}
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
|
||||
@@ -34,13 +34,13 @@ export class UsersService {
|
||||
|
||||
async findOne(id: string) {
|
||||
console.log(`FIND ONE USER SERVICE Find user ${id}`);
|
||||
const user = await this.userRepository.createQueryBuilder('user')
|
||||
const user = await this.userRepository.createQueryBuilder('user')
|
||||
.leftJoinAndSelect('user.stats', 'stats')
|
||||
.where('user.id = :id', { id: +id })
|
||||
.getOne();
|
||||
if (!user)
|
||||
throw new NotFoundException(`The requested user not found.`);
|
||||
console.log(`FIND ONE USER SERVICE The requested user found.`
|
||||
console.log(`FIND ONE USER SERVICE The requested user found.` + user.username
|
||||
+ user.stats.id + user.stats.winGame + user.stats.loseGame + user.stats.drawGame + user.stats.totalGame);
|
||||
const partialUser : Partial<User> = {
|
||||
username: user.username,
|
||||
@@ -49,6 +49,7 @@ export class UsersService {
|
||||
status: user.status,
|
||||
stats: user.stats,
|
||||
};
|
||||
console.log(`Returned Partial User.` + partialUser.username + user.username);
|
||||
return partialUser;
|
||||
}
|
||||
|
||||
@@ -115,7 +116,11 @@ export class UsersService {
|
||||
}
|
||||
|
||||
async enableTwoFactorAuth(id: string) {
|
||||
return this.userRepository.update(id, {isEnabledTwoFactorAuth: true, isTwoFactorAuthenticated: true});
|
||||
return this.userRepository.update(id, {isEnabledTwoFactorAuth: true});
|
||||
}
|
||||
|
||||
async authenticateUserWith2FA(id: string) {
|
||||
return this.userRepository.update(id, { isTwoFactorAuthenticated: true})
|
||||
}
|
||||
|
||||
async setIsTwoFactorAuthenticatedWhenLogout(id: number) {
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
})()
|
||||
|
||||
const submitCode = async() => {
|
||||
const response = await fetch("http://transcendance:8080/api/v2/auth/2fa/turn-on",
|
||||
const response = await fetch("http://transcendance:8080/api/v2/auth/2fa/check",
|
||||
{
|
||||
method : 'POST',
|
||||
headers : {
|
||||
@@ -47,7 +47,7 @@
|
||||
}
|
||||
if (response.status === 200) {
|
||||
push('/profile');
|
||||
console.log('vaid Code for 2FA')
|
||||
console.log('valid Code for 2FA')
|
||||
}
|
||||
};
|
||||
|
||||
@@ -102,4 +102,4 @@
|
||||
font-size: 0.8em;
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
onMount( async() => {
|
||||
user = await fetch('http://transcendance:8080/api/v2/user')
|
||||
.then( (x) => x.json() );
|
||||
// do a .catch?
|
||||
// do a .catch?
|
||||
|
||||
if (user === undefined) {
|
||||
console.log('User did not load, something more official should prolly happen')
|
||||
@@ -80,7 +80,6 @@
|
||||
.then(response => response.json())
|
||||
// .then((result) => console.log(result))
|
||||
// .then(() => console.log('successful sub of new settings'))
|
||||
.then(() => push('/profile'));
|
||||
}
|
||||
|
||||
};
|
||||
@@ -206,4 +205,4 @@
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user