Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seguridad en frontend #13

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
78 changes: 78 additions & 0 deletions backend-concecionario/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions backend-concecionario/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@
"!*/__tests__"
],
"dependencies": {
"@loopback/authentication": "^9.0.4",
"@loopback/boot": "^5.0.4",
"@loopback/core": "^4.0.4",
"@loopback/repository": "^5.0.4",
"@loopback/rest": "^12.0.4",
"@loopback/rest-explorer": "^5.0.4",
"@loopback/security": "^0.8.4",
"@loopback/service-proxy": "^5.0.4",
"crypto-js": "^4.1.1",
"jsonwebtoken": "^8.5.1",
"loopback-connector-mongodb": "^5.6.0",
"node-fetch": "^2.6.7",
"parse-bearer-token": "^1.0.1",
"password-generator": "^2.3.2",
"tslib": "^2.0.0"
},
Expand Down
7 changes: 7 additions & 0 deletions backend-concecionario/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {RestApplication} from '@loopback/rest';
import {ServiceMixin} from '@loopback/service-proxy';
import path from 'path';
import {MySequence} from './sequence';
import { AuthenticationComponent, registerAuthenticationStrategy } from '@loopback/authentication';
import { EstrategiaAdministrador } from './strategies/Admin.strategy';
import { EstrategiaVendedor } from './strategies/Vende.strategy';

export {ApplicationConfig};

Expand Down Expand Up @@ -40,5 +43,9 @@ export class BackendConcecionarioApplication extends BootMixin(
nested: true,
},
};
registerAuthenticationStrategy(this, EstrategiaAdministrador);
registerAuthenticationStrategy(this, EstrategiaVendedor);
this.component(AuthenticationComponent);

}
}
24 changes: 22 additions & 2 deletions backend-concecionario/src/controllers/administrador.controller.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { service } from '@loopback/core';
import {
Count,
CountSchema,
Expand All @@ -16,14 +17,20 @@ import {
del,
requestBody,
response,
HttpErrors,
} from '@loopback/rest';
import {Administrador} from '../models';
import {AdministradorRepository} from '../repositories';
import {AutenticacionService, NotificacionService} from '../services';

export class AdministradorController {

constructor(
@repository(AdministradorRepository)
public administradorRepository : AdministradorRepository,
@service(NotificacionService)
public servicioNotificacion: NotificacionService

) {}

@post('/Administradores')
Expand All @@ -43,8 +50,21 @@ export class AdministradorController {
},
})
administrador: Omit<Administrador, 'id'>,
): Promise<Administrador> {
return this.administradorRepository.create(administrador);
): Promise<Administrador|any> {
let clave = this.servicioNotificacion.GenerarClave();
let claveCifrada = this.servicioNotificacion.CifrarClave(clave);
administrador.contrasena = claveCifrada;//A la persona que llega le debemos asignar a la clave esa clave cifrada. dificil leer en BD
let admin = this.administradorRepository.create(administrador)
let asunto = "Registro en plataforma como Administrador"
let mensaje = "Bienvenido a nuestra plataforma" + administrador.nombres + "" + administrador.apellidos + " su clave temporal es: " + clave + " y su usuario es: " + administrador.correo;
let enviadoEmail = this.servicioNotificacion.notificacionEmail(administrador.correo, asunto, mensaje);
let enviadoSms = this.servicioNotificacion.notificacionSms(administrador.telefono, mensaje);
if (enviadoEmail && enviadoSms) {
return admin
} else {
return new HttpErrors[500]("No se pudo crear el Administrador")
}
//return this.administradorRepository.create(administrador);
}

@get('/Administradores/count')
Expand Down
3 changes: 3 additions & 0 deletions backend-concecionario/src/controllers/factura.controller.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { authenticate } from '@loopback/authentication';
import {
Count,
CountSchema,
Expand All @@ -20,6 +21,8 @@ import {
import {Factura} from '../models';
import {FacturaRepository} from '../repositories';

@authenticate("vende")

export class FacturaController {
constructor(
@repository(FacturaRepository)
Expand Down
8 changes: 7 additions & 1 deletion backend-concecionario/src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export * from './factura.controller';
export * from './vendedor-venta.controller';
export * from './venta-vendedor.controller';
export * from './factura-venta.controller';
export * from './vehiculo-venta.controller';
export * from './venta-vehiculo.controller';
export * from './proveedor-vehiculo.controller';
export * from './vehiculo-proveedor.controller';
Expand All @@ -16,3 +15,10 @@ export * from './vehiculo.controller';
export * from './proveedor.controller';
export * from './usuario.controller';
export * from './administrador.controller';
export * from './proveedor.controller';
export * from './proveedor-vehiculo.controller';
export * from './vehiculo-proveedor.controller';
export * from './vehiculo.controller';
export * from './venta-vendedor.controller';
export * from './venta-vehiculo.controller';
export * from './venta.controller';
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ProveedorVehiculoController {
@param.path.string('id') id: string,
@param.query.object('filter') filter?: Filter<Vehiculo>,
): Promise<Vehiculo[]> {
return this.proveedorRepository.SuProveedor(id).find(filter);
return this.proveedorRepository.susVehiculos(id).find(filter);
}

@post('/proveedors/{id}/vehiculos', {
Expand All @@ -67,7 +67,7 @@ export class ProveedorVehiculoController {
},
}) vehiculo: Omit<Vehiculo, 'id'>,
): Promise<Vehiculo> {
return this.proveedorRepository.SuProveedor(id).create(vehiculo);
return this.proveedorRepository.susVehiculos(id).create(vehiculo);
}

@patch('/proveedors/{id}/vehiculos', {
Expand All @@ -90,7 +90,7 @@ export class ProveedorVehiculoController {
vehiculo: Partial<Vehiculo>,
@param.query.object('where', getWhereSchemaFor(Vehiculo)) where?: Where<Vehiculo>,
): Promise<Count> {
return this.proveedorRepository.SuProveedor(id).patch(vehiculo, where);
return this.proveedorRepository.susVehiculos(id).patch(vehiculo, where);
}

@del('/proveedors/{id}/vehiculos', {
Expand All @@ -105,6 +105,6 @@ export class ProveedorVehiculoController {
@param.path.string('id') id: string,
@param.query.object('where', getWhereSchemaFor(Vehiculo)) where?: Where<Vehiculo>,
): Promise<Count> {
return this.proveedorRepository.SuProveedor(id).delete(where);
return this.proveedorRepository.susVehiculos(id).delete(where);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ export class VehiculoProveedorController {
async getProveedor(
@param.path.string('id') id: typeof Vehiculo.prototype.id,
): Promise<Proveedor> {
return this.vehiculoRepository.suProveedor(id);
return this.vehiculoRepository.SuProveedor(id);
}
}
Loading