Completed backend of profile page
This commit is contained in:
parent
10cd782a52
commit
e1c7ef7a94
@ -15,7 +15,7 @@ import {
|
|||||||
import { AuthService } from '../services/auth';
|
import { AuthService } from '../services/auth';
|
||||||
import { AuthGuard } from '@nestjs/passport';
|
import { AuthGuard } from '@nestjs/passport';
|
||||||
import { Public } from '../authguards';
|
import { Public } from '../authguards';
|
||||||
import { Responses, Requests } from 'dto';
|
import { Requests, Responses } from 'dto';
|
||||||
import { tfaTypes } from '../entities';
|
import { tfaTypes } from '../entities';
|
||||||
import { toDataURL } from 'qrcode';
|
import { toDataURL } from 'qrcode';
|
||||||
import * as base32 from 'thirty-two';
|
import * as base32 from 'thirty-two';
|
||||||
@ -48,12 +48,22 @@ export default class AuthController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async tfa(
|
@Post('2fa/disable')
|
||||||
req,
|
async tfaDisable(
|
||||||
code: string,
|
@Request() req
|
||||||
type: tfaTypes
|
): Promise<Responses.Auth.RemoveTfaResponse> {
|
||||||
|
await this.authService.setTfaType(req.user, tfaTypes.NONE);
|
||||||
|
await this.authService.revokeAll(req.user);
|
||||||
|
return new Responses.Auth.RemoveTfaResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('2fa/complete')
|
||||||
|
async tfaMail(
|
||||||
|
@Request() req,
|
||||||
|
@Body(new ValidationPipe()) data: Requests.Auth.TfaComplete
|
||||||
): Promise<Responses.Auth.TfaCompletedResponse> {
|
): Promise<Responses.Auth.TfaCompletedResponse> {
|
||||||
if (!(await this.authService.verifyTfa(req.user, code, type))) {
|
const type = data.mail ? tfaTypes.EMAIL : tfaTypes.TOTP;
|
||||||
|
if (!(await this.authService.verifyTfa(req.user, data.code, type))) {
|
||||||
throw new UnauthorizedException('Incorrect 2fa');
|
throw new UnauthorizedException('Incorrect 2fa');
|
||||||
}
|
}
|
||||||
await this.authService.setTfaType(req.user, type);
|
await this.authService.setTfaType(req.user, type);
|
||||||
@ -61,23 +71,7 @@ export default class AuthController {
|
|||||||
return new Responses.Auth.TfaCompletedResponse();
|
return new Responses.Auth.TfaCompletedResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('2fa/complete/mail')
|
@Post('2fa/setup')
|
||||||
async tfaMail(
|
|
||||||
@Request() req,
|
|
||||||
@Body(new ValidationPipe()) data: Requests.Auth.TfaComplete
|
|
||||||
): Promise<Responses.Auth.TfaCompletedResponse> {
|
|
||||||
return await this.tfa(req, data.code, tfaTypes.EMAIL);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('2fa/complete/totp')
|
|
||||||
async tfaTotp(
|
|
||||||
@Request() req,
|
|
||||||
@Body(new ValidationPipe()) data: Requests.Auth.TfaComplete
|
|
||||||
): Promise<Responses.Auth.TfaCompletedResponse> {
|
|
||||||
return await this.tfa(req, data.code, tfaTypes.TOTP);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('2fa/setup')
|
|
||||||
async setupTotp(
|
async setupTotp(
|
||||||
@Request() req,
|
@Request() req,
|
||||||
@Body(new ValidationPipe()) data: Requests.Auth.TfaSetup
|
@Body(new ValidationPipe()) data: Requests.Auth.TfaSetup
|
||||||
@ -93,7 +87,7 @@ export default class AuthController {
|
|||||||
.encode(secret)
|
.encode(secret)
|
||||||
.toString()}&issuer=MFileserver`
|
.toString()}&issuer=MFileserver`
|
||||||
),
|
),
|
||||||
secret
|
base32.encode(secret).toString()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,4 +141,10 @@ export default class AuthController {
|
|||||||
);
|
);
|
||||||
return new Responses.Auth.ChangePasswordResponse();
|
return new Responses.Auth.ChangePasswordResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('logout_all')
|
||||||
|
async logoutAll(@Request() req): Promise<Responses.Auth.LogoutAllResponse> {
|
||||||
|
await this.authService.revokeAll(req.user);
|
||||||
|
return new Responses.Auth.LogoutAllResponse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user