nodemailer
This commit is contained in:
parent
dea010ac34
commit
21e906f768
14
package-lock.json
generated
14
package-lock.json
generated
@ -22,6 +22,7 @@
|
||||
"class-validator": "^0.13.2",
|
||||
"moment": "^2.29.3",
|
||||
"mysql2": "^2.3.3",
|
||||
"nodemailer": "^6.7.3",
|
||||
"passport": "^0.5.2",
|
||||
"passport-jwt": "^4.0.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
@ -7107,6 +7108,14 @@
|
||||
"integrity": "sha512-XxYDdcQ6eKqp/YjI+tb2C5WM2LgjnZrfYg4vgQt49EK268b6gYCHsBLrK2qvJo4FmCtqmKezb0WZFK4fkrZNsg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/nodemailer": {
|
||||
"version": "6.7.3",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.7.3.tgz",
|
||||
"integrity": "sha512-KUdDsspqx89sD4UUyUKzdlUOper3hRkDVkrKh/89G+d9WKsU5ox51NWS4tB1XR5dPUdR4SP0E3molyEfOvSa3g==",
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/nopt": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz",
|
||||
@ -15225,6 +15234,11 @@
|
||||
"integrity": "sha512-XxYDdcQ6eKqp/YjI+tb2C5WM2LgjnZrfYg4vgQt49EK268b6gYCHsBLrK2qvJo4FmCtqmKezb0WZFK4fkrZNsg==",
|
||||
"dev": true
|
||||
},
|
||||
"nodemailer": {
|
||||
"version": "6.7.3",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.7.3.tgz",
|
||||
"integrity": "sha512-KUdDsspqx89sD4UUyUKzdlUOper3hRkDVkrKh/89G+d9WKsU5ox51NWS4tB1XR5dPUdR4SP0E3molyEfOvSa3g=="
|
||||
},
|
||||
"nopt": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz",
|
||||
|
@ -34,6 +34,7 @@
|
||||
"class-validator": "^0.13.2",
|
||||
"moment": "^2.29.3",
|
||||
"mysql2": "^2.3.3",
|
||||
"nodemailer": "^6.7.3",
|
||||
"passport": "^0.5.2",
|
||||
"passport-jwt": "^4.0.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
|
@ -49,6 +49,7 @@ import { TipoEntrada } from './tipo-entrada/entity/tipo-entrada.entity';
|
||||
import { TipoUsuario } from './tipo-usuario/entity/tipo-usuario.entity';
|
||||
import { UploadFileModule } from './upload-file/upload-file.module';
|
||||
import { Usuario } from './usuario/entity/usuario.entity';
|
||||
import { NodemailerModule } from './nodemailer/nodemailer.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@ -115,6 +116,7 @@ import { Usuario } from './usuario/entity/usuario.entity';
|
||||
BcryptModule,
|
||||
UploadFileModule,
|
||||
CronModule,
|
||||
NodemailerModule,
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
12
src/nodemailer/dto/nodemailer-message.dto.ts
Normal file
12
src/nodemailer/dto/nodemailer-message.dto.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { IsEmail, IsInt, IsString } from 'class-validator';
|
||||
|
||||
export class NodemailerMessageDto {
|
||||
@IsEmail()
|
||||
email: string;
|
||||
|
||||
@IsString()
|
||||
subject: string;
|
||||
|
||||
@IsString()
|
||||
html: string;
|
||||
}
|
8
src/nodemailer/nodemailer.module.ts
Normal file
8
src/nodemailer/nodemailer.module.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { NodemailerService } from './nodemailer.service';
|
||||
|
||||
@Module({
|
||||
providers: [NodemailerService],
|
||||
exports: [NodemailerService],
|
||||
})
|
||||
export class NodemailerModule {}
|
18
src/nodemailer/nodemailer.service.spec.ts
Normal file
18
src/nodemailer/nodemailer.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { NodemailerService } from './nodemailer.service';
|
||||
|
||||
describe('NodemailerService', () => {
|
||||
let service: NodemailerService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [NodemailerService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<NodemailerService>(NodemailerService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
25
src/nodemailer/nodemailer.service.ts
Normal file
25
src/nodemailer/nodemailer.service.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import * as nodemailer from 'nodemailer';
|
||||
import { NodemailerMessageDto } from './dto/nodemailer-message.dto';
|
||||
|
||||
@Injectable()
|
||||
export class NodemailerService {
|
||||
constructor(private configService: ConfigService) {}
|
||||
|
||||
sendEmail(message: NodemailerMessageDto) {
|
||||
const transporter = nodemailer.createTransport({
|
||||
service: this.configService.get<string>('NODEMAILER_SERVICE'),
|
||||
auth: {
|
||||
user: this.configService.get<string>('NODEMAILER_USER'),
|
||||
pass: this.configService.get<string>('NODEMAILER_PASWORD'),
|
||||
},
|
||||
});
|
||||
|
||||
return transporter.sendMail({
|
||||
to: message.email,
|
||||
subject: message.subject,
|
||||
html: message.html,
|
||||
});
|
||||
}
|
||||
}
|
@ -5,7 +5,8 @@ import { UsuarioController } from './usuario.controller';
|
||||
import { UsuarioService } from './usuario.service';
|
||||
import { Usuario } from './entity/usuario.entity';
|
||||
import { BcryptModule } from '../bcrypt/bcrypt.module';
|
||||
// import { CarreraModule } from '../carrera/carrera.module';
|
||||
import { CarreraModule } from '../carrera/carrera.module';
|
||||
import { NodemailerModule } from '../nodemailer/nodemailer.module';
|
||||
import { InstitucionModule } from '../institucion/institucion.module';
|
||||
import { TipoUsuarioModule } from '../tipo-usuario/tipo-usuario.module';
|
||||
|
||||
@ -14,8 +15,9 @@ import { TipoUsuarioModule } from '../tipo-usuario/tipo-usuario.module';
|
||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
TypeOrmModule.forFeature([Usuario]),
|
||||
BcryptModule,
|
||||
// CarreraModule,
|
||||
CarreraModule,
|
||||
InstitucionModule,
|
||||
NodemailerModule,
|
||||
TipoUsuarioModule,
|
||||
],
|
||||
controllers: [UsuarioController],
|
||||
|
@ -10,8 +10,9 @@ import { Carrera } from '../carrera/entity/carrera.entity';
|
||||
import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
import { TipoUsuario } from '../tipo-usuario/entity/tipo-usuario.entity';
|
||||
import { BcryptService } from '../bcrypt/bcrypt.service';
|
||||
// import { CarreraService } from '../carrera/carrera.service';
|
||||
import { CarreraService } from '../carrera/carrera.service';
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
import { NodemailerService } from '../nodemailer/nodemailer.service';
|
||||
import { TipoUsuarioService } from '../tipo-usuario/tipo-usuario.service';
|
||||
|
||||
@Injectable()
|
||||
@ -19,11 +20,35 @@ export class UsuarioService {
|
||||
constructor(
|
||||
@InjectRepository(Usuario) private repository: Repository<Usuario>,
|
||||
private bcryptService: BcryptService,
|
||||
// private carreraService: CarreraService,
|
||||
private carreraService: CarreraService,
|
||||
private institucionService: InstitucionService,
|
||||
private nodemailerService: NodemailerService,
|
||||
private tipoUsuarioService: TipoUsuarioService,
|
||||
) {}
|
||||
|
||||
correoPassword(password: string) {
|
||||
return `<h2>Estimado usuario, su registro se realizó con éxito.</h2>
|
||||
<p>Para acceder al servicio debe hacerlo con los siguientes datos:</p>
|
||||
|
||||
<p>• Usuario: Número de cuenta o número de trabajador</p>
|
||||
|
||||
<p>• Contraseña: ${password}</p>
|
||||
|
||||
<p style=" text-align: justify; text-justify: inter-word;">
|
||||
El presente registro le permite hacer uso del préstamo del equipo de cómputo seleccionado, el cual puede ser utilizado únicamente al interior de la FES Acatlán.
|
||||
Para acceder al servicio es obligatorio y su responsabilidad leer los lineamientos "pcpuma-solicita" en la siguiente liga: <u>https://www.acatlan.unam.mx/pcpuma/Lineamientos.html</u>
|
||||
Hacemos de su conocimiento que la presente información es confidencial y debe ser tratada como tal, es de uso exclusivo para el usuario al que fue asignada y se encuentra protegida por la normatividad de la Universidad Nacional Autónoma de México en la materia, cualquier uso no autorizado o indebido se hará del conocimiento de la autoridad universitaria.
|
||||
Puede consultar nuestro aviso de privacidad en: <u>https://www.acatlan.unam.mx/normatividad</u>.
|
||||
</p>
|
||||
|
||||
<p>Para mayor información o duda contáctenos por este medio.</p>
|
||||
|
||||
<p>Atte.</p>
|
||||
|
||||
<p>Pc Puma Solicita</p>
|
||||
`;
|
||||
}
|
||||
|
||||
async findAll(filtros: {
|
||||
pagina: string;
|
||||
id_carrera?: string;
|
||||
@ -43,18 +68,16 @@ export class UsuarioService {
|
||||
const tipoUsuario = filtros.id_tipo_usuario
|
||||
? await this.tipoUsuarioService.findById(Number(filtros.id_tipo_usuario))
|
||||
: null;
|
||||
/* Terminar cuando se tengan las fuinciones faltantes */
|
||||
// const carrera = filtros.id_carrera
|
||||
// ? await this.carreraService.findById(Number(filtros.id_carrera))
|
||||
// : null;
|
||||
const carrera = filtros.id_carrera
|
||||
? await this.carreraService.findById(Number(filtros.id_carrera))
|
||||
: null;
|
||||
|
||||
/* buscar like */
|
||||
/* buscar usnado like */
|
||||
if (filtros.usuario) busqueda.usuario = filtros.usuario;
|
||||
if (institucion) busqueda.institucion = institucion;
|
||||
if (tipoUsuario) busqueda.tipoUsuario = tipoUsuario;
|
||||
// if (carrera) busqueda.carrera = carrera;
|
||||
/* falta página */
|
||||
console.log(busqueda);
|
||||
if (carrera) busqueda.carrera = carrera;
|
||||
/* falta página, paginado */
|
||||
return this.repository.find(busqueda);
|
||||
}
|
||||
|
||||
@ -111,9 +134,15 @@ export class UsuarioService {
|
||||
);
|
||||
usuario.telefono = telefono;
|
||||
usuario.password = this.bcryptService.encriptar(password);
|
||||
/* Mandar correo con contraseña */
|
||||
return this.repository.save(usuario);
|
||||
})
|
||||
.then((usuario) =>
|
||||
this.nodemailerService.sendEmail({
|
||||
email: `${usuario.usuario}@pcpuma.acatlan.unam.mx`,
|
||||
subject: 'Credenciales Pc Puma',
|
||||
html: this.correoPassword(password),
|
||||
}),
|
||||
)
|
||||
.then((_) => ({ message: 'Se creo correctamente un usuario.' }));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user