Merge branch 'Lino' of https://repositorio.acatlan.unam.mx/IO/api-AT into Lino
This commit is contained in:
@@ -55,3 +55,11 @@ export class CreateUserDto {
|
||||
@IsNotEmpty()
|
||||
id_perfil: number;
|
||||
}
|
||||
|
||||
export class changePasswordDto {
|
||||
@IsString()
|
||||
password: string;
|
||||
|
||||
@IsString()
|
||||
newPassword: string;
|
||||
}
|
||||
|
||||
@@ -6,11 +6,13 @@ import {
|
||||
UseGuards,
|
||||
Request,
|
||||
Res,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
import type { Response } from 'express';
|
||||
import { UserService } from './user.service';
|
||||
import { CreateUserDto, Login } from './dto/create-user.dto';
|
||||
import { changePasswordDto, CreateUserDto, Login } from './dto/create-user.dto';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { JwtAuthGuard } from './jwt.guard';
|
||||
|
||||
@Controller('user')
|
||||
export class UserController {
|
||||
@@ -23,7 +25,7 @@ export class UserController {
|
||||
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@Get('/validate-token')
|
||||
getProfile(@Request() req) {
|
||||
getProfile(@Req() req) {
|
||||
return req.user;
|
||||
}
|
||||
|
||||
@@ -31,5 +33,13 @@ export class UserController {
|
||||
async createUser(@Body() data: CreateUserDto) {
|
||||
return this.userService.create(data);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('/change-password')
|
||||
async changePassword(@Body() data: changePasswordDto, @Req() req) {
|
||||
const id_usuario = req.user.id;
|
||||
await this.userService.changePassword(data, id_usuario);
|
||||
return { message: 'Contraseña actualizada correctamente' };
|
||||
}
|
||||
}
|
||||
//IO
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
import { CreateUserDto, Login } from './dto/create-user.dto';
|
||||
import { changePasswordDto, CreateUserDto, Login } from './dto/create-user.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Perfil, User } from './entities/user.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
@@ -76,5 +76,15 @@ export class UserService {
|
||||
const user = this.userRepository.create(datauser);
|
||||
return this.userRepository.save(user);
|
||||
}
|
||||
|
||||
async changePassword(data: changePasswordDto, id_usuario: number) {
|
||||
const user = await this.findOneByNameandPassword({
|
||||
usuario: (await this.findOne(id_usuario)).usuario,
|
||||
password: data.password,
|
||||
});
|
||||
|
||||
user.password = data.newPassword;
|
||||
return this.userRepository.save(user);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
|
||||
Reference in New Issue
Block a user