mirror of
https://github.com/dadosfera/maestro.git
synced 2026-08-31 19:58:21 +00:00
FEAT: reset password
This commit is contained in:
@@ -13,6 +13,8 @@ import {
|
||||
AuthDismissTotpMfaRequest,
|
||||
AuthVerifyTotpMfaRequest,
|
||||
AuthChangePasswordRequest,
|
||||
AuthResetPasswordRequest,
|
||||
AuthConfirmResetPasswordRequest,
|
||||
} from '@victorradael/protospack';
|
||||
|
||||
export class AuthClientService implements OnModuleInit {
|
||||
@@ -206,4 +208,38 @@ export class AuthClientService implements OnModuleInit {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async resetPassword({ username }: AuthResetPasswordRequest): Promise<any> {
|
||||
console.log('AuthClientService', 'resetPassword');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.authService.resetPassword({ username }).subscribe({
|
||||
next: resolve,
|
||||
error: (err) => reject(err.details),
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async confirmResetPassword({
|
||||
username,
|
||||
code,
|
||||
newPassword,
|
||||
}: AuthConfirmResetPasswordRequest): Promise<any> {
|
||||
console.log('AuthClientService', 'confirmResetPassword');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.authService
|
||||
.confirmResetPassword({ username, code, newPassword })
|
||||
.subscribe({
|
||||
next: resolve,
|
||||
error: (err) => reject(err.details),
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import {
|
||||
AuthDisableTotpMfaRequest,
|
||||
AuthVerifyTotpMfaRequest,
|
||||
AuthChangePasswordRequest,
|
||||
AuthResetPasswordRequest,
|
||||
AuthConfirmResetPasswordRequest,
|
||||
} from '@victorradael/protospack';
|
||||
|
||||
import { AuthClientService } from 'src/clients/auth/client.service';
|
||||
@@ -169,4 +171,38 @@ export class AuthController {
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Post('reset-password')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async resetPassword(@Body() body: AuthResetPasswordRequest): Promise<any> {
|
||||
console.log(`/auth`, 'reset-password');
|
||||
|
||||
const { username } = body;
|
||||
|
||||
const response = await this.authClient
|
||||
.resetPassword({ username })
|
||||
.catch((err) => {
|
||||
throw ErrorBuilder(err);
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Post('confirm-reset-password')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async confirmResetPassword(
|
||||
@Body() body: AuthConfirmResetPasswordRequest,
|
||||
): Promise<any> {
|
||||
console.log(`/auth`, 'confirm-reset-password');
|
||||
|
||||
const { username, code, newPassword } = body;
|
||||
|
||||
const response = await this.authClient
|
||||
.confirmResetPassword({ username, code, newPassword })
|
||||
.catch((err) => {
|
||||
throw ErrorBuilder(err);
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
+26
-17
@@ -10,23 +10,6 @@ export default function ErrorBuilder(code: string) {
|
||||
console.log(code);
|
||||
|
||||
switch (code) {
|
||||
case ErrorCodes.AUTH.UNAUTHORIZED:
|
||||
return Builder({
|
||||
statusCode: HttpStatus.UNAUTHORIZED,
|
||||
error: 'Não autenticado',
|
||||
message: 'É necessário estar logado para realizar essa operação',
|
||||
code,
|
||||
});
|
||||
|
||||
case ErrorCodes.AUTH.FORBIDDEN:
|
||||
return Builder({
|
||||
statusCode: HttpStatus.FORBIDDEN,
|
||||
error: 'Não autorizado',
|
||||
message:
|
||||
'Você não tem permissões suficientes para realizar essa operação',
|
||||
code,
|
||||
});
|
||||
|
||||
case ErrorCodes.AUTH.WRONG_CREDENTIALS:
|
||||
return Builder({
|
||||
statusCode: HttpStatus.UNAUTHORIZED,
|
||||
@@ -84,6 +67,14 @@ export default function ErrorBuilder(code: string) {
|
||||
code,
|
||||
});
|
||||
|
||||
case ErrorCodes.AUTH.RESET_PASSWORD_CODE_EXPIRED:
|
||||
return Builder({
|
||||
statusCode: HttpStatus.UNAUTHORIZED,
|
||||
error: 'Não permitido',
|
||||
message: 'Token para recuperar senha inválido ou expirado',
|
||||
code,
|
||||
});
|
||||
|
||||
case ErrorCodes.AUTH.WEAK_NEW_PASSWORD:
|
||||
return Builder({
|
||||
statusCode: HttpStatus.BAD_REQUEST,
|
||||
@@ -101,6 +92,24 @@ export default function ErrorBuilder(code: string) {
|
||||
code,
|
||||
});
|
||||
|
||||
case ErrorCodes.AUTH.UNAUTHORIZED:
|
||||
return Builder({
|
||||
statusCode: HttpStatus.UNAUTHORIZED,
|
||||
error: 'Não autenticado',
|
||||
message: 'É necessário estar logado para realizar essa operação',
|
||||
code,
|
||||
});
|
||||
|
||||
case ErrorCodes.AUTH.FORBIDDEN:
|
||||
return Builder({
|
||||
statusCode: HttpStatus.FORBIDDEN,
|
||||
error: 'Não autorizado',
|
||||
message:
|
||||
'Você não tem permissões suficientes para realizar essa operação',
|
||||
code,
|
||||
});
|
||||
|
||||
case ErrorCodes.INTERNAL:
|
||||
case ErrorCodes.UNKNOWN:
|
||||
default:
|
||||
return Builder({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export const Auth = {
|
||||
export const AUTH = {
|
||||
UNAUTHORIZED: 'AUTH.UNAUTHORIZED',
|
||||
FORBIDDEN: 'AUTH.FORBIDDEN',
|
||||
WRONG_CREDENTIALS: 'AUTH.WRONG_CREDENTIALS',
|
||||
@@ -9,13 +9,15 @@ export const Auth = {
|
||||
TOTP_REQUIRED: 'AUTH.TOTP_REQUIRED',
|
||||
CODE_MISMATCH: 'AUTH.CODE_MISMATCH',
|
||||
CODE_ALREADY_USED: 'AUTH.CODE_ALREADY_USED',
|
||||
RESET_PASSWORD_CODE_EXPIRED: 'AUTH.RESET_PASSWORD_CODE_EXPIRED',
|
||||
WEAK_NEW_PASSWORD: 'AUTH.WEAK_NEW_PASSWORD',
|
||||
};
|
||||
|
||||
const ErrorCodes = {
|
||||
UNKNOWN: 'UNKNOWN',
|
||||
RATE_LIMIT: 'RATE_LIMIT',
|
||||
AUTH: Auth,
|
||||
INTERNAL: 'INTERNAL',
|
||||
AUTH,
|
||||
};
|
||||
|
||||
export default ErrorCodes;
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user