amélioration de la 2Fa
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": {
|
"node_modules/dezalgo": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz",
|
||||||
"integrity": "sha512-K7i4zNfT2kgQz3GylDw40ot9GAE47sFZ9EXHFSPP6zONLgH6kWXE0KWJchkbQJLBkRazq4APwZ4OwiFFlT95OQ==",
|
"integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"asap": "^2.0.0",
|
"asap": "^2.0.0",
|
||||||
@@ -4823,25 +4823,28 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/formidable": {
|
"node_modules/formidable": {
|
||||||
"version": "2.0.1",
|
"version": "2.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/formidable/-/formidable-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.1.tgz",
|
||||||
"integrity": "sha512-rjTMNbp2BpfQShhFbR3Ruk3qk2y9jKpvMW78nJgx8QKtxjDVrwbZG+wvDOmVbifHyOUOQJXxqEy6r0faRrPzTQ==",
|
"integrity": "sha512-0EcS9wCFEzLvfiks7omJ+SiYJAiD+TzK4Pcw1UlUoGnhUxDcMKjt0P7x8wEb0u6OHu8Nb98WG3nxtlF5C7bvUQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dezalgo": "1.0.3",
|
"dezalgo": "^1.0.4",
|
||||||
"hexoid": "1.0.0",
|
"hexoid": "^1.0.0",
|
||||||
"once": "1.4.0",
|
"once": "^1.4.0",
|
||||||
"qs": "6.9.3"
|
"qs": "^6.11.0"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://ko-fi.com/tunnckoCore/commissions"
|
"url": "https://ko-fi.com/tunnckoCore/commissions"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/formidable/node_modules/qs": {
|
"node_modules/formidable/node_modules/qs": {
|
||||||
"version": "6.9.3",
|
"version": "6.11.0",
|
||||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.9.3.tgz",
|
"resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
|
||||||
"integrity": "sha512-EbZYNarm6138UKKq46tdx08Yo/q9ZhFoAXAI1meAFd2GtbRDhbZY2WQSICskT0c5q99aFzLG1D4nvTk9tqfXIw==",
|
"integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"side-channel": "^1.0.4"
|
||||||
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.6"
|
"node": ">=0.6"
|
||||||
},
|
},
|
||||||
@@ -12651,9 +12654,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"dezalgo": {
|
"dezalgo": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz",
|
||||||
"integrity": "sha512-K7i4zNfT2kgQz3GylDw40ot9GAE47sFZ9EXHFSPP6zONLgH6kWXE0KWJchkbQJLBkRazq4APwZ4OwiFFlT95OQ==",
|
"integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"asap": "^2.0.0",
|
"asap": "^2.0.0",
|
||||||
@@ -13380,22 +13383,25 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"formidable": {
|
"formidable": {
|
||||||
"version": "2.0.1",
|
"version": "2.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/formidable/-/formidable-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.1.tgz",
|
||||||
"integrity": "sha512-rjTMNbp2BpfQShhFbR3Ruk3qk2y9jKpvMW78nJgx8QKtxjDVrwbZG+wvDOmVbifHyOUOQJXxqEy6r0faRrPzTQ==",
|
"integrity": "sha512-0EcS9wCFEzLvfiks7omJ+SiYJAiD+TzK4Pcw1UlUoGnhUxDcMKjt0P7x8wEb0u6OHu8Nb98WG3nxtlF5C7bvUQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"dezalgo": "1.0.3",
|
"dezalgo": "^1.0.4",
|
||||||
"hexoid": "1.0.0",
|
"hexoid": "^1.0.0",
|
||||||
"once": "1.4.0",
|
"once": "^1.4.0",
|
||||||
"qs": "6.9.3"
|
"qs": "^6.11.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"qs": {
|
"qs": {
|
||||||
"version": "6.9.3",
|
"version": "6.11.0",
|
||||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.9.3.tgz",
|
"resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
|
||||||
"integrity": "sha512-EbZYNarm6138UKKq46tdx08Yo/q9ZhFoAXAI1meAFd2GtbRDhbZY2WQSICskT0c5q99aFzLG1D4nvTk9tqfXIw==",
|
"integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"side-channel": "^1.0.4"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ export class AuthenticationController {
|
|||||||
console.log('On redirige');
|
console.log('On redirige');
|
||||||
const user : User = request.user
|
const user : User = request.user
|
||||||
if (user.isEnabledTwoFactorAuth === false || user.isTwoFactorAuthenticated === true)
|
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');
|
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)
|
@UseGuards(AuthenticateGuard)
|
||||||
async verify(@Req() request, @Body() {twoFaCode} : TwoFaDto, @Res() response){
|
async verify(@Req() request, @Body() {twoFaCode} : TwoFaDto, @Res() response){
|
||||||
const user : User = request.user;
|
const user : User = request.user;
|
||||||
if (user.isEnabledTwoFactorAuth === true)
|
|
||||||
{
|
|
||||||
console.log('ON EST DANS VERIFY POUR 2FA AUTH CONTROLLER')
|
console.log('ON EST DANS VERIFY POUR 2FA AUTH CONTROLLER')
|
||||||
const isCodeIsValid = await this.authService.verify2FaCode(request.user, twoFaCode);
|
const isCodeIsValid = await this.authService.verify2FaCode(request.user, twoFaCode);
|
||||||
if (isCodeIsValid === false)
|
if (isCodeIsValid === false)
|
||||||
{
|
|
||||||
throw new UnauthorizedException('Wrong Code.');
|
throw new UnauthorizedException('Wrong Code.');
|
||||||
}
|
await this.userService.authenticateUserWith2FA(request.user.id);
|
||||||
await this.userService.enableTwoFactorAuth(request.user.id);
|
|
||||||
console.log('ON REDIRIGE');
|
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/');
|
return response.status(200).redirect('http://transcendance:8080/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ export class AuthenticationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async verify2FaCode(user : User, code : string) {
|
async verify2FaCode(user : User, code : string) {
|
||||||
|
console.log("User : " + user.username);
|
||||||
return authenticator.verify({ token: code, secret: user.secretTwoFactorAuth });
|
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 {
|
export class CreateUsersDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
readonly username: string;
|
readonly username: string;
|
||||||
@IsString()
|
|
||||||
readonly fortyTwoId: string;
|
readonly fortyTwoId: string;
|
||||||
@IsEmail()
|
@IsEmail()
|
||||||
readonly email: string;
|
readonly email: string;
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ export class UsersController {
|
|||||||
@Get()
|
@Get()
|
||||||
findOne(@Req() req) {
|
findOne(@Req() req) {
|
||||||
console.log("Backend Getting current user");
|
console.log("Backend Getting current user");
|
||||||
// console.log(this.usersService.findOne(req.user.id));
|
|
||||||
return this.usersService.findOne(req.user.id);
|
return this.usersService.findOne(req.user.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,12 +62,16 @@ export class UsersController {
|
|||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@Patch()
|
@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");
|
console.log("DANS PATCH USERS");
|
||||||
this.usersService.update(req.user.id, usersUpdateDto);
|
const user = await this.usersService.update(req.user.id, usersUpdateDto);
|
||||||
const user : User = req.user;
|
// const user : User = req.user;
|
||||||
|
console.log ("Enbale 2FA " + user.isEnabledTwoFactorAuth + " Is authenticated " + user.isTwoFactorAuthenticated);
|
||||||
if (user.isEnabledTwoFactorAuth === true && user.isTwoFactorAuthenticated === false)
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export class UsersService {
|
|||||||
.getOne();
|
.getOne();
|
||||||
if (!user)
|
if (!user)
|
||||||
throw new NotFoundException(`The requested user not found.`);
|
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);
|
+ user.stats.id + user.stats.winGame + user.stats.loseGame + user.stats.drawGame + user.stats.totalGame);
|
||||||
const partialUser : Partial<User> = {
|
const partialUser : Partial<User> = {
|
||||||
username: user.username,
|
username: user.username,
|
||||||
@@ -49,6 +49,7 @@ export class UsersService {
|
|||||||
status: user.status,
|
status: user.status,
|
||||||
stats: user.stats,
|
stats: user.stats,
|
||||||
};
|
};
|
||||||
|
console.log(`Returned Partial User.` + partialUser.username + user.username);
|
||||||
return partialUser;
|
return partialUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +116,11 @@ export class UsersService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async enableTwoFactorAuth(id: string) {
|
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) {
|
async setIsTwoFactorAuthenticatedWhenLogout(id: number) {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
})()
|
})()
|
||||||
|
|
||||||
const submitCode = async() => {
|
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',
|
method : 'POST',
|
||||||
headers : {
|
headers : {
|
||||||
@@ -48,9 +48,8 @@
|
|||||||
wrongCode = `Wrong code`;
|
wrongCode = `Wrong code`;
|
||||||
}
|
}
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
userLogout();
|
|
||||||
push('/profile');
|
push('/profile');
|
||||||
console.log('vaid Code for 2FA')
|
console.log('valid Code for 2FA')
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
// .then((result) => console.log(result))
|
// .then((result) => console.log(result))
|
||||||
// .then(() => console.log('successful sub of new settings'))
|
// .then(() => console.log('successful sub of new settings'))
|
||||||
.then(() => push('/profile'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ export const primaryRoutes = {
|
|||||||
const user = await fetch('http://transcendance:8080/api/v2/user')
|
const user = await fetch('http://transcendance:8080/api/v2/user')
|
||||||
.then((resp) => resp.json())
|
.then((resp) => resp.json())
|
||||||
|
|
||||||
console.log('in /test what is in user')
|
console.log('in /profile what is in user')
|
||||||
console.log(user)
|
console.log(user)
|
||||||
|
|
||||||
if (user && user.username)
|
if (user && user.username)
|
||||||
@@ -167,7 +167,7 @@ export const primaryRoutes = {
|
|||||||
const user = await fetch('http://transcendance:8080/api/v2/user')
|
const user = await fetch('http://transcendance:8080/api/v2/user')
|
||||||
.then((resp) => resp.json())
|
.then((resp) => resp.json())
|
||||||
|
|
||||||
console.log('in /test what is in user')
|
console.log('in /profile/* what is in user')
|
||||||
console.log(user)
|
console.log(user)
|
||||||
|
|
||||||
if (user && user.username)
|
if (user && user.username)
|
||||||
|
|||||||
Reference in New Issue
Block a user