Merge pull request #95 from DeimosPr4/dev

Agregar backend para registro de administrador del sistema
This commit is contained in:
Eduardo Quiros 2022-07-11 22:21:14 -06:00 committed by GitHub
commit b2cba486d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 919 additions and 8 deletions

View File

@ -5,7 +5,6 @@
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "api-gateway",
"version": "0.0.1", "version": "0.0.1",
"license": "UNLICENSED", "license": "UNLICENSED",
"dependencies": { "dependencies": {

View File

@ -44,6 +44,14 @@ export class AppController {
return this.appService.allUsers(); return this.appService.allUsers();
} }
@Post('user/loginUser')
inicioSesion(
@Body('email') pEmail: string,
@Body('password') pPassword: string,
) {
return this.appService.inicioSesion(pEmail,pPassword);
}
@Get('user/find/:dni') @Get('user/find/:dni')
findUser( findUser(
@Param('dni') paramUserDNI: string @Param('dni') paramUserDNI: string

View File

@ -71,6 +71,16 @@ export class AppService {
); );
} }
inicioSesion(pEmail: string, pPassword: string) {
const pattern = { cmd: 'loginUser' };
const payload = { email: pEmail, password: pPassword};
return this.clientUserApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
// ====================== COMMUNITIES =============================== // ====================== COMMUNITIES ===============================
//POST parameter from API //POST parameter from API

6
package-lock.json generated Normal file
View File

@ -0,0 +1,6 @@
{
"name": "katoikia-app",
"lockfileVersion": 2,
"requires": true,
"packages": {}
}

File diff suppressed because it is too large Load Diff

View File

@ -28,6 +28,9 @@
"@nestjs/mongoose": "^9.1.1", "@nestjs/mongoose": "^9.1.1",
"@nestjs/platform-express": "^8.0.0", "@nestjs/platform-express": "^8.0.0",
"@nestjs/swagger": "^5.2.1", "@nestjs/swagger": "^5.2.1",
"buffer": "^5.7.1",
"crypto-browserify": "^3.12.0",
"md5-typescript": "^1.0.5",
"mongoose": "^6.4.1", "mongoose": "^6.4.1",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",

View File

@ -38,4 +38,12 @@ export class UsersController {
let dni = id['dni']; let dni = id['dni'];
return this.userService.remove(dni); return this.userService.remove(dni);
} }
//inicio de sesion
@MessagePattern({ cmd: 'loginUser' })
findLogin(@Payload() body:string) {
let pemail= body['email'];
let ppassword= body['password'];
return this.userService.findLogin(pemail,ppassword);
}
} }

View File

@ -2,14 +2,17 @@ import { Injectable } from '@nestjs/common';
import { Model } from 'mongoose'; import { Model } from 'mongoose';
import { User, UserDocument } from '../schemas/user.schema'; import { User, UserDocument } from '../schemas/user.schema';
import { InjectModel } from '@nestjs/mongoose'; import { InjectModel } from '@nestjs/mongoose';
import {Md5} from "md5-typescript";
@Injectable() @Injectable()
export class UsersService { export class UsersService {
constructor( constructor(
@InjectModel(User.name) private readonly userModel: Model<UserDocument>, @InjectModel(User.name) private readonly userModel: Model<UserDocument>,
) {} ) {}
private publicKey: string;
async create(user: UserDocument): Promise<User> { async create(user: UserDocument): Promise<User> {
let passwordEncriptada=Md5.init(user.password);
user.password=passwordEncriptada;
return this.userModel.create(user); return this.userModel.create(user);
} }
@ -37,4 +40,29 @@ export class UsersService {
async remove(id: string) { async remove(id: string) {
return this.userModel.findByIdAndRemove({ _id: id }).exec(); return this.userModel.findByIdAndRemove({ _id: id }).exec();
} }
//inicio de sesion
async findLogin(email: string, password: string) : Promise<User> {
let repo1=this.userModel;
let userReturn = new Promise<User>((resolve, reject) => {
let repo =repo1;
repo.find({ email : email }).exec((err, res) => {
if (err) {
reject(err);
}
else {
let passwordEncriptada=Md5.init(password);
if (res[0].password==passwordEncriptada) {
resolve(res[0]);
}
else {
resolve(null);
}
}
});
});
return userReturn;
}
} }

View File

@ -28,6 +28,7 @@ import TreeDemo from './components/TreeDemo';
import InvalidStateDemo from './components/InvalidStateDemo'; import InvalidStateDemo from './components/InvalidStateDemo';
import BlocksDemo from './components/BlocksDemo'; import BlocksDemo from './components/BlocksDemo';
import IconsDemo from './components/IconsDemo'; import IconsDemo from './components/IconsDemo';
import FormAdminSistema from './components/FormAdminSistema';
import Crud from './pages/Crud'; import Crud from './pages/Crud';
import EmptyPage from './pages/EmptyPage'; import EmptyPage from './pages/EmptyPage';
@ -159,9 +160,10 @@ const App = () => {
const menu = [ const menu = [
{ {
label: 'Home', label: 'Home',
items: [{ items: [
label: 'Dashboard', icon: 'pi pi-fw pi-home', to: '/' {label: 'Dashboard', icon: 'pi pi-fw pi-home', to: '/'},
}] {label: 'Registro admin sistema', icon: 'pi pi-fw pi-id-card', to: '/formAdminSistema'}
]
}, },
{ {
label: 'UI Components', icon: 'pi pi-fw pi-sitemap', label: 'UI Components', icon: 'pi pi-fw pi-sitemap',
@ -320,6 +322,7 @@ const App = () => {
<Route path="/crud" component={Crud} /> <Route path="/crud" component={Crud} />
<Route path="/empty" component={EmptyPage} /> <Route path="/empty" component={EmptyPage} />
<Route path="/documentation" component={Documentation} /> <Route path="/documentation" component={Documentation} />
<Route path="/formAdminSistema" component={FormAdminSistema} />
</div> </div>
<AppFooter layoutColorMode={layoutColorMode} /> <AppFooter layoutColorMode={layoutColorMode} />

View File

@ -0,0 +1,79 @@
import React, { useState } from 'react';
import { InputText } from 'primereact/inputtext';
import { Button } from 'primereact/button';
const FormAdminSistema = () => {
function registrarAdmin() {
var data = {
dni: "12687",
name: "hola",
last_name: "buuu",
email: "tmora4c@ucenfotec.ac.cr",
phone: 84664515,
password: "1203",
user_type: "1",
status: "2"
};
console.log(data);
fetch('http://localhost:4000/user/createAdminSystem/', {
cache: 'no-cache',
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
})
.then(
function (response) {
if (response.status != 200)
console.log('Ocurrió un error con el servicio: ' + response.status);
else
return response.json();
}
)
.then(
function (response) {
console.log(response);
}
)
.catch(
err => console.log('Ocurrió un error con el fetch', err)
);
}
return (
<div className="grid">
<div className="col-12">
<div className="card">
<h5>Registro de un administrador del sistema</h5>
<div className="p-fluid formgrid grid">
<div className="field col-12 md:col-6">
<label htmlFor="nombre">Nombre</label>
<InputText id="nombre" type="text" />
</div>
<div className="field col-12 md:col-6">
<label htmlFor="apellidos">Apellidos</label>
<InputText id="apellidos" type="text" />
</div>
<div className="field col-12 md:col-6">
<label htmlFor="correo_electronico">Correo electrónico</label>
<InputText id="correo_electronico" type="text" />
</div>
<div className="field col-12 md:col-6">
<label htmlFor="identificacion">Identificación</label>
<InputText id="identificacion" type="text" />
</div>
<div className="field col-12">
<label htmlFor="telefono">Teléfono</label>
<InputText id="telefono" type="text" rows="4" />
</div>
<Button label="Registrar" onClick={registrarAdmin}></Button>
</div>
</div>
</div>
</div>
)
}
export default React.memo(FormAdminSistema);