Merge pull request #90 from DeimosPr4/UH-inicioSesion

Uh inicio sesion
This commit is contained in:
Traym17 2022-07-10 21:50:32 -06:00 committed by GitHub
commit 6668c43afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 832 additions and 5 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,13 +2,14 @@ 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> {
return this.userModel.create(user); return this.userModel.create(user);
} }
@ -37,4 +38,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;
}
} }