2FA
This commit is contained in:
@@ -4,15 +4,12 @@ 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';
|
||||
import { request } from 'http';
|
||||
|
||||
@Controller('auth')
|
||||
export class AuthenticationController {
|
||||
|
||||
constructor(private authService: AuthenticationService,
|
||||
private userService: UsersService,
|
||||
// private jwtservice: JwtService
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -74,10 +71,8 @@ export class AuthenticationController {
|
||||
const isCodeIsValid = await this.authService.verify2FaCode(request.user, twoFaCode);
|
||||
if (isCodeIsValid === false)
|
||||
{
|
||||
request.session.destroy();
|
||||
throw new UnauthorizedException('Wrong Code.');
|
||||
}
|
||||
await this.userService.enableTwoFactorAuth(request.user.id);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export class FortyTwoAuthGuard extends AuthGuard('42') {
|
||||
export class AuthenticateGuard implements CanActivate {
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
console.log(request.isAuthenticated());
|
||||
console.log("Is User authenticated : " + request.isAuthenticated());
|
||||
return request.isAuthenticated();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,6 @@ export class FortyTwoStrategy extends PassportStrategy(Strategy, "42") {
|
||||
const user = await this.authenticationService.validateUser(userDTO);
|
||||
if (!user)
|
||||
throw new UnauthorizedException();
|
||||
if (!user.isEnabledTwoFactorAuth)
|
||||
return user;
|
||||
if (userDTO.isEnabledTwoFactorAuth)
|
||||
return user;
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user