Merge branch 'Lino' of https://repositorio.acatlan.unam.mx/mcervantesag/api_directorio into Sam
This commit is contained in:
@@ -14,8 +14,13 @@ import {
|
||||
import { AuthGuard } from './auth.guard';
|
||||
import { AuthService } from './auth.service';
|
||||
import { registerDto } from './dto/registerDto.dto';
|
||||
import {Roles} from '../permissions/roles.decorator'
|
||||
import {RolesGuard} from '../permissions/roles.guard'
|
||||
import {Role} from '../permissions/role.enum'
|
||||
|
||||
|
||||
@Controller('auth')
|
||||
@UseGuards(RolesGuard)
|
||||
export class AuthController {
|
||||
constructor(private authService: AuthService) {}
|
||||
|
||||
@@ -25,7 +30,9 @@ export class AuthController {
|
||||
return this.authService.signIn(data);
|
||||
}
|
||||
|
||||
@UseGuards()
|
||||
@Post("register")
|
||||
@Roles(Role.Admin)
|
||||
async register(@Body() data: registerDto){
|
||||
return this.authService.register(data)
|
||||
}
|
||||
@@ -36,14 +43,18 @@ export class AuthController {
|
||||
return req.user;
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Put('Modificacion/:id')
|
||||
@Roles(Role.Admin)
|
||||
async update(@Param('id') userId: number, @Body() data: registerDto) {
|
||||
return this.authService.update(userId, data);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async remove(@Param('id') userId: number) {
|
||||
await this.authService.remove(userId);
|
||||
@UseGuards(AuthGuard)
|
||||
@Delete('Borrado/:id')
|
||||
@Roles(Role.Admin)
|
||||
async remove(@Param('id') id: number) {
|
||||
await this.authService.remove(id);
|
||||
return { message: 'User successfully deleted' };
|
||||
}
|
||||
|
||||
|
||||
@@ -49,9 +49,11 @@ export class AuthService {
|
||||
if (!checkPassword) {
|
||||
throw new UnauthorizedException('Invalid password');
|
||||
}
|
||||
|
||||
const payload = {
|
||||
id_usuario: user.id_usuario,
|
||||
username: user.usuario,
|
||||
permissions: user.id_tipo_usuario,
|
||||
};
|
||||
const token = this.jwtService.sign(payload);
|
||||
|
||||
|
||||
@@ -6,6 +6,10 @@ export class registerDto{
|
||||
@IsNotEmpty()
|
||||
usuario: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
nombre: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
contraseña: string;
|
||||
|
||||
Reference in New Issue
Block a user