ce1d1396e0
Bypass solo en desarrollo; pruebas y producción validan header turnstile vía HTTPS nativo. Co-authored-by: Cursor <cursoragent@cursor.com>
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
import { ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
import { Serealize } from '../interceptors/serialize.interceptor';
|
|
import { TurnstileGuard } from '../guards/turnstile.guard';
|
|
import { AuthService } from './auth.service';
|
|
import { LoginAdminDto } from './dto/input/login-admin.dto';
|
|
import { LoginOperadorDto } from './dto/input/login-operador.dto';
|
|
import { LoginUsuarioDto } from './dto/input/login-usuario.dto';
|
|
import { AuthTokenOutputDto } from './dto/output/token.dto';
|
|
|
|
@Controller('auth')
|
|
@ApiTags('auth')
|
|
export class AuthController {
|
|
constructor(private authService: AuthService) {}
|
|
|
|
@Serealize(AuthTokenOutputDto)
|
|
@UseGuards(TurnstileGuard)
|
|
@Post('login-admin')
|
|
@ApiOperation({ description: 'Login del admin.' })
|
|
@ApiBody({
|
|
description: 'Variables que necesita el endpoint.',
|
|
examples: { ejemplo: { value: { operador: '', password: '' } } },
|
|
})
|
|
loginAdmin(@Body() body: LoginAdminDto) {
|
|
return this.authService.loginAdmin(body.operador, body.password);
|
|
}
|
|
|
|
@Serealize(AuthTokenOutputDto)
|
|
@UseGuards(TurnstileGuard)
|
|
@Post('login-operador')
|
|
@ApiOperation({ description: 'Login del operador.' })
|
|
@ApiBody({
|
|
description: 'Variables que necesita el endpoint.',
|
|
examples: {
|
|
ejemplo: { value: { id_modulo: 1, operador: '', password: '' } },
|
|
},
|
|
})
|
|
loginOperador(@Body() body: LoginOperadorDto) {
|
|
return this.authService.loginOperador(
|
|
body.id_modulo,
|
|
body.operador,
|
|
body.password,
|
|
);
|
|
}
|
|
|
|
@Serealize(AuthTokenOutputDto)
|
|
@UseGuards(TurnstileGuard)
|
|
@Post('login-usuario')
|
|
@ApiOperation({ description: 'Login del usuario.' })
|
|
@ApiBody({
|
|
description: 'Variables que necesita el endpoint.',
|
|
examples: { ejemplo: { value: { password: '', usuario: '' } } },
|
|
})
|
|
loginUsuario(@Body() body: LoginUsuarioDto) {
|
|
return this.authService.loginUsuario(body.usuario, body.password);
|
|
}
|
|
|
|
@Get('validar-token')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@ApiOperation({ description: 'Validamos que el un token sea válido.' })
|
|
validarToken() {
|
|
return { valido: true };
|
|
}
|
|
}
|