nuevos datos de operador
This commit is contained in:
@@ -17,4 +17,16 @@ export class BcryptService {
|
||||
|
||||
return bcrypt.hashSync(password, salt);
|
||||
}
|
||||
|
||||
generarPassword = () => {
|
||||
const length = 8;
|
||||
const charset =
|
||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
const n = charset.length;
|
||||
let password = '';
|
||||
|
||||
for (let i = 0; i < length; i++)
|
||||
password += charset.charAt(Math.floor(Math.random() * n));
|
||||
return password;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
import { IsInt, IsString } from 'class-validator';
|
||||
import { IsEmail, IsInt, IsString } from 'class-validator';
|
||||
|
||||
export class CreateOperadorDto {
|
||||
@IsEmail()
|
||||
correo: string;
|
||||
|
||||
@IsInt()
|
||||
id_institucion: number;
|
||||
|
||||
@IsInt()
|
||||
id_tipo_usuario: number;
|
||||
|
||||
@IsString()
|
||||
nombre: string;
|
||||
|
||||
@IsString()
|
||||
operador: string;
|
||||
|
||||
|
||||
@@ -9,6 +9,12 @@ export class OperadorOutputDto {
|
||||
@Expose()
|
||||
activo;
|
||||
|
||||
@Expose()
|
||||
correo;
|
||||
|
||||
@Expose()
|
||||
nombre;
|
||||
|
||||
@Expose()
|
||||
operador;
|
||||
|
||||
|
||||
@@ -20,6 +20,12 @@ export class Operador {
|
||||
@Column({ type: Boolean, nullable: false, default: false })
|
||||
activo: boolean;
|
||||
|
||||
@Column({ type: String, nullable: false, length: 60 })
|
||||
correo: string;
|
||||
|
||||
@Column({ type: String, nullable: false, length: 100 })
|
||||
nombre: string;
|
||||
|
||||
@Column({ type: String, nullable: false, length: 50 })
|
||||
operador: string;
|
||||
|
||||
|
||||
@@ -30,8 +30,10 @@ export class OperadorController {
|
||||
examples: {
|
||||
ejemplo: {
|
||||
value: {
|
||||
correo: '',
|
||||
id_institucion: 200,
|
||||
id_tipo_usuario: 4,
|
||||
nombre: '',
|
||||
operador: '',
|
||||
password: '',
|
||||
},
|
||||
@@ -43,6 +45,8 @@ export class OperadorController {
|
||||
body.id_institucion,
|
||||
body.id_tipo_usuario,
|
||||
body.operador,
|
||||
body.nombre,
|
||||
body.correo,
|
||||
body.password,
|
||||
);
|
||||
}
|
||||
@@ -100,6 +104,19 @@ export class OperadorController {
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
// reporte() {}
|
||||
|
||||
@Put('update-password')
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({
|
||||
description: 'Enpoint que envía una nueva password al correo del usuario.',
|
||||
})
|
||||
@ApiBody({
|
||||
description: 'Es obligatorio enviar el campo id_usuario.',
|
||||
examples: { ejemplo: { value: { id_usuario: 1 } } },
|
||||
})
|
||||
passwordResset(@Body() body: UpdateOperadorDto) {
|
||||
return this.operadorService.passwordReset(body.id_operador, body.password);
|
||||
}
|
||||
|
||||
@Put()
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({
|
||||
|
||||
@@ -6,12 +6,14 @@ import { OperadorService } from './operador.service';
|
||||
import { Operador } from './entity/operador.entity';
|
||||
import { BcryptModule } from '../bcrypt/bcrypt.module';
|
||||
import { InstitucionModule } from '../institucion/institucion.module';
|
||||
import { NodemailerModule } from '../nodemailer/nodemailer.module';
|
||||
import { TipoUsuarioModule } from '../tipo-usuario/tipo-usuario.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
BcryptModule,
|
||||
InstitucionModule,
|
||||
NodemailerModule,
|
||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
TipoUsuarioModule,
|
||||
TypeOrmModule.forFeature([Operador]),
|
||||
|
||||
@@ -9,6 +9,7 @@ import { Institucion } from '../institucion/entity/institucion.entity';
|
||||
import { Operador } from './entity/operador.entity';
|
||||
import { BcryptService } from '../bcrypt/bcrypt.service';
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
import { NodemailerService } from '../nodemailer/nodemailer.service';
|
||||
import { TipoUsuarioService } from '../tipo-usuario/tipo-usuario.service';
|
||||
|
||||
@Injectable()
|
||||
@@ -17,14 +18,39 @@ export class OperadorService {
|
||||
@InjectRepository(Operador) private repository: Repository<Operador>,
|
||||
private bcryptService: BcryptService,
|
||||
private institucionService: InstitucionService,
|
||||
private nodemailerService: NodemailerService,
|
||||
private tipoUsuarioService: TipoUsuarioService,
|
||||
) {}
|
||||
|
||||
correoPassword(operador, password: string) {
|
||||
return `<h2>Estimado operador, su registro se realizó con éxito.</h2>
|
||||
<p>Para acceder al servicio debe hacerlo con los siguientes datos:</p>
|
||||
|
||||
<p>• Usuario: ${operador}</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 create(
|
||||
id_institucion: number,
|
||||
id_tipo_usuario: number,
|
||||
operador: string,
|
||||
password: string,
|
||||
nombre: string,
|
||||
correo: string,
|
||||
password?: string,
|
||||
) {
|
||||
const institucion = await this.institucionService.findById(id_institucion);
|
||||
const tipoUsuario = await this.tipoUsuarioService.findById(id_tipo_usuario);
|
||||
@@ -46,16 +72,25 @@ export class OperadorService {
|
||||
throw new ConflictException(
|
||||
'Ya existe un operador en esta institución con ese nombre, intenta de nuevo con otro.',
|
||||
);
|
||||
password = this.bcryptService.encriptar(password);
|
||||
if (password!) password = this.bcryptService.generarPassword();
|
||||
return this.repository.save(
|
||||
this.repository.create({
|
||||
correo,
|
||||
institucion,
|
||||
nombre,
|
||||
operador,
|
||||
password,
|
||||
password: this.bcryptService.encriptar(password),
|
||||
tipoUsuario,
|
||||
}),
|
||||
);
|
||||
})
|
||||
.then((operador) =>
|
||||
this.nodemailerService.sendEmail({
|
||||
email: operador.correo,
|
||||
subject: 'Credenciales Pc Puma',
|
||||
html: this.correoPassword(password, operador.correo),
|
||||
}),
|
||||
)
|
||||
.then((_) => ({
|
||||
message: `Se creó correctamente un nuevo ${tipoUsuario.tipo_usuario.toLowerCase()}.`,
|
||||
}));
|
||||
@@ -140,6 +175,25 @@ export class OperadorService {
|
||||
});
|
||||
}
|
||||
|
||||
passwordReset(id_operador: number, password?: string) {
|
||||
return this.findById(id_operador)
|
||||
.then((operador) => {
|
||||
if (!password) password = this.bcryptService.generarPassword();
|
||||
operador.password = this.bcryptService.encriptar(password);
|
||||
return this.repository.save(operador);
|
||||
})
|
||||
.then((operador) =>
|
||||
this.nodemailerService.sendEmail({
|
||||
email: operador.correo,
|
||||
subject: 'Credenciales Pc Puma',
|
||||
html: this.correoPassword(password, operador.correo),
|
||||
}),
|
||||
)
|
||||
.then((_) => ({
|
||||
message: 'Se cambió correctamente la constraseña del operador.',
|
||||
}));
|
||||
}
|
||||
|
||||
update(attrs: Partial<Operador>) {
|
||||
return this.findById(attrs.id_operador)
|
||||
.then((operador) => {
|
||||
|
||||
@@ -5,10 +5,10 @@ import { UsuarioController } from './usuario.controller';
|
||||
import { UsuarioService } from './usuario.service';
|
||||
import { Usuario } from './entity/usuario.entity';
|
||||
import { BcryptModule } from '../bcrypt/bcrypt.module';
|
||||
import { NodemailerModule } from '../nodemailer/nodemailer.module';
|
||||
import { InstitucionModule } from '../institucion/institucion.module';
|
||||
import { InstitucionCarreraModule } from '../institucion-carrera/institucion-carrera.module';
|
||||
import { InstitucionUsuarioModule } from '../institucion-usuario/institucion-usuario.module';
|
||||
import { NodemailerModule } from '../nodemailer/nodemailer.module';
|
||||
import { SoapClientModule } from '../soap-client/soap-client.module';
|
||||
import { TipoUsuarioModule } from '../tipo-usuario/tipo-usuario.module';
|
||||
|
||||
|
||||
@@ -216,20 +216,8 @@ export class UsuarioService {
|
||||
});
|
||||
}
|
||||
|
||||
generarPassword = () => {
|
||||
const length = 8;
|
||||
const charset =
|
||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
const n = charset.length;
|
||||
let password = '';
|
||||
|
||||
for (let i = 0; i < length; i++)
|
||||
password += charset.charAt(Math.floor(Math.random() * n));
|
||||
return password;
|
||||
};
|
||||
|
||||
passwordReset(id_usuario: number) {
|
||||
const password = this.generarPassword();
|
||||
const password = this.bcryptService.generarPassword();
|
||||
|
||||
return this.findById(id_usuario, true, true)
|
||||
.then((usuario) => {
|
||||
@@ -249,7 +237,7 @@ export class UsuarioService {
|
||||
}
|
||||
|
||||
registrar(id_institucion_usuario: number, telefono: string, correo?: string) {
|
||||
const password = this.generarPassword();
|
||||
const password = this.bcryptService.generarPassword();
|
||||
let message =
|
||||
'Se creó correctamente tu cuenta, ingresa a tu correo institucional y consulta tu contraseña para acceder a este servicio.';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user