added alumno_inscrito and others Ep
This commit is contained in:
@@ -7,3 +7,12 @@ export class CreateUserDto {
|
||||
@IsString()
|
||||
password: string;
|
||||
}
|
||||
|
||||
export class changePasswordDto {
|
||||
|
||||
@IsString()
|
||||
password: string;
|
||||
|
||||
@IsString()
|
||||
newPassword: string;
|
||||
}
|
||||
@@ -6,15 +6,17 @@ import {
|
||||
UseGuards,
|
||||
Request,
|
||||
Res,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
import type { Response } from 'express';
|
||||
import { UserService } from './user.service';
|
||||
import { CreateUserDto } from './dto/create-user.dto';
|
||||
import { changePasswordDto, CreateUserDto } from './dto/create-user.dto';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { JwtAuthGuard } from './jwt.guard';
|
||||
|
||||
@Controller('user')
|
||||
export class UserController {
|
||||
constructor(private readonly userService: UserService) {}
|
||||
constructor(private readonly userService: UserService) { }
|
||||
|
||||
@Post()
|
||||
async Login(@Body() data: CreateUserDto, @Res() res: Response) {
|
||||
@@ -23,8 +25,16 @@ export class UserController {
|
||||
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@Get('/validate-token')
|
||||
getProfile(@Request() req) {
|
||||
getProfile(@Req() req) {
|
||||
return req.user;
|
||||
}
|
||||
|
||||
@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 } from './dto/create-user.dto';
|
||||
import { changePasswordDto, CreateUserDto } from './dto/create-user.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { User } from './entities/user.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
@@ -12,7 +12,7 @@ export class UserService {
|
||||
@InjectRepository(User)
|
||||
private userRepository: Repository<User>,
|
||||
private jwtService: JwtService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async findOneByNameandPassword(data: CreateUserDto): Promise<User> {
|
||||
const { usuario, password } = data;
|
||||
@@ -56,5 +56,16 @@ export class UserService {
|
||||
}
|
||||
return student;
|
||||
}
|
||||
|
||||
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